-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
Description
Description
Updating the openapi-generator-maven-plugin to 7.1.0 breaks all APIs which use models consisting only of additionalProperties. It looks like model generation is skipped for those models, however the API still uses them, and they're also beneficial for the code in general since they serve as an anti-corruption layer.
openapi-generator version
7.1.0
OpenAPI declaration file content or url
openapi: 3.0.3
info:
title: bug
version: 1.0.0
paths:
/test:
post:
responses:
default:
description: dummy response
content:
application/json:
schema:
type: object
requestBody:
description: additional properties only
content:
application/json:
schema:
$ref: '#/components/schemas/TestRequestBody'
operationId: getQuestionnaire
components:
schemas:
TestRequestBody:
type: object
description: A schema consisting only of additional properties
additionalProperties: trueGeneration Details
<!-- OpenAPI code generators -->
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>7.1.0</version>
<executions>
<execution>
<id>test</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/openapi/openapi-bug.yaml</inputSpec>
<generatorName>spring</generatorName>
<configOptions>
<library>spring-boot</library>
<interfaceOnly>true</interfaceOnly>
<serializableModel>true</serializableModel>
<useSpringBoot3>true</useSpringBoot3>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>Steps to reproduce
Generate the provided api-specification using the provided configuration.
The generator logs:
[INFO] Model TestRequestBody not generated since it's a free-form object
while the generated DefaultApi.java class uses:
default ResponseEntity<Object> getQuestionnaire(
@Parameter(name = "TestRequestBody", description = "additional properties only") @Valid @RequestBody(required = false) TestRequestBody testRequestBody
) {
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
}which doesn't compile, since the TestRequestBody class wasn't generated.
Related issues/PRs
Suggest a fix
Don't skip generation of free-form objects. There's a reason why the api-specification uses a separate schema with title to define the model, instead of using an inline object.