OpenAPITools / OpenAPITools/openapi-generator
[BUG] Generator 3.3.4 does not respect Java import mapping for string refs
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Description
I am trying to map a custom data type to a JSON string-valued property (more or less equivalent to a custom format); Jackson will transparently handle the conversion for me in Java. However, the generator does not observe user custom mappings when a $ref type is marked as a string.
openapi-generator version
This behavior is observed with 3.3.4
OpenAPI content
# correctly identifies that EntityIdentifier is a string and produces a Map<String, String>,
# but does not use the LSP to use a custom data type
components:
schemas:
EntityIdentifier:
type: string
pattern: '^\w+:[\w\d-]+$'
ResolveExpressionRequest:
type: object
properties:
expression:
type: string
minLength: 1
rootObject:
type: object
additionalProperties:
$ref: '#/components/schemas/EntityIdentifier'
# Generates a Map<String, EntityIdentifierDto>
components:
schemas:
EntityIdentifier:
type: object
ResolveExpressionRequest:
type: object
properties:
expression:
type: string
minLength: 1
rootObject:
type: object
additionalProperties:
$ref: '#/components/schemas/EntityIdentifier'
Command line used for generation
Invoked via Maven plugin:
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>3.3.4</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/openapi/openapi.yaml</inputSpec>
<generatorName>java</generatorName>
<importMappings>EntityIdentifier=foo.EntityIdentifierDto</importMappings>
<configOptions>
<library>resttemplate</library>
<java8>true</java8>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
Steps to reproduce
As above, a $ref that is of type: string does not get overridden by the custom mapping.
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
Use the Maven plugin configuration and supplied OpenAPI snippets to reproduce how the Java generator handles importMappings for a string-valued $ref in additionalProperties. Trace the Java generator's type-mapping path and add or run a regression test; done means the custom EntityIdentifier mapping is used for the generated Map value without changing ordinary string handling.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100