OpenAPITools / OpenAPITools/openapi-generator
[BUG][JAVA] Syntax error generating JAVA class from params object with certain schema
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
Generator generates broken (meaning it contains syntax error) class when an endpoint parameter schema object
- has a
propertywhich is also anobjectand - that property object has both some
propertiesandadditionalPropertiesspecified of same type.
Please note "PostParams" schema below.
openapi-generator version
5.1.1, 5.2.0
OpenAPI declaration file content or url
openapi: 3.0.1
info:
title: Example API
version: 0.0.1
servers:
- url: http://example.com
paths:
/content:
post:
summary: Fetch 'something' using a POST request
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/PostParams'
responses:
200:
description: The fetched 'something'
content:
application/json:
schema:
type: object
components:
schemas:
PostParams:
type: object
properties:
mapOfStringLists:
type: object
description: ARBITRARY map of string lists.
additionalProperties:
type: array
items:
type: string
properties:
property1:
type: array
items:
type: string
Generation Details
Running mvn build generates the following function (improper!!!) in PostParams.java:
public PostParams putMapOfStringListsItem(String key, List<String> mapOfStringListsItem) {
if (this.mapOfStringLists == null) {
this.mapOfStringLists = ; // NOTE THE MISSING ASSIGNMENT HERE!!!
}
this.mapOfStringLists.put(key, mapOfStringListsItem);
return this;
}
Steps to reproduce
Run mvn build having the following in pom.xml:
<build>
<plugins>
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>${openapi-generator.version}</version>
<executions>
<execution>
<id>someid</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>path/to/swagger.yaml</inputSpec>
<generatorName>java</generatorName>
<library>rest-assured</library>
<output>target/openapi</output>
<apiPackage>some.package.name</apiPackage>
<modelPackage>some.model.name</modelPackage>
<configOptions>
<interfaceOnly>true</interfaceOnly>
<sourceFolder>src/gen/java</sourceFolder>
<dateLibrary>java8</dateLibrary>
<serializationLibrary>jackson</serializationLibrary>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Related issues/PRs
My search criteria was: https://github.com/OpenAPITools/openapi-generator/issues?q=is%3Aissue+is%3Aopen+in%3Atitle+%5BJAVA%5D+additionalProperties+
Most relevant issue (in my read) which is only similar (only) is: https://github.com/OpenAPITools/openapi-generator/issues/9791
Suggest a fix
I cannot suggest a fix unfortunately.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with the provided OpenAPI declaration and Maven configuration, then inspect the generated PostParams.java for the missing assignment. Trace the Java generator handling of a nested object that combines properties and additionalProperties of the same type, and add regression coverage showing that the generated class compiles with the expected assignment.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi
- Domain
- api, devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100