openapi-processor-spring icon indicating copy to clipboard operation
openapi-processor-spring copied to clipboard

Generating a oneOf interface results in 'repeated interface' error

Open juniorhamish opened this issue 2 months ago • 1 comments

Generation of the oneOf interface works fine if you only reference it once in the spec. For every time you reference the interface it seems like the code generator adds another 'implements' to the same model class.

If I take the example from the docs and add in an additional path that also references the Foo schema:

 /foo:
    get:
      responses:
        '200':
          description: oneOf
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Foo'
  /bar:
    get:
      responses:
        '200':
          description: oneOf
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Foo'

Then the result of the generation is that the generated DTO implements FooOneOfDTO twice, which results in a compilation error:

Image

For completeness, here is the spec file I was using, which was built upon from the docs (which omitted some of the file for brevity, so I've filled it in myself)

openapi: 3.1.0
info:
  title: oneOf marker interface
  version: 1.0.0

paths:
  /foo:
    get:
      responses:
        '200':
          description: oneOf
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Foo'
  /bar:
    get:
      responses:
        '200':
          description: oneOf
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Foo'

components:
  schemas:

    Foo:
      type: object
      properties:
        foo:
          $ref: '#/components/schemas/FooOneOf'
    Bar:
      type: object
      properties:
        x:
          type: string
    Baz:
      type: object
      properties:
        y:
          type: string

    FooOneOf:
      oneOf:
        - $ref: '#/components/schemas/Baz'
        - $ref: '#/components/schemas/Bar'

juniorhamish avatar Nov 11 '25 18:11 juniorhamish

Thanks for reporting :-)

hauner avatar Nov 13 '25 08:11 hauner