Summary
MapperPathUtil.buildResponse throws java.util.NoSuchElementException: No value present when an operation response is declared via a $ref that is not present in the pre-built response map — e.g. a response referenced from an external/multi-file location. The generator aborts instead of resolving the reference (or degrading gracefully).
Environment
- Plugin:
com.sngular:scs-multiapi-maven-plugin (reproduced on the 6.3.x/6.4.0 engine code)
- OpenAPI:
3.0/3.1, multi-file layout
Reproduction
An operation whose response is a $ref to a response defined outside the main file's components/responses, e.g.:
responses:
'200':
$ref: './responses/ServiceTypes.yml'
Generation fails with:
java.util.NoSuchElementException: No value present
at java.util.Optional.orElseThrow (Optional.java:377)
at com.sngular.api.generator.plugin.openapi.utils.MapperPathUtil.buildResponse (MapperPathUtil.java:347)
at com.sngular.api.generator.plugin.openapi.utils.MapperPathUtil.mapResponseObject (MapperPathUtil.java:327)
at com.sngular.api.generator.plugin.openapi.utils.MapperPathUtil.createOperation (MapperPathUtil.java:145)
...
Root cause
In buildResponse:
if (ApiTool.hasRef(response)) {
realResponse = globalObject.getResponseNode(MapperUtil.getRefSchemaKey(response)).orElseThrow();
}
globalObject.getResponseNode(...) only contains entries built from the main openapi.yml's components/responses (see ApiTool.getResponseSchemas / getComponentSchemasByType, keyed RESPONSES/<snake_name>). A response $ref that points to an external file (or whose key does not match) yields an empty Optional, and orElseThrow() aborts the whole generation.
Suggested fix
When the response ref is not found in the response map, fall back to resolving it from the filesystem (as getRefSchema already does for schemas via SchemaUtil.solveRef), and if it still cannot be resolved, degrade gracefully (treat as a no-content response) rather than throwing. Content-less responses (204/401/403/500, description only) must remain valid — mapContentObject already tolerates a null content.
Notes
A reproduction fixture (operation with an external response $ref, plus no-body responses) will be added with the fix.
Summary
MapperPathUtil.buildResponsethrowsjava.util.NoSuchElementException: No value presentwhen an operation response is declared via a$refthat is not present in the pre-built response map — e.g. a response referenced from an external/multi-file location. The generator aborts instead of resolving the reference (or degrading gracefully).Environment
com.sngular:scs-multiapi-maven-plugin(reproduced on the6.3.x/6.4.0engine code)3.0/3.1, multi-file layoutReproduction
An operation whose response is a
$refto a response defined outside the main file'scomponents/responses, e.g.:Generation fails with:
Root cause
In
buildResponse:globalObject.getResponseNode(...)only contains entries built from the mainopenapi.yml'scomponents/responses(seeApiTool.getResponseSchemas/getComponentSchemasByType, keyedRESPONSES/<snake_name>). A response$refthat points to an external file (or whose key does not match) yields an emptyOptional, andorElseThrow()aborts the whole generation.Suggested fix
When the response ref is not found in the response map, fall back to resolving it from the filesystem (as
getRefSchemaalready does for schemas viaSchemaUtil.solveRef), and if it still cannot be resolved, degrade gracefully (treat as a no-content response) rather than throwing. Content-less responses (204/401/403/500, description only) must remain valid —mapContentObjectalready tolerates a nullcontent.Notes
A reproduction fixture (operation with an external response
$ref, plus no-body responses) will be added with the fix.