{"record":{"id":"6dff3248cdc8edc5","repo":"OpenAPITools/openapi-generator","slug":"failed-to-write-collapsed-spec-0","errorCode":null,"errorMessage":"Failed to write collapsed spec {0}","messagePattern":"Failed to write collapsed spec (.+?)","errorType":"exception","errorClass":"MojoExecutionException","httpStatus":null,"severity":"error","filePath":"modules/openapi-generator-maven-plugin/src/main/java/org/openapitools/codegen/plugin/CodeGenMojo.java","lineNumber":1278,"sourceCode":"    private Path createCollapsedSpec() throws MojoExecutionException {\n        // Merge the OpenAPI spec file.\n        final var parseOptions = new ParseOptions();\n        parseOptions.setResolve(true);\n        final List<AuthorizationValue> authorizationValues = AuthParser.parse(this.auth);\n\n        final var openApiMerged = new OpenAPIResolver(new OpenAPIV3Parser().readLocation(inputSpec, authorizationValues, parseOptions).getOpenAPI()).resolve();\n\n        // Switch based on JSON or YAML.\n        final var extension = inputSpec.toLowerCase(Locale.ROOT).endsWith(\".json\") ? \".json\" : \".yaml\";\n        final var mapper = inputSpec.toLowerCase(Locale.ROOT).endsWith(\".json\") ? Json.mapper() : Yaml.mapper();\n\n        // Write the merged spec to the output file.\n        final var collapsedSpecPath = output.toPath().resolve(collapsedSpec + extension).toAbsolutePath();\n        try {\n            final var openApiString = mapper.writeValueAsString(openApiMerged);\n            FileUtils.writeStringToFile(collapsedSpecPath.toFile(), openApiString, StandardCharsets.UTF_8);\n        } catch (final IOException e) {\n            throw new MojoExecutionException(new MessageFormat(\"Failed to write collapsed spec {0}\", Locale.ROOT).format(collapsedSpecPath), e);\n        }\n\n        // Return the path to the collapsed spec file.\n        return collapsedSpecPath;\n    }\n}\n","sourceCodeStart":1260,"sourceCodeEnd":1285,"githubUrl":"https://github.com/OpenAPITools/openapi-generator/blob/fcec517be3cf5b7964296bcba25fbc97541484e7/modules/openapi-generator-maven-plugin/src/main/java/org/openapitools/codegen/plugin/CodeGenMojo.java#L1260-L1285","documentation":"Thrown by CodeGenMojo when the <collapsedSpec> option is used: after resolving/merging the spec, the plugin serializes it to output/<collapsedSpec>.json|.yaml, and an IOException from mapper.writeValueAsString or FileUtils.writeStringToFile is wrapped in this MojoExecutionException whose message embeds the target path via MessageFormat. The writer does not create parent directories, so a missing output directory is the most common cause.","triggerScenarios":"Configuring <collapsedSpec>merged</collapsedSpec> in the generate goal while the plugin <output> directory does not exist yet or is not writable; the target path collides with an existing directory; disk full or filesystem lock (e.g. antivirus/IDE holding the file) during the write.","commonSituations":"First use of the collapsedSpec feature on a fresh checkout where target/ has not been created; read-only output locations in containers; Windows file locks from an IDE or indexer; very large merged specs exhausting disk space.","solutions":["Pre-create the parent directory (mvn clean or any phase that creates target/) or point <output> at a location that exists and is writable.","Check the path in the error message: if a directory occupies the target file name, rename or remove it.","Free disk space / remove file locks (close IDE watchers, exclude the folder from antivirus scanning) and rerun.","If the directory is inherently read-only, change <output> to a writable path."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"# ensure the collapsed-spec parent directory exists before the mojo runs\nmkdir -p target/generated-sources && mvn openapi-generator:generate","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Bind the generate goal to a phase after target/ is created (e.g. generate-sources), never to validate on a clean tree, when using collapsedSpec.","Keep the plugin <output> on a writable local filesystem, not a read-only container volume.","Exclude generated/collapsed spec output from IDE and antivirus file watchers to avoid locks.","If you do not need the flattened spec artifact, leave collapsedSpec unset."],"tags":["openapi-generator","maven","file-write","ioexception","spec-merging","collapsed-spec"],"backgroundTag":"file-write-failed","analyzedSha":"fcec517be3cf5b7964296bcba25fbc97541484e7","analyzedAt":"2026-08-22T11:13:11.613Z","schemaVersion":2},"datasetVersion":"2026-08-22T14:17:55.899Z"}