Skip to content

Cookies will never be used when generating a fiber server #1752

@nikitaRykhlov

Description

@nikitaRykhlov

The version of oapi-codegen you're using - v2.1.0

The YAML configuration file you're using:

package: openapi
generate:
  fiber-server: true
  models: true
output: server_interface_gen.go

The OpenAPI spec you're using:

openapi: "3.0.0"
info:
  version: 1.0.0
  title: Minimal ping API server
paths:
  /ping:
    get:
      parameters:
        - in: cookie
          name: some_name
          required: true
          schema:
            type: string
      responses:
        '200':
          description: pet response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Pong'
components:
  schemas:
    # base types
    Pong:
      type: object
      required:
        - ping
      properties:
        ping:
          type: string
          example: pong

What problem you're seeing:

Here you can see that the parameter received from the cookie will simply not be used.

// GetPing operation middleware
func (siw *ServerInterfaceWrapper) GetPing(c *fiber.Ctx) error {

	var err error

	// Parameter object where we will unmarshal all parameters from the context
	var params GetPingParams

	var cookie string

	if cookie = c.Cookies("some_name"); cookie == "" {
		var value string
		err = runtime.BindStyledParameterWithOptions("simple", "some_name", cookie, &value, runtime.BindStyledParameterOptions{Explode: true, Required: true})
		if err != nil {
			return fiber.NewError(fiber.StatusBadRequest, fmt.Errorf("Invalid format for parameter some_name: %w", err).Error())
		}
		params.SomeName = value

	} else {
		err = fmt.Errorf("Query argument some_name is required, but not found")
		return fiber.NewError(fiber.StatusBadRequest, err.Error())
	}

	return siw.Handler.GetPing(c, params)
}

What the expected behaviour is:

I expect the value obtained from the cookie to be passed to the request handler.

What version of Go you're using:

go1.22.6 darwin/arm64

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions