Search code examples
javajax-rsopenapiopenapi-generatoropenapi-generator-maven-plugin

Howto map a given external type with Openapi codegen into a generated model class


I'm using Openapi 3.0.3 with openapi-generator-maven-plugin 6.6.0 and the jaxrs-spec generator.

I have to map a given type external to the API from a given external library in my schema definition, I tried with x-implements like:

myExternalTypeToMap:
    x-implements: 'path.to.external.type.that.should.be.mapped.MyExternalTypeToMap'
    x-field-extra-annotation: '@JsonIgnore'

but that gets mapped into the generated model class like this:

@JsonIgnore
private @Valid Object myExternalTypeToMap = null;

How can I get a mapping to:

@JsonIgnore
private @Valid path.to.external.type.that.should.be.mapped.MyExternalTypeToMap myExternalTypeToMap;

in my generated model class?


Solution

  • Well it kinda works with in the pom.xml

    <typeMappings>
        <typeMapping>MyExternalTypeToMap=path.to.external.type.that.should.be.mapped.MyExternalTypeToMap</typeMapping>
    </typeMappings>
    

    and in the schema yaml

    myExternalTypeToMap:
      x-field-extra-annotation: '@JsonIgnore'
      type: MyExternalTypeToMap
    

    what compiles to

    @JsonIgnore
    private @Valid path.to.external.type.that.should.be.mapped.MyExternalTypeToMap myExternalTypeToMap = null;
    

    what is good enough for the moment. Would like to get rid of the null initialization though.