OpenAPITools / OpenAPITools/openapi-generator

[BUG] Generator 3.3.4 does not respect Java import mapping for string refs

Open
#2,858 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.