OpenAPITools / OpenAPITools/openapi-generator
[BUG][jaxrs-spec] Generated code is not valid with additionalProperties
Open
Nobody has claimed this yet.
Issue: Bug
Server: Java
- 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)?
- What's the version of OpenAPI Generator used?
- Have you search for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Bounty to sponsor the fix (example)
Description
Generated code is not valid. A schema that has additional properties generates
private @Valid LocalizedString name = new java.util.HashMap<>();
Which is not valid it should've been
private @Valid LocalizedString name = new LocalizedString();
openapi-generator version
4.0.3
OpenAPI declaration file content or url
LocalizedString:
description: |
An object containing all the translations for a given object. Each key represents an
[IETF BCP 47](https://tools.ietf.org/html/bcp47) language tag.
type: object
title: Localized String
properties:
"und":
description: Represents `und`etermined which is used as the default when a more specialized version is not available.
type: string
additionalProperties:
x-additionalPropertiesName: language-tag
description: |
The key represents the [IETF BCP 47](https://tools.ietf.org/html/bcp47) language tag for clients to determine
what string to display.
type: string
example:
"und": "default locale"
"en": "English"
"en-CA": "Canadian English"
"en-US": "US English"
"zh": "Chinese"
"zh-CN": "China Chinese (Simplified)"
Command line used for generation
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>4.0.3</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<configOptions>
<apiPackage>com.devhaus.dlm.api</apiPackage>
<booleanGetterPrefix>is</booleanGetterPrefix>
<dateLibrary>java8</dateLibrary>
<fullJavaUtil>true</fullJavaUtil>
<invokerPackage>com.devhaus.dlm.api</invokerPackage>
<java8>true</java8>
<modelPackage>com.devhaus.dlm.api.model</modelPackage>
<useSwaggerAnnotations>false</useSwaggerAnnotations>
</configOptions>
<generatorName>jaxrs-spec</generatorName>
<inputSpec>${project.basedir}/src/main/resources/openapi.yml</inputSpec>
</configuration>
</execution>
</executions>
</plugin>
Steps to reproduce
Related issues/PRs
https://github.com/OpenAPITools/openapi-generator/issues/3388
Suggest a fix
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
Start by running the jaxrs-spec Maven generation with the provided OpenAPI YAML and inspect the generated LocalizedString model. Trace how additionalProperties determines the field initializer; done means the generated Java is valid and initializes the field as LocalizedString rather than HashMap.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi
- Domain
- api, backend, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100