oapi-codegen icon indicating copy to clipboard operation
oapi-codegen copied to clipboard

Anonymous object schema with oneof cannot be generated properly

Open alexpyc opened this issue 1 year ago • 1 comments

Following example masked any identifying information

      responses:
        200:
          description: "Success"
          content:
            application/json:
              schema:
                title: SomethingSuccess
                type: object
                required:
                - results
                properties:
                  results:
                    type: array
                    items:
                      anyOf:
                      - type: object
                        properties:
                          order:
                            $ref: '#/components/schemas/Order'
                      - type: object
                        properties:
                          error:
                            type: object
                            properties:
                              code:
                                type: number
                                example: 400
                              error:
                                type: string
                                example: ERROR_MISSING_PARAMETER
                              message:
                                type: string
                                example: Parameter `id` is missing

The above example will generate a struct with field Results of type []200_Results_Item in-line in the generated go code, example:

var dest struct {
    Results []200_Results_Item`json:results`
}

I am using v1.15.0

alexpyc avatar Mar 11 '24 07:03 alexpyc

It seems related to issue #636

alexpyc avatar Mar 11 '24 07:03 alexpyc

Update: I managed to "circumvent" the error but factoring out the schema into a component

      responses:
        200:
          description: "Success"
          content:
            application/json:
              schema:
                $ref: /#/components/schemas/SomethingSuccess'

alexpyc avatar Mar 16 '24 14:03 alexpyc