{"record":{"id":"875c0bac5982f8d8","repo":"OpenAPITools/openapi-generator","slug":"failed-to-write-collapsed-spec-0-875c0b","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/ValidateMojo.java","lineNumber":468,"sourceCode":"    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(\n        new OpenAPIV3Parser().readLocation(inputFile, authorizationValues, parseOptions).getOpenAPI()).resolve();\n\n    // Switch based on JSON or YAML.\n    final var extension = inputFile.toLowerCase(Locale.ROOT).endsWith(\".json\") ? \".json\" : \".yaml\";\n    final var mapper = inputFile.toLowerCase(Locale.ROOT).endsWith(\".json\") ? Json.mapper() : Yaml.mapper();\n\n    // Write the merged spec to the output file.\n    final var collapsedSpecPath =\n        Paths.get(project.getBuild().getOutputDirectory(), 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(\n          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  private void logInvalid(Invalid invalid) {\n    LOGLEVEL loglevel = invalid.getSeverity() == Severity.ERROR ? LOGLEVEL.ERROR : LOGLEVEL.WARNING;\n    loglevel.logColored(getLog(), invalid.getMessage());\n    loglevel.log(getLog(), MessageUtils.buffer().format(\"Based on rule: %s\", invalid.getRule()).toString());\n    loglevel.log(getLog(), MessageUtils.buffer()\n        .format(isNotEmpty(invalid.getDetails()) ? \"Details: %s\" : \"No details available.\", invalid.getDetails())\n        .toString());\n    loglevel.logColored(getLog(), \"----------\");\n  }\n\n  private enum LOGLEVEL {","sourceCodeStart":450,"sourceCodeEnd":486,"githubUrl":"https://github.com/OpenAPITools/openapi-generator/blob/fcec517be3cf5b7964296bcba25fbc97541484e7/modules/openapi-generator-maven-plugin/src/main/java/org/openapitools/codegen/plugin/ValidateMojo.java#L450-L486","documentation":"Thrown by ValidateMojo when <collapsedSpec> is configured: the resolved spec is serialized and written to {project.build.outputDirectory}/<collapsedSpec>.json|.yaml (normally target/classes), and an IOException — typically because target/classes does not exist yet, is unwritable, or the path is blocked — is wrapped in a MojoExecutionException whose message embeds the target path.","triggerScenarios":"Validate goal with <collapsedSpec>merged</collapsedSpec> running in a phase before target/classes exists (validate/init phases on a fresh checkout); read-only or containerized output directory; target path occupied by a directory; file locked by another process during the write.","commonSituations":"Binding validate+collapse to an early lifecycle phase so there is nothing in target/ yet; CI with cached/partially restored target directories; Docker volumes mounted read-only; IDE or antivirus locks on Windows.","solutions":["Pre-create the directory: bind the goal after a phase that creates target/classes (e.g. process-classes) or add a mkdir step/antrun execution beforehand.","Check the path from the error message for a conflicting directory or lock and remove it.","Ensure the build user can write to ${project.build.outputDirectory} (permissions, volume mount mode).","If writing the collapsed spec during validation is unnecessary, remove <collapsedSpec>."],"exampleFix":"<!-- before: bound to validate phase on clean checkout, target/classes missing -->\n<execution>\n  <phase>validate</phase>\n  <goals><goal>validate</goal></goals>\n  <configuration><collapsedSpec>merged</collapsedSpec></configuration>\n</execution>\n\n<!-- after: bind later so target/classes exists -->\n<execution>\n  <phase>process-classes</phase>\n  <goals><goal>validate</goal></goals>\n  <configuration><collapsedSpec>merged</collapsedSpec></configuration>\n</execution>","handlingStrategy":"validation","validationCode":"# create target/classes before validating with collapsedSpec\nmkdir -p target/classes && mvn openapi-generator:validate","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Bind the validate-with-collapse execution to a phase after compile (e.g. process-classes or test), when target/classes exists.","On clean checkouts, add a mkdir/antrun step or rely on a later lifecycle phase instead of 'validate'.","Keep ${project.build.outputDirectory} writable in containers/CI.","Drop collapsedSpec from the validate goal unless the flattened artifact is actually consumed downstream."],"tags":["openapi-generator","maven","file-write","ioexception","collapsed-spec","lifecycle-binding"],"backgroundTag":"file-write-failed","analyzedSha":"fcec517be3cf5b7964296bcba25fbc97541484e7","analyzedAt":"2026-08-22T11:13:11.613Z","schemaVersion":2},"datasetVersion":"2026-08-22T14:17:55.899Z"}