OpenAPIModelCLI 0.1.1
See the version list below for details.
dotnet add package OpenAPIModelCLI --version 0.1.1
NuGet\Install-Package OpenAPIModelCLI -Version 0.1.1
<PackageReference Include="OpenAPIModelCLI" Version="0.1.1" />
<PackageVersion Include="OpenAPIModelCLI" Version="0.1.1" />
<PackageReference Include="OpenAPIModelCLI" />
paket add OpenAPIModelCLI --version 0.1.1
#r "nuget: OpenAPIModelCLI, 0.1.1"
#:package OpenAPIModelCLI@0.1.1
#addin nuget:?package=OpenAPIModelCLI&version=0.1.1
#tool nuget:?package=OpenAPIModelCLI&version=0.1.1
OpenAPI Model Generator CLI
OpenAPI Model Generator CLI is a lightweight command-line interface for generating plain C# models (POCOs) from OpenAPI specifications. It leverages the OpenAPIModelGenerator library to streamline development workflows.
Features
- Generate Models Quickly: Turn OpenAPI schemas into C# models in seconds.
- Custom Output Settings: Specify output directory and namespace for generated files.
- Comprehensive Logs: Monitor each step of the process via the console.
- Platform Agnostic: Works seamlessly on Windows, macOS, and Linux.
Installation
Install the CLI globally using the .NET CLI:
dotnet tool install -g openapi-gen
To update to the latest version:
dotnet tool update -g openapi-gen
Usage
Command Syntax
openapi-gen -i <InputFilePath> -o <OutputDirectory> -n <Namespace>
Options
Option | Description | Required | Default |
---|---|---|---|
-i , --input |
Path to the OpenAPI specification file | Yes | N/A |
-o , --output |
Directory for the generated C# files | Yes | N/A |
-n , --namespace |
Namespace for the generated files | No | CodeGen |
-h , --help |
Displays the help message | No | N/A |
Examples
Generate Models with Custom Namespace
openapi-gen -i ./openapi.yaml -o ./GeneratedModels -n MyCustomNamespace
Generate Models with Default Namespace
openapi-gen -i ./openapi.json -o ./Models
Display Help
openapi-gen --help
Example Output
Here’s an example of a generated class:
using Newtonsoft.Json;
namespace MyCustomNamespace
{
public class SampleModel
{
[JsonProperty("id")]
public string Id { get; set; }
[JsonProperty("name")]
public string Name { get; set; }
}
}
Logging
The CLI provides real-time logs to ensure transparency and traceability:
- INFO: Indicates the progress of the operation.
- WARNING: Alerts about potential issues in the input file.
- ERROR: Stops execution for critical errors.
Example Log Output
[INFO] Reading OpenAPI specification from ./openapi.yaml
[INFO] OpenAPI version detected: 3.1.0
[INFO] Generating models in ./GeneratedModels
[INFO] Successfully generated 5 models!
Troubleshooting
Common Issues
Invalid Input File Path: Ensure the file path provided via
--input
exists and is accessible.Permission Issues: Verify you have write permissions for the output directory.
Invalid OpenAPI Document: Use an OpenAPI validator to confirm the document adheres to the OpenAPI specification.
License
This project is licensed under the MIT License.
Contributing
We welcome contributions! If you'd like to report an issue, request a feature, or submit a pull request, please visit the GitHub repository.
Contact
For questions or support, please reach out via the repository's Issues section.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. 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. |
-
net8.0
- CommandLineParser (>= 2.9.1)
- Microsoft.Extensions.Logging (>= 9.0.0)
- OpenAPIModelGenerator (>= 0.1.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.