Apollo3zehn.OpenApiClientGenerator
1.0.0-beta.13
This is a prerelease version of Apollo3zehn.OpenApiClientGenerator.
There is a newer prerelease version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package Apollo3zehn.OpenApiClientGenerator --version 1.0.0-beta.13
NuGet\Install-Package Apollo3zehn.OpenApiClientGenerator -Version 1.0.0-beta.13
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Apollo3zehn.OpenApiClientGenerator" Version="1.0.0-beta.13" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Apollo3zehn.OpenApiClientGenerator --version 1.0.0-beta.13
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Apollo3zehn.OpenApiClientGenerator, 1.0.0-beta.13"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Apollo3zehn.OpenApiClientGenerator as a Cake Addin #addin nuget:?package=Apollo3zehn.OpenApiClientGenerator&version=1.0.0-beta.13&prerelease // Install Apollo3zehn.OpenApiClientGenerator as a Cake Tool #tool nuget:?package=Apollo3zehn.OpenApiClientGenerator&version=1.0.0-beta.13&prerelease
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Apollo3zehn.OpenApiClientGenerator
- This project provides an OpenAPI client generator, i.e. it takes an openapi.json file as input and generates the corresponding output.
- The generator code has been tested on three different projects but is not yet fully generic, so it might not lead to perfect results in your case. Please file an issue if you run into problems.
- The generated C# code makes heavy use of C# 10 Record types .
- Both types of clients (C# and Python) will be generated with sync and async support.
- All types are strongly-typed, i.e. JSON data will be serialized and deserialized as required.
Sample usage (taken from https://github.com/Apollo3zehn/hsds-api):
dotnet add package Apollo3zehn.OpenApiClientGenerator --prerelease
using Apollo3zehn.OpenApiClientGenerator;
using Microsoft.OpenApi.Readers;
namespace Hsds.ClientGenerator;
public static class Program
{
public static async Task Main(string[] args)
{
// read open API document
var client = new HttpClient();
var response = await client.GetAsync("https://raw.githubusercontent.com/HDFGroup/hdf-rest-api/master/openapi.yaml");
response.EnsureSuccessStatusCode();
var openApiJsonString = await response.Content.ReadAsStringAsync();
// TODO: workaround (OpenAPI version 3.1.0 is not yet supported)
openApiJsonString = openApiJsonString.Replace("3.1.0", "3.0.3");
var document = new OpenApiStringReader()
.Read(openApiJsonString, out var diagnostic);
// generate clients
var basePath = Assembly.GetExecutingAssembly().Location;
// TODO: remove when https://github.com/HDFGroup/hdf-rest-api/issues/10 is resolved
var pathToMethodNameMap = new Dictionary<string, string>()
{
["/"] = "Domain",
["Post:/groups"] = "Group",
["Get:/groups"] = "Groups",
["/groups/{id}"] = "Group",
["/groups/{id}/links"] = "Links",
["/groups/{id}/links/{linkname}"] = "Link",
["Post:/datasets"] = "Dataset",
["Get:/datasets"] = "Datasets",
["/datasets/{id}"] = "Dataset",
["/datasets/{id}/shape"] = "Shape",
["/datasets/{id}/type"] = "DataType",
["/datasets/{id}/value"] = "Values",
["/datatypes"] = "DataType",
["/datatypes/{id}"] = "Datatype",
["/{collection}/{obj_uuid}/attributes"] = "Attributes",
["/{collection}/{obj_uuid}/attributes/{attr}"] = "Attribute",
["/acls"] = "AccessLists",
["/acls/{user}"] = "UserAccess",
["/groups/{id}/acls"] = "GroupAccessLists",
["/groups/{id}/acls/{user}"] = "GroupUserAccess",
["/datasets/{id}/acls"] = "DatasetAccessLists",
["/datatypes/{id}/acls"] = "DataTypeAccessLists"
};
var settings = new GeneratorSettings(
Namespace: "Hsds.Api",
ClientName: "Hsds",
ExceptionType: "HsdsException",
ExceptionCodePrefix: "H",
GetOperationName: (path, type, _) => {
if (!pathToMethodNameMap.TryGetValue($"{type}:{path}", out var methodName))
methodName = pathToMethodNameMap[path];
return $"{type}{methodName}";
},
Special_ConfigurationHeaderKey: default!, /* Apollo3zehn-specific option */
Special_WebAssemblySupport: false, /* Apollo3zehn-specific option */
Special_AccessTokenSupport: false, /* Apollo3zehn-specific option */
Special_NexusFeatures: false); /* Apollo3zehn-specific option */
// generate C# client
var csharpGenerator = new CSharpGenerator(settings);
var csharpCode = csharpGenerator.Generate(document);
File.WriteAllText("my_csharp_code.cs", csharpcode)
// generate Python client
var pythonGenerator = new PythonGenerator(settings);
var pythonCode = pythonGenerator.Generate(document);
File.WriteAllText("my_python_code.py", pythonCode)
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.1
- Microsoft.OpenApi.Readers (>= 1.2.3)
- Stubble.Core (>= 1.10.8)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.0-beta.17 | 155 | 10/30/2024 |
1.0.0-beta.16 | 51 | 10/30/2024 |
1.0.0-beta.15 | 47 | 10/30/2024 |
1.0.0-beta.14 | 44 | 10/30/2024 |
1.0.0-beta.13 | 53 | 10/29/2024 |
1.0.0-beta.12 | 94 | 10/1/2024 |
1.0.0-beta.11 | 55 | 10/1/2024 |
1.0.0-beta.10 | 339 | 3/5/2024 |
1.0.0-beta.9 | 61 | 3/5/2024 |
1.0.0-beta.8 | 91 | 2/28/2024 |
1.0.0-beta.7 | 57 | 2/28/2024 |
1.0.0-beta.6 | 189 | 7/13/2023 |
1.0.0-beta.5 | 280 | 3/15/2023 |
1.0.0-beta.4 | 91 | 3/15/2023 |
1.0.0-beta.3 | 88 | 3/15/2023 |
1.0.0-beta.2 | 87 | 3/15/2023 |
1.0.0-beta.1 | 140 | 3/14/2023 |