OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
20.51k stars 6.27k forks source link

Fix issue 18889,15274 - configOptions to not remove enum prefix and oneOf subtypes annotations example #18998

Open rodrigoma3 opened 6 days ago

rodrigoma3 commented 6 days ago
  1. configOptions to not remove enum prefix: An option was implemented to not remove the common prefix between enums, but it was not available in the documentation and does not work by adding it to configOptions. I just added it to cliOptions so that it appears in the documentation and works through configOptions in the pom. merged: #5166 fix #18889
<configOptions>
    <removeEnumValuePrefix>false</removeEnumValuePrefix>
</configOptions>
  1. oneOf subtypes annotations example: I created a test to show how using oneOf with mapping works without duplicating class mappings. fix #15274

example

@JsonIgnoreProperties(
  value = "petType", // ignore manually set petType, it will be automatically generated by Jackson during serialization
  allowSetters = true // allows the petType to be set during deserialization
)
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "petType", visible = true)
@JsonSubTypes({
  @JsonSubTypes.Type(value = Cat.class, name = "PET_CAT"),
  @JsonSubTypes.Type(value = Dog.class, name = "PET_DOG"),
  @JsonSubTypes.Type(value = Lizard.class, name = "PET_LIZARD")
})

@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", date = "2024-06-22T15:24:51.304753300-03:00[America/Sao_Paulo]", comments = "Generator version: unset")
public interface Pet {
    public PetType getPetType();
}

PR checklist

@cachescrubber (2022/02) @welshm (2022/02) @MelleD (2022/02) @atextor (2022/02) @manedev79 (2022/02) @javisst (2022/02) @borsch (2022/02) @banlevente (2022/02) @Zomzog (2022/09) @wing328

rodrigoma3 commented 5 days ago

@welshm

Looks good to me - although ideally we don't need to replicate each option in each sub-generator and can just refer to the global option

I agree. However, the project is very big and I'm still getting to know it. For now, I will continue as is being done as I believe it is safer. In the future maybe I will be a little more daring.

rodrigoma3 commented 3 days ago

fix #18889 #15274