Skip to content

Anonymous object schema with oneof cannot be generated properly #1496

Closed

Description

@alexpyc

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

Activity

  1. alexpyc commented on Mar 11, 2024

    @alexpyc
    Author

    It seems related to issue #636

  2. alexpyc commented on Mar 16, 2024

    @alexpyc
    Author

    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'
    
  3. added
    area:*of
    on Mar 25, 2024
  4. added this to the v2.6.0 milestone on Nov 28, 2024
  5. nanderv commented on Jan 23, 2025

    @nanderv

    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'
    

    Note that this approach does not work for arrays of oneofs, because of a different bug.

  6. mromaszewicz commented on Apr 30, 2026

    @mromaszewicz
    Member

    This was fixed in #2348

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:*of

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions