{"record":{"id":"e259caffb506f38b","repo":"RicoSuter/NSwag","slug":"the-schema-type-schematype-is-not-supported","errorCode":null,"errorMessage":"The schema type '\" + schemaType + \"' is not supported.","messagePattern":"The schema type '\" \\+ schemaType \\+ \"' is not supported\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/NSwag.Core/OpenApiDocument.Serialization.cs","lineNumber":40,"sourceCode":"\n        private static readonly Lazy<PropertyRenameAndIgnoreSerializerContractResolver> OpenApi3ContractResolver =\n            new Lazy<PropertyRenameAndIgnoreSerializerContractResolver>(() => CreateJsonSerializerContractResolver(SchemaType.OpenApi3));\n\n        /// <summary>Creates the serializer contract resolver based on the <see cref=\"NJsonSchema.SchemaType\"/>.</summary>\n        /// <param name=\"schemaType\">The schema type.</param>\n        /// <returns>The settings.</returns>\n        public static PropertyRenameAndIgnoreSerializerContractResolver GetJsonSerializerContractResolver(SchemaType schemaType)\n        {\n            if (schemaType == SchemaType.Swagger2)\n            {\n                return Swagger2ContractResolver.Value;\n            }\n            else if (schemaType == SchemaType.OpenApi3)\n            {\n                return OpenApi3ContractResolver.Value;\n            }\n\n            throw new ArgumentException(\"The schema type '\" + schemaType + \"' is not supported.\");\n        }\n\n        private static PropertyRenameAndIgnoreSerializerContractResolver CreateJsonSerializerContractResolver(SchemaType schemaType)\n        {\n            var resolver = JsonSchema.CreateJsonSerializerContractResolver(schemaType);\n\n            if (schemaType == SchemaType.Swagger2)\n            {\n                resolver.IgnoreProperty(typeof(OpenApiDocument), \"openapi\");\n                resolver.IgnoreProperty(typeof(OpenApiDocument), \"servers\");\n                resolver.IgnoreProperty(typeof(OpenApiParameter), \"title\");\n\n                // TODO: Use rename for not mapped properties!\n                resolver.IgnoreProperty(typeof(OpenApiPathItem), \"summary\");\n                resolver.IgnoreProperty(typeof(OpenApiPathItem), \"description\");\n                resolver.IgnoreProperty(typeof(OpenApiPathItem), \"servers\");\n\n                resolver.IgnoreProperty(typeof(OpenApiOperation), \"callbacks\");","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/RicoSuter/NSwag/blob/63daf8fcc3a25151b62eb4b326a1e8ea048a0d41/src/NSwag.Core/OpenApiDocument.Serialization.cs#L22-L58","documentation":"OpenApiDocument.Serialization.GetJsonSerializerContractResolver only supports Swagger2 and OpenApi3 schema types and throws ArgumentException for any other value. JsonSchema is explicitly not a valid serialization target for OpenAPI documents (see also error 46).","triggerScenarios":"Calling serialization APIs (e.g. ToJsonAsync / contract resolution) with a SchemaType value other than SchemaType.Swagger2 or SchemaType.OpenApi3, such as SchemaType.JsonSchema or a garbage cast value.","commonSituations":"Setting document.SchemaType manually to an unsupported value, or migrating code from JsonSchema utilities to OpenAPI documents without changing the schema type enum.","solutions":["Set SchemaType to SchemaType.Swagger2 or SchemaType.OpenApi3 before serializing","Verify the SchemaType enum value passed into serialization helpers","Use FromJsonAsync with explicit expectedSchemaType instead of relying on defaults"],"exampleFix":"// before\ndocument.SchemaType = SchemaType.JsonSchema;\nawait document.ToJsonAsync();\n// after\ndocument.SchemaType = SchemaType.OpenApi3;\nawait document.ToJsonAsync();","handlingStrategy":"validation","validationCode":"if (schemaType is not (SchemaType.Swagger2 or SchemaType.OpenApi3))\n    throw new ArgumentException($\"Unsupported schema type: {schemaType}\");","typeGuard":"bool isSerializable = schemaType == SchemaType.Swagger2 || schemaType == SchemaType.OpenApi3;","tryCatchPattern":"try { await doc.ToJsonAsync(); } catch (ArgumentException ex) { /* fix SchemaType and retry */ }","preventionTips":["Only ever assign SchemaType from the fixed set Swagger2/OpenApi3 for OpenApiDocument","Let FromJsonAsync detect and set SchemaType instead of setting it manually"],"tags":["nswag","schema-type","unsupported"],"backgroundTag":"unsupported-enum-value","analyzedSha":"63daf8fcc3a25151b62eb4b326a1e8ea048a0d41","analyzedAt":"2026-09-14T11:38:15.205Z","contentChangedAt":"2026-09-14T11:38:15.205Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}