CLI Reference
Synopsis
Section titled “Synopsis”openapi-codegen [OPTIONS] <input> [output]openapi-codegen --input <file-or-url> --output <file>Arguments
Section titled “Arguments”<input>
Section titled “<input>”Required. Path to a local OpenAPI specification file (JSON or YAML) or a URL to a remote spec.
# Local fileopenapi-codegen ./specs/api.yaml
# Remote URLopenapi-codegen https://example.com/api/openapi.json[output]
Section titled “[output]”Optional. Path to the output C# file. If omitted, the generated code is written to stdout.
# Write to fileopenapi-codegen spec.yaml Models.cs
# Write to stdoutopenapi-codegen spec.yamlOptions
Section titled “Options”-i, --input <path>
Section titled “-i, --input <path>”Input OpenAPI specification file path or URL. Alternative to the positional <input> argument.
openapi-codegen --input spec.yaml --output Models.cs-o, --output <path>
Section titled “-o, --output <path>”Output C# file path. Alternative to the positional [output] argument. The directory is created automatically if it doesn’t exist.
openapi-codegen spec.yaml --output src/Generated/Models.cs-n, --namespace <name>
Section titled “-n, --namespace <name>”C# namespace for the generated types.
- Default:
GeneratedModels
openapi-codegen spec.yaml -o Models.cs -n MyApp.Api.Models--no-doc-comments
Section titled “--no-doc-comments”Disable generation of XML documentation comments from OpenAPI descriptions.
openapi-codegen spec.yaml -o Models.cs --no-doc-comments--no-header
Section titled “--no-header”Disable the auto-generated file comment header (// <auto-generated>...).
openapi-codegen spec.yaml -o Models.cs --no-header--no-default-non-nullable
Section titled “--no-default-non-nullable”Don’t treat properties with default values as non-nullable.
openapi-codegen spec.yaml -o Models.cs --no-default-non-nullable--no-add-default-values
Section titled “--no-add-default-values”Don’t add default values from the OpenAPI spec to the generated properties.
openapi-codegen spec.yaml -o Models.cs --no-add-default-values--mutable-arrays
Section titled “--mutable-arrays”Use List<T> instead of IReadOnlyList<T> for array properties.
openapi-codegen spec.yaml -o Models.cs --mutable-arrays--mutable-dictionaries
Section titled “--mutable-dictionaries”Use Dictionary<string, T> instead of IReadOnlyDictionary<string, T> for map/additionalProperties types.
openapi-codegen spec.yaml -o Models.cs --mutable-dictionaries-v, --version
Section titled “-v, --version”Display the tool version and exit.
openapi-codegen --version-h, --help
Section titled “-h, --help”Display the help message and exit.
openapi-codegen --helpExit Codes
Section titled “Exit Codes”| Code | Meaning |
|---|---|
0 | Success |
1 | Error (missing input, parse failure, etc.) |
Examples
Section titled “Examples”# Basic generationopenapi-codegen petstore.yaml -o Models.cs
# Custom namespaceopenapi-codegen petstore.yaml -o Models.cs -n PetStore.Models
# From URL with all options disabledopenapi-codegen https://example.com/api.json \ -o Models.cs \ --no-doc-comments \ --no-header \ --no-default-non-nullable \ --no-add-default-values \ --mutable-arrays \ --mutable-dictionaries
# Preview to stdoutopenapi-codegen spec.yaml | head -50
# Named flags styleopenapi-codegen --input spec.yaml --output Models.cs --namespace MyApp