swagger-codegen-generators icon indicating copy to clipboard operation
swagger-codegen-generators copied to clipboard

Fix discriminator property name and mapping $ref value

Open justinplus opened this issue 1 year ago • 0 comments

The discriminator property name should not be camel-cased, and the key-value pair of discriminator mappings map is reversed in latest code.

For example, this one-of definition would generate wrong java model interface as follows.

NewDeployment:
  oneOf:
    - $ref: '#/components/schemas/MappingDeployment'
  discriminator:
    propertyName: deployment_type
    mapping:
      mapping_deployment: '#/components/schemas/MappingDeployment'

Java model interface generated

@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "deploymentType", visible = true )
@JsonSubTypes({
    @JsonSubTypes.Type(value = #/components/schemas/MappingDeployment.class, name = "mapping_deployment"),
    @JsonSubTypes.Type(value = mapping_deployment.class, name = "MappingDeployment"),
})
public interface NewDeployment {
}

After fix, it would be

@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "deployment_type", visible = true )
@JsonSubTypes({
    @JsonSubTypes.Type(value = MappingDeployment.class, name = "mapping_deployment"),
})
public interface NewDeployment {
}

justinplus avatar May 21 '24 04:05 justinplus