{"record":{"id":"e9faaaa8a3ad4839","repo":"OpenAPITools/openapi-generator","slug":"issues-with-the-openapi-input-possible-causes-in","errorCode":null,"errorMessage":"Issues with the OpenAPI input. Possible causes: invalid/missing spec, malformed JSON/YAML files, etc.","messagePattern":"Issues with the OpenAPI input\\. Possible causes: invalid/missing spec, malformed JSON/YAML files, etc\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultGenerator.java","lineNumber":1277,"sourceCode":"            if (ProcessUtils.hasHttpSignatureMethods(authMethods)) {\n                bundle.put(\"hasHttpSignatureMethods\", true);\n                bundle.put(\"httpSignatureMethods\", ProcessUtils.getHttpSignatureMethods(authMethods));\n            }\n            if (ProcessUtils.hasHttpBasicMethods(authMethods)) {\n                bundle.put(\"hasHttpBasicMethods\", true);\n                bundle.put(\"httpBasicMethods\", ProcessUtils.getHttpBasicMethods(authMethods));\n            }\n            if (ProcessUtils.hasApiKeyMethods(authMethods)) {\n                bundle.put(\"hasApiKeyMethods\", true);\n                bundle.put(\"apiKeyMethods\", ProcessUtils.getApiKeyMethods(authMethods));\n            }\n        }\n    }\n\n    @Override\n    public List<File> generate() {\n        if (openAPI == null) {\n            throw new RuntimeException(\"Issues with the OpenAPI input. Possible causes: invalid/missing spec, malformed JSON/YAML files, etc.\");\n        }\n\n        if (config == null) {\n            throw new RuntimeException(\"missing config!\");\n        }\n\n        if (config.getGeneratorMetadata() == null) {\n            LOGGER.warn(\"Generator '{}' is missing generator metadata!\", config.getName());\n        } else {\n            GeneratorMetadata generatorMetadata = config.getGeneratorMetadata();\n            if (StringUtils.isNotEmpty(generatorMetadata.getGenerationMessage())) {\n                LOGGER.info(generatorMetadata.getGenerationMessage());\n            }\n\n            Stability stability = generatorMetadata.getStability();\n            String stabilityMessage = String.format(Locale.ROOT, \"Generator '%s' is considered %s.\", config.getName(), stability.value());\n            if (stability == Stability.DEPRECATED) {\n                LOGGER.warn(stabilityMessage);","sourceCodeStart":1259,"sourceCodeEnd":1295,"githubUrl":"https://github.com/OpenAPITools/openapi-generator/blob/fcec517be3cf5b7964296bcba25fbc97541484e7/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultGenerator.java#L1259-L1295","documentation":"DefaultGenerator.generate() starts with a null guard on the parsed OpenAPI document. openAPI is populated during opts(...) from the input spec (ClientOptInput/GeneratorSettings flow and CodegenConfigurator); if generate() is reached with openAPI still null, nothing was ever parsed/attached and the run aborts immediately. This is an API-misuse guard that the CLI normally makes unreachable - it chiefly bites programmatic callers who skip or mis-order the setup steps.","triggerScenarios":"Calling new DefaultGenerator().generate() without first calling opts(...); building ClientOptInput manually and leaving the OpenAPI/spec unset (e.g. only setting generatorName); a wrapper that catches and swallows an earlier parse failure and then calls generate() anyway; migrating from an older API where setInputSpec was invoked directly on ClientOptInput.","commonSituations":"Service code that generates on demand and takes an error path that skips opts(); tutorials copied from an incompatible openapi-generator version; tests constructing DefaultGenerator directly without CodegenConfigurator.","solutions":["Always build opts through org.openapitools.codegen.config.CodegenConfigurator: configurator.setInputSpec(...)/setGeneratorName(...) then ClientOptInput input = configurator.toClientOptInput(); generator.opts(input).generate().","If constructing ClientOptInput by hand, set the parsed spec on it (input.setOpenAPI(parsed) / via GeneratorSettings) before opts().","Before generate(), assert the pipeline is complete - parse the spec first (OpenAPIParser) and fail loudly if parsing produced null, so this guard never fires.","On the CLI, always pass -i <spec> (and verify the path exists) so the input is loaded."],"exampleFix":"// before\nDefaultGenerator generator = new DefaultGenerator();\ngenerator.generate(); // RuntimeException: no OpenAPI attached\n// after\nCodegenConfigurator configurator = new CodegenConfigurator();\nconfigurator.setInputSpec(\"api.yaml\");\nconfigurator.setGeneratorName(\"java\");\nClientOptInput input = configurator.toClientOptInput();\nnew DefaultGenerator().opts(input).generate();","handlingStrategy":"validation","validationCode":"// Parse and attach the spec explicitly; fail before generate()\nio.swagger.v3.parser.core.models.SwaggerParseResult parsed =\n        new io.swagger.v3.parser.OpenAPIParser().readLocation(specPath, null, null);\nif (parsed.getOpenAPI() == null) {\n    throw new IllegalArgumentException(\"Unparseable spec \" + specPath + \": \" + parsed.getMessages());\n}\nClientOptInput input = new ClientOptInput();\ninput.setOpenAPI(parsed.getOpenAPI());\ninput.setConfig(CodegenConfigLoader.forName(generatorName));\nnew DefaultGenerator().opts(input).generate();","typeGuard":null,"tryCatchPattern":"try {\n    new DefaultGenerator().opts(input).generate();\n} catch (RuntimeException e) {\n    if (\"Issues with the OpenAPI input. Possible causes: invalid/missing spec, malformed JSON/YAML files, etc.\".equals(e.getMessage())) {\n        // setup bug: spec never attached. Re-run the parse+opts pipeline; do NOT retry generate() as-is.\n        throw new IllegalStateException(\"generate() called before opts() with a parsed spec\", e);\n    }\n    throw e;\n}","preventionTips":["Always construct opts via CodegenConfigurator.toClientOptInput() instead of hand-building ClientOptInput.","Fail fast on parse errors - never continue to generate() after a swallowed parse failure.","Wrap generation in a helper method that enforces spec-then-opts-then-generate ordering."],"tags":["openapi-generator","programmatic-usage","api-misuse","java"],"backgroundTag":"missing-openapi-spec-input","analyzedSha":"fcec517be3cf5b7964296bcba25fbc97541484e7","analyzedAt":"2026-08-22T11:13:11.613Z","schemaVersion":2},"datasetVersion":"2026-08-22T14:17:55.899Z"}