Search code examples
javayamlopenapicode-generation

How to combine two components using allOf in openapi yaml specification?


I try to generate java model classes from yaml specification using openapi-generator-maven-plugin:3.3.4. In one component I have allOf parameter trying to combine two different components by their refs. It goes like:

Flight: allOf: - $ref: '#/components/schemas/FlightReference' - $ref: '#/components/schemas/FlightItem'

What I got is Flight class which extends FlightReference, and FlightItem is not included in model at all. AFAIK in swagger-codegen-maven-plugin all properties from both classes was placed in class Flight, and current plugin introduces polymorphism instead, missing fields from second component.

Is there a way to create class which combines all parameters from two other components as in swagger 2.0 plugin?


Solution

  • 3.3.4 was released a while ago. Please upgrade to the latest stable version v4.2.3, which should solve the problem for you in terms of how allOf is handled.