Skip to content

strict fiber server returns nothing when using schema with oneOf #1872

@holyfuchs

Description

@holyfuchs

oapi-codegen --version: v2.4.1
go 1.23.4

Generating code with the following config:

package: main
generate:
  fiber-server: true
  strict-server: true
  models: true

and a openapi.yaml with a oneof:

openapi: 3.0.0
paths:
  /test:
    get:
      responses:
        '200':
          description: Ok
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Test'
components:
  schemas:
    Test:
      oneOf:
        - $ref: '#/components/schemas/Test1'
        - $ref: '#/components/schemas/Test2'
    Test1:
      type: object
      properties:
        test1:
          type: string
      required:
        - test1
    Test2:
      type: object
      properties:
        test2:
          type: string
      required:
        - test2

generates code:

type Test struct {
	union json.RawMessage
}
type GetTest200JSONResponse Test
func (response GetTest200JSONResponse) VisitGetTestResponse(ctx *fiber.Ctx) error {
	ctx.Response().Header.Set("Content-Type", "application/json")
	ctx.Status(200)

	return ctx.JSON(&response)
}

since union starts with a lower case letter the endpoint won't return anything.
I would expect it to return my Test struct.

changing the generated code to return ctx.JSON(&response.union) fixed the issue

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions