RicoSuter/NSwag · error · ArgumentException
The given schema type is not supported.
Error message
The given schema type is not supported.
What it means
CreateJsonSerializerContractResolver configures JSON serializer settings per schema type but only has branches for Swagger2 and OpenApi3; anything else throws ArgumentException('The given schema type is not supported.'). It is a private factory called by the cached resolver providers for known types.
Solutions
- Pass only SchemaType.Swagger2 or SchemaType.OpenApi3
- Validate/normalize the schema type before serialization
- Upgrade NSwag if a newer schema type is expected to be supported
Example fix
// before
var resolver = GetJsonSerializerContractResolver(schemaType);
// after
if (schemaType != SchemaType.Swagger2 && schemaType != SchemaType.OpenApi3)
throw new ArgumentException($"Unsupported schema type: {schemaType}");
var resolver = GetJsonSerializerContractResolver(schemaType); Defensive patterns
Strategy: validation
Validate before calling
var supported = new[] { SchemaType.Swagger2, SchemaType.OpenApi3 };
if (!supported.Contains(schemaType)) throw new ArgumentException(nameof(schemaType)); Type guard
bool resolverSupported = schemaType == SchemaType.Swagger2 || schemaType == SchemaType.OpenApi3;
Prevention
- Keep SchemaType sources (config, CLI flags) validated against supported enum values
- Pin NSwag version and enum usage consistently across projects
When it happens
Trigger: Invoking the contract resolver factory with a SchemaType other than Swagger2/OpenApi3, typically via GetJsonSerializerContractResolver with an invalid enum value.
Common situations: A SchemaType field set from unvalidated input, or a new enum value added in a newer NSwag version being passed to an older runtime.
Related errors
- The schema type '" + schemaType + "' is not supported.
- The schema type JsonSchema is not supported.
- This UI does not support multiple documents per UI: Do not…
- The SwaggerUiRoute cannot contain
- The NSwag DI services are not registered: Call…
AI-assisted analysis of RicoSuter/NSwag@63daf8fcc3 (2026-09-14).
Data as JSON: /api/errors/a671a57a975de36d.
Report an issue: GitHub.
Appendix: source
Thrown at src/NSwag.Core/OpenApiDocument.Serialization.cs:110
//resolver.IgnoreProperty(typeof(SwaggerResponse), "produces");
resolver.IgnoreProperty(typeof(OpenApiDocument), "definitions");
resolver.IgnoreProperty(typeof(OpenApiDocument), "parameters");
resolver.IgnoreProperty(typeof(OpenApiDocument), "responses");
resolver.IgnoreProperty(typeof(OpenApiDocument), "securityDefinitions");
resolver.IgnoreProperty(typeof(OpenApiResponse), "schema");
resolver.IgnoreProperty(typeof(OpenApiResponse), "examples");
resolver.IgnoreProperty(typeof(OpenApiResponse), "x-nullable");
resolver.IgnoreProperty(typeof(OpenApiSecurityScheme), "flow");
resolver.IgnoreProperty(typeof(OpenApiSecurityScheme), "authorizationUrl");
resolver.IgnoreProperty(typeof(OpenApiSecurityScheme), "tokenUrl");
resolver.IgnoreProperty(typeof(OpenApiSecurityScheme), "scopes");
}
else
{
throw new ArgumentException("The given schema type is not supported.");
}
return resolver;
}
private ObservableCollection<OpenApiSchema> _schemes = [];
internal List<string> _consumes = [];
internal List<string> _produces = [];
/// <summary>Gets or sets the host (name or ip) serving the API (Swagger only).</summary>
[JsonProperty(PropertyName = "host", Order = 5, DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate)]
public string Host
{
get => Servers?.FirstOrDefault()?.Url?.Replace("http://", "").Replace("https://", "").Split('/')[0];
set => UpdateServers(Schemes, value, BasePath);
}
/// <summary>Gets or sets the base path on which the API is served, which is relative to the <see cref="Host"/>.</summary>View on GitHub (pinned to 63daf8fcc3)