swagger-api / swagger-codegen-generators

Apache License 2.0
284 stars 424 forks source link

Fix discriminator property name and mapping $ref value #1287

Open justinplus opened 6 months ago

justinplus commented 6 months ago

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 {
}