Skip to content

Instantly share code, notes, and snippets.

@stevetalkscode
Last active June 26, 2024 02:07
Show Gist options
  • Save stevetalkscode/69719465d8271f1e9fa412626fdadfcd to your computer and use it in GitHub Desktop.
Save stevetalkscode/69719465d8271f1e9fa412626fdadfcd to your computer and use it in GitHub Desktop.
NSwag Commands for use with OpenApiReference Options element
Command Value Type Default Value Description
Namespace string "MyNamespace" The namespace to use on the generated classes for the generated client class
AdditionalNamespaceUsages string[] Empty Array Additional namespaces to include in using directives for the client
GenerateContractsOutput bool false Specifies whether to generate contracts output (interface and models in a separate file set with the ContractsOutput parameter).
ContractsNamespace string null The namespace to use on the generated classes for contracts (interface and models)
ContractsOutput string null The contracts output file path (optional, if no path is set then a single file with the implementation and contracts is generated)
AdditionalContractNamespaceUsages string[] Empty Array Additional namespaces to include in using directives for the contracts (Comma seperated list on command line)
GenerateExceptionClasses bool true Specifies whether to generate custom exception classes or not
ExceptionClass string "SwaggerException" The custom exception class to use if GenerateExceptionClasses is set to true (default 'SwaggerException', may use '{controller}' placeholder).
GenerateClientClasses bool true Specifies whether to generate client classes or not. You may decide to turn this off if just want client contracts generated
OperationGenerationMode string "MultipleClientsFromOperationId" The operation generation mode from one of these options :
* MultipleClientsFromOperationId : Multiple clients from the Swagger operation ID in the form '{controller}_{action}'
* MultipleClientsFromPathSegments : From path segments (operation name = last segment, client name = second to last segment)
* MultipleClientsFromFirstTagAndPathSegments : From the first operation tag and path segments (operation name = last segment, client name = first operation tag)
* MultipleClientsFromFirstTagAndOperationId : From the first operation tag and path segments (operation name = last segment, client name = first operation tag).
* SingleClientFromOperationId : From the Swagger operation ID.
* SingleClientFromPathSegments : From path segments suffixed by HTTP operation name
ClientBaseInterface string null Base interface for client interfaces (empty for no client base interface)
WrapDtoExceptions bool true Specifies whether DTO exceptions are wrapped in a SwaggerException instance (default: true)
WrapResponses bool false Specifies whether to wrap success responses to allow full response access
GenerateResponseClasses bool true Specifies whether to generate response classes (default: true)
ResponseClass string "SwaggerResponse" The response class (default 'SwaggerResponse', may use '{controller}' placeholder)
WrapResponseMethods string[] Empty Array List of methods where responses are wrapped ('ControllerName.MethodName', WrapResponses must be true)
ParameterArrayType string "System.Collections.Generic.IEnumerable" The generic array .NET type of operation parameters (default: 'IEnumerable')
ParameterDictionaryType string "System.Collections.Generic.IDictionary" The generic dictionary .NET type of operation parameters (default: 'IDictionary')
ResponseArrayType string "System.Collections.Generic.ICollection" The generic array .NET type of operation responses (default: 'ICollection')
ResponseDictionaryType string "System.Collections.Generic.IDictionary" The generic dictionary .NET type of operation responses (default: 'IDictionary')
GenerateDtoTypes bool true Specifies whether to generate DTO classes
GenerateOptionalPropertiesAsNullable bool false Specifies whether optional schema properties
GenerateNullableReferenceTypes bool false Specifies whether whether to enerate Nullable Reference Type annotations (default: false).
ExcludedTypeNames string[] Empty Array The excluded DTO type names (must be defined in an import or other namespace)
TypeAccessModifier string "public" The DTO class/enum access modifier (default: public).
GenerateDefaultValues bool true Specifies whether to generate default values for properties (may generate CSharp 6 code, default: true)
GenerateImmutableArrayProperties bool false Specifies whether to remove the setter for non-nullable array properties (default: false)
GenerateImmutableDictionaryProperties bool false Specifies whether to remove the setter for non-nullable dictionary properties (default: false).
GenerateDataAnnotations bool true Specifies whether to generate data annotation attributes on DTO classes (default: true)
GenerateJsonMethods bool false Specifies whether to render ToJson() and FromJson() methods for DTOs (default: true)
EnforceFlagEnums bool false Specifies whether enums should be always generated as bit flags (default: false).
InlineNamedArrays bool false Inline named arrays (default: false)
InlineNamedDictionaries bool false Inline named dictionaries (default: false)
InlineNamedTuples bool true Inline named tuples (default: true).
InlineNamedAny bool false Inline named any types (default: false).
ClassStyle sting "Poco" The CSharp class style, 'Poco' or 'Inpc' (default: 'Poco')
RequiredPropertiesMustBeDefined bool true Specifies whether a required property must be defined in JSON (sets Required.Always when the property is required).
HandleReferences bool false Use preserve references handling (All) in the JSON serializer (default: false)
JsonConverters string[] null Specifies the custom Json.NET converter types (optional, comma separated).
JsonSerializerSettingsTransformationMethod string null Specifies the custom Json.NET converter types (optional, comma separated)
AnyType string "object", The any .NET type (default: 'object')
DateType string "System.DateTimeOffset" The date .NET type (default: 'DateTimeOffset')
DateTimeType string "System.DateTimeOffset" The date time .NET type (default: 'DateTimeOffset')
TimeType string "System.TimeSpan" The time .NET type (default: 'TimeSpan')
TimeSpanType string "System.TimeSpan" The time span .NET type (default: 'TimeSpan')
ArrayType string "System.Collections.Generic.ICollection", ArrayType
ArrayInstanceType string "System.Collections.ObjectModel.Collection" "The generic array .NET instance type (default: empty = ArrayType)
DictionaryType string "System.Collections.Generic.IDictionary" The generic dictionary .NET type (default: 'IDictionary')
DictionaryInstanceType string "System.Collections.Generic.Dictionary" The generic dictionary .NET instance type (default: empty = DictionaryType)
ArrayBaseType string "System.Collections.ObjectModel.Collection" The generic array .NET type (default: 'Collection')
DictionaryBaseType string "System.Collections.Generic.Dictionary" The generic dictionary .NET type (default: 'Dictionary')
ServiceHost string null Overrides the service host of the web document (optional, use '.' to remove the hostname).
ServiceSchemes string[] null Overrides the allowed schemes of the web service (optional, comma separated, 'http', 'https', 'ws', 'wss').
TemplateDirectory string null The Liquid template directory (experimental)
Output string null The output file path (optional)
NewLineBehavior string "Auto" The new line behavior (Auto (OS default), CRLF, LF)
ConfigurationClass string null The configuration class. The setting ClientBaseClass must be set. (empty for no configuration class)
@doggy8088
Copy link

typo: OpenApiRefrerence -> OpenApiReference

@doggy8088
Copy link

Another way to see all the options available:

nswag help openapi2csclient

nswag help openapi2tsclient

@stevetalkscode
Copy link
Author

Thanks ... didn't know about that one. Typo corrected.

@peereflits
Copy link

TypeAccessModifier = ClientClassAccessModifier in version 13.16.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment