OpenAPIModelCLI 0.1.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package OpenAPIModelCLI --version 0.1.1
                    
NuGet\Install-Package OpenAPIModelCLI -Version 0.1.1
                    
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="OpenAPIModelCLI" Version="0.1.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="OpenAPIModelCLI" Version="0.1.1" />
                    
Directory.Packages.props
<PackageReference Include="OpenAPIModelCLI" />
                    
Project file
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 OpenAPIModelCLI --version 0.1.1
                    
#r "nuget: OpenAPIModelCLI, 0.1.1"
                    
#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 OpenAPIModelCLI@0.1.1
                    
#: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=OpenAPIModelCLI&version=0.1.1
                    
Install as a Cake Addin
#tool nuget:?package=OpenAPIModelCLI&version=0.1.1
                    
Install as a Cake Tool

OpenAPI Model Generator CLI

NuGet Version License: MIT

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

  1. Invalid Input File Path: Ensure the file path provided via --input exists and is accessible.

  2. Permission Issues: Verify you have write permissions for the output directory.

  3. 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
0.2.0 153 11/30/2024
0.1.1 118 11/25/2024
0.1.0 133 11/22/2024