Apollo3zehn.OpenApiClientGenerator
1.0.0-beta.19
This is a prerelease version of Apollo3zehn.OpenApiClientGenerator.
dotnet add package Apollo3zehn.OpenApiClientGenerator --version 1.0.0-beta.19
NuGet\Install-Package Apollo3zehn.OpenApiClientGenerator -Version 1.0.0-beta.19
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.19" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Apollo3zehn.OpenApiClientGenerator" Version="1.0.0-beta.19" />
<PackageReference Include="Apollo3zehn.OpenApiClientGenerator" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Apollo3zehn.OpenApiClientGenerator --version 1.0.0-beta.19
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Apollo3zehn.OpenApiClientGenerator, 1.0.0-beta.19"
#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.
#:package Apollo3zehn.OpenApiClientGenerator@1.0.0-beta.19
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Apollo3zehn.OpenApiClientGenerator&version=1.0.0-beta.19&prerelease
#tool nuget:?package=Apollo3zehn.OpenApiClientGenerator&version=1.0.0-beta.19&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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.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.19 | 206 | 1/22/2025 |
1.0.0-beta.18 | 66 | 1/22/2025 |
1.0.0-beta.17 | 316 | 10/30/2024 |
1.0.0-beta.16 | 73 | 10/30/2024 |
1.0.0-beta.15 | 71 | 10/30/2024 |
1.0.0-beta.14 | 66 | 10/30/2024 |
1.0.0-beta.13 | 73 | 10/29/2024 |
1.0.0-beta.12 | 118 | 10/1/2024 |
1.0.0-beta.11 | 72 | 10/1/2024 |
1.0.0-beta.10 | 353 | 3/5/2024 |
1.0.0-beta.9 | 73 | 3/5/2024 |
1.0.0-beta.8 | 104 | 2/28/2024 |
1.0.0-beta.7 | 73 | 2/28/2024 |
1.0.0-beta.6 | 220 | 7/13/2023 |
1.0.0-beta.5 | 317 | 3/15/2023 |
1.0.0-beta.4 | 127 | 3/15/2023 |
1.0.0-beta.3 | 123 | 3/15/2023 |
1.0.0-beta.2 | 121 | 3/15/2023 |
1.0.0-beta.1 | 175 | 3/14/2023 |