{"record":{"id":"649b67bff86f8999","repo":"OpenAPITools/openapi-generator","slug":"the-openapi-specification-supplied-was-not-valid","errorCode":null,"errorMessage":"The OpenAPI specification supplied was not valid","messagePattern":"The OpenAPI specification supplied was not valid","errorType":"http","errorClass":"ResponseStatusException","httpStatus":400,"severity":"error","filePath":"modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/service/Generator.java","lineNumber":110,"sourceCode":"                    List<AuthorizationValue> authorizationValues = new ArrayList<>();\n                    authorizationValues.add(opts.getAuthorizationValue());\n                    openapi = new OpenAPIParser().readLocation(opts.getOpenAPIUrl(), authorizationValues, parseOptions).getOpenAPI();\n                } else {\n                    openapi = new OpenAPIParser().readLocation(opts.getOpenAPIUrl(), null, parseOptions).getOpenAPI();\n                }\n            } else {\n                throw new ResponseStatusException(HttpStatus.BAD_REQUEST, \"No OpenAPI specification was supplied\");\n            }\n        } else if (opts.getAuthorizationValue() != null) {\n            List<AuthorizationValue> authorizationValues = new ArrayList<>();\n            authorizationValues.add(opts.getAuthorizationValue());\n            openapi = new OpenAPIParser().readContents(node.toString(), authorizationValues, parseOptions).getOpenAPI();\n\n        } else {\n            openapi = new OpenAPIParser().readContents(node.toString(), null, parseOptions).getOpenAPI();\n        }\n        if (openapi == null) {\n            throw new ResponseStatusException(HttpStatus.BAD_REQUEST, \"The OpenAPI specification supplied was not valid\");\n        }\n\n\n        // do not use opts.getOptions().get(\"outputFolder\") as the input can contain ../../\n        // to access other folders in the server\n        String destPath = language + \"-\" + type.getTypeName();\n\n        ClientOptInput clientOptInput = new ClientOptInput();\n        String outputFolder = getTmpFolder().getAbsolutePath() + File.separator + destPath;\n        String outputFilename = outputFolder + \"-bundle.zip\";\n\n        clientOptInput.openAPI(openapi);\n\n        CodegenConfig codegenConfig;\n        try {\n            codegenConfig = CodegenConfigLoader.forName(language);\n        } catch (RuntimeException e) {\n            throw new ResponseStatusException(HttpStatus.BAD_REQUEST, \"Unsupported target \" + language + \" supplied\");","sourceCodeStart":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/OpenAPITools/openapi-generator/blob/fcec517be3cf5b7964296bcba25fbc97541484e7/modules/openapi-generator-online/src/main/java/org/openapitools/codegen/online/service/Generator.java#L92-L128","documentation":"Thrown when the swagger-parser call returned a result whose getOpenAPI() is null (Generator.java:94-111), meaning the input could not be turned into an OpenAPI model at all. For inline specs, readContents yields a null model when the payload is not recognizable YAML/JSON (e.g. an HTML error page, an empty document, or garbage). For openAPIUrl, readLocation yields null when the URL cannot be fetched or its content is unparseable — critically, the URL is fetched server-side, from the generator host's network, not the client's.","triggerScenarios":"openAPIUrl pointing at localhost/127.0.0.1 or an intranet host unreachable from the generator server; URL returning HTML (login page, 404 handler) instead of the spec; inline spec that is malformed YAML/JSON or empty; URL with a typo or wrong scheme; private repo URL without an authorizationValue.","commonSituations":"Developers testing against a spec served by their own machine ('works when I open the URL in my browser'); specs behind auth where authorizationValue was omitted; gateways that answer 200 with an HTML error body; copy-pasted URLs with trailing garbage or smart quotes.","solutions":["Inline the spec in the body (\"spec\": ...) instead of \"openAPIUrl\" so no server-side fetch is needed","If using openAPIUrl, make sure the URL is reachable from the generator server (public or same network), and test with curl FROM the server","For auth-protected specs, supply \"authorizationValue\": {\"value\": \"...\", \"type\": \"header\", \"keyName\": \"Authorization\"}","Pre-validate the document locally with swagger-parser or a validator before submitting"],"exampleFix":"# before\n{\"openAPIUrl\": \"http://localhost:8080/openapi.json\"}   # server cannot reach YOUR localhost -> 400 not valid\n\n# after\n# fetch it yourself, then inline it\n{\"spec\": $(curl -s https://internal-host/openapi.json)}","handlingStrategy":"validation","validationCode":"// parse locally first with the same parser the server uses\nSwaggerParseResult r = new OpenAPIParser().readContents(specJson, null, new ParseOptions());\nif (r.getOpenAPI() == null) throw new IllegalArgumentException(\"spec unparseable: \" + r.getMessages());\n// for URLs: prefer inlining — the server fetches from ITS network, not yours","typeGuard":"boolean isFetchableSpecUrl(String url) {\n    try {\n        HttpURLConnection c = (HttpURLConnection) new URI(url).toURL().openConnection();\n        c.setConnectTimeout(3000);\n        return c.getResponseCode() == 200\n            && (c.getContentType() == null || c.getContentType().contains(\"json\")\n                || c.getContentType().contains(\"yaml\"));\n    } catch (Exception e) { return false; }\n}","tryCatchPattern":"catch (HttpClientErrorException.BadRequest e) {\n    if (e.getResponseBodyAsString().contains(\"not valid\")) {\n        // null model = unparseable/unfetchable source; inline the spec instead of the URL\n        input.setOpenAPIUrl(null);\n        input.setSpec(fetchAndParseSpecLocally());\n    }\n}","preventionTips":["Never point openAPIUrl at localhost or intranet hosts unless the generator server shares that network","Inline the spec whenever possible — it removes the whole fetch failure class","Lint the document with swagger-parser/Redocly locally before submitting"],"tags":["http-400","openapi-spec","swagger-parser","url-unreachable","openapi-generator-online"],"backgroundTag":"invalid-openapi-spec","analyzedSha":"fcec517be3cf5b7964296bcba25fbc97541484e7","analyzedAt":"2026-08-22T11:13:11.613Z","schemaVersion":2},"datasetVersion":"2026-08-22T14:17:55.899Z"}