4

I want to generate our models based on an Openapi spec 3.0 yml definition. In my spec I have a definition using allOf to include the fields of the other components. When generating the models with the openapi-generator-maven-plugin. I see the following warning allOf with multiple schemas defined. Using only the first one.

The result is that only the first allOf definition's properties are included. While I expected all fields to be included. https://editor.swagger.io/ generates the schemas correct.

Why are not all properties defined in an allOf included?

Schema definition:

Dto:
  title: Dto
  type: object
  properties:
    created_by:
      type: string
      format: date-time

Foo:
  title: Foo
  type: object
  allOf:
    - $ref: '#/Dto'
  properties:
    fooProperty:
      type: string

Bar:
  title: Bar
  type: object
  allOf:
    - $ref: '#/Foo'
  properties:
    barProperty:
      type: string

maven plugin configuration:

        <plugin>
            <groupId>org.openapitools</groupId>
            <artifactId>openapi-generator-maven-plugin</artifactId>
            <version>6.1.0</version>
            <executions>
                <execution>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                    <configuration>
                        <inputSpec>myspec.yml</inputSpec>
                        <generatorName>spring</generatorName>
                        <generateApis>false</generateApis>
                        <generateSupportingFiles>false</generateSupportingFiles>
                        <configOptions>
                            <serializableModel>true</serializableModel>
                            <documentationProvider>none</documentationProvider>
                            <openApiNullable>false</openApiNullable>
                        </configOptions>
                    </configuration>
                </execution>
            </executions>
        </plugin>

The result is Bar with only the fields of Dto and Bar but not those of Foo. Why are not all properties defined in an allOf included?

appel500
  • 164
  • 1
  • 10
  • 1
    Did you find any answer? I am facing same issue..where generating kotlin files, it generates only allOf field, but no other properties are in generated class. Please let me know if you found a solution – sgupta Nov 15 '22 at 23:30
  • @sgupta https://github.com/OpenAPITools/openapi-generator/issues/10010 - no solution yet – appel500 Nov 18 '22 at 10:11

1 Answers1

3

The way allOf is processed has recently changed, as of v6.5.0, in order to deal with the exact issue you're describing. The changes were motivated by this issue, and introduced in this PR.

The new functionality is not default behaviour, however. In order to try it, you can use the REFACTOR_ALLOF_WITH_PROPERTIES_ONLY flag. The following example is for the openapi-generator-cli, though it can easily be extended to the Maven plugin using the openApiNormalizer configuration.

openapi-generator generate -g <target_language> -i <api_spec_file> -o gen --openapi-normalizer REFACTOR_ALLOF_WITH_PROPERTIES_ONLY=true
zeval
  • 147
  • 1
  • 10