{"record":{"id":"89318d0c69f4bf72","repo":"RicoSuter/NSwag","slug":"the-schema-type-jsonschema-is-not-supported","errorCode":null,"errorMessage":"The schema type JsonSchema is not supported.","messagePattern":"The schema type JsonSchema is not supported\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/NSwag.Core/OpenApiDocument.cs","lineNumber":200,"sourceCode":"            var match = Regex.Match(data, pattern, RegexOptions.IgnoreCase);\n            if (match.Success)\n            {\n                var schemaType = match.Groups[\"schemaType\"].Value.ToLowerInvariant();\n                var schemaVersion = match.Groups[\"schemaVersion\"].Value.ToLowerInvariant();\n\n                if (schemaType == \"swagger\" && schemaVersion.StartsWith('2'))\n                {\n                    expectedSchemaType = SchemaType.Swagger2;\n                }\n                else if (schemaType == \"openapi\" && schemaVersion.StartsWith('3'))\n                {\n                    expectedSchemaType = SchemaType.OpenApi3;\n                }\n            }\n\n            if (expectedSchemaType == SchemaType.JsonSchema)\n            {\n                throw new NotSupportedException(\"The schema type JsonSchema is not supported.\");\n            }\n\n            var contractResolver = GetJsonSerializerContractResolver(expectedSchemaType);\n            return await JsonSchemaSerialization.FromJsonAsync<OpenApiDocument>(data, expectedSchemaType, documentPath, document =>\n            {\n                document.SchemaType = expectedSchemaType;\n                if (referenceResolverFactory != null)\n                {\n                    return referenceResolverFactory(document);\n                }\n                else\n                {\n                    var schemaResolver = new OpenApiSchemaResolver(document, new SystemTextJsonSchemaGeneratorSettings());\n                    return new JsonReferenceResolver(schemaResolver);\n                }\n            }, contractResolver, cancellationToken).ConfigureAwait(false);\n        }\n","sourceCodeStart":182,"sourceCodeEnd":218,"githubUrl":"https://github.com/RicoSuter/NSwag/blob/63daf8fcc3a25151b62eb4b326a1e8ea048a0d41/src/NSwag.Core/OpenApiDocument.cs#L182-L218","documentation":"OpenApiDocument.FromJsonAsync detects the schema type of the input JSON and throws NotSupportedException if the result is SchemaType.JsonSchema, because OpenApiDocument can only be deserialized as Swagger 2 or OpenAPI 3. A plain JSON Schema document is not an OpenAPI document.","triggerScenarios":"Passing a pure JSON Schema document (or one whose $schema/version fields resolve to JsonSchema) to OpenApiDocument.FromJsonAsync.","commonSituations":"Pointing the loader at a JSON Schema file instead of a Swagger/OpenAPI spec, or a spec missing the 'swagger'/'openapi' version field so detection falls back to JsonSchema.","solutions":["Load the document as JsonSchema instead (use the JsonSchema class / FromJsonAsync on JsonSchema)","Ensure the input has a valid 'swagger': '2.0' or 'openapi': '3.x' field","Check detection logic: verify the file is actually an OpenAPI document"],"exampleFix":"// before\nvar doc = await OpenApiDocument.FromJsonAsync(json);\n// after\nif (json.Contains(\"\\\"swagger\\\"\") || json.Contains(\"\\\"openapi\\\"\"))\n    var doc = await OpenApiDocument.FromJsonAsync(json);\nelse\n    var schema = await JsonSchema.FromJsonAsync(json);","handlingStrategy":"validation","validationCode":"var isOpenApi = json.Contains(\"\\\"swagger\\\"\") || json.Contains(\"\\\"openapi\\\"\");\nif (!isOpenApi) throw new InvalidOperationException(\"Input is not an OpenAPI document\");","typeGuard":null,"tryCatchPattern":"try { doc = await OpenApiDocument.FromJsonAsync(json); }\ncatch (NotSupportedException) { schema = await JsonSchema.FromJsonAsync(json); }","preventionTips":["Verify the spec file declares 'swagger': '2.0' or 'openapi': '3.x' at the root","Use JsonSchema APIs for pure JSON Schema files, OpenApiDocument only for OpenAPI specs"],"tags":["nswag","schema-type","json-schema","not-supported"],"backgroundTag":"unsupported-operation","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"}