Skip to content

CLI Reference

openapi-codegen [OPTIONS] <input> [output]
openapi-codegen --input <file-or-url> --output <file>

Required. Path to a local OpenAPI specification file (JSON or YAML) or a URL to a remote spec.

Terminal window
# Local file
openapi-codegen ./specs/api.yaml
# Remote URL
openapi-codegen https://example.com/api/openapi.json

Optional. Path to the output C# file. If omitted, the generated code is written to stdout.

Terminal window
# Write to file
openapi-codegen spec.yaml Models.cs
# Write to stdout
openapi-codegen spec.yaml

Input OpenAPI specification file path or URL. Alternative to the positional <input> argument.

Terminal window
openapi-codegen --input spec.yaml --output Models.cs

Output C# file path. Alternative to the positional [output] argument. The directory is created automatically if it doesn’t exist.

Terminal window
openapi-codegen spec.yaml --output src/Generated/Models.cs

C# namespace for the generated types.

  • Default: GeneratedModels
Terminal window
openapi-codegen spec.yaml -o Models.cs -n MyApp.Api.Models

Disable generation of XML documentation comments from OpenAPI descriptions.

Terminal window
openapi-codegen spec.yaml -o Models.cs --no-doc-comments

Disable the auto-generated file comment header (// <auto-generated>...).

Terminal window
openapi-codegen spec.yaml -o Models.cs --no-header

Don’t treat properties with default values as non-nullable.

Terminal window
openapi-codegen spec.yaml -o Models.cs --no-default-non-nullable

Don’t add default values from the OpenAPI spec to the generated properties.

Terminal window
openapi-codegen spec.yaml -o Models.cs --no-add-default-values

Use List<T> instead of IReadOnlyList<T> for array properties.

Terminal window
openapi-codegen spec.yaml -o Models.cs --mutable-arrays

Use Dictionary<string, T> instead of IReadOnlyDictionary<string, T> for map/additionalProperties types.

Terminal window
openapi-codegen spec.yaml -o Models.cs --mutable-dictionaries

Display the tool version and exit.

Terminal window
openapi-codegen --version

Display the help message and exit.

Terminal window
openapi-codegen --help
CodeMeaning
0Success
1Error (missing input, parse failure, etc.)
Terminal window
# Basic generation
openapi-codegen petstore.yaml -o Models.cs
# Custom namespace
openapi-codegen petstore.yaml -o Models.cs -n PetStore.Models
# From URL with all options disabled
openapi-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 stdout
openapi-codegen spec.yaml | head -50
# Named flags style
openapi-codegen --input spec.yaml --output Models.cs --namespace MyApp