FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

generating enum values for the query param · Issue #603 · oapi-codegen/oapi-codegen · GitHub

generating enum values for the query param #603

Description

Hi,
I met the strange behavior working with enums generation. The tool generates constants for the enums in the response body but doesn't generate them for the enums in the query param.

example.yaml:

openapi: "3.0.0"
info:
  version: 1.1.0
  title: Example for the oapi-codegen
  description: lol

components:
  schemas:
    Response:
      type: object
      properties:
        test:
          type: integer
        test_enum_field:
          type: string
          enum:
            - kek
            - lol
paths:
  /kek:
      get:
        description: ----
        operationId: getKek
        tags:
          - Example
        responses:
          "200":
            description: description
            content:
              application/json:
                schema:
                  $ref: "#/components/schemas/Response"
        parameters:
          - in: query
            name: enum_query
            schema:
              type: string
              enum:
                - arbidol
                - cheburek

command:

	oapi-codegen \
    		-generate=types,client \
    		-package oapigen \
    		./example.yaml \
    		> ./api.gen.go

the result api.gen.go will have:

// Defines values for ResponseTestEnumField.
const (
	ResponseTestEnumFieldKek ResponseTestEnumField = "kek"

	ResponseTestEnumFieldLol ResponseTestEnumField = "lol"
)

// Response defines model for Response.
type Response struct {
	Test          *int                   `json:"test,omitempty"`
	TestEnumField *ResponseTestEnumField `json:"test_enum_field,omitempty"`
}

// ResponseTestEnumField defines model for Response.TestEnumField.
type ResponseTestEnumField string

// GetKekParams defines parameters for GetKek.
type GetKekParams struct {
	EnumQuery *GetKekParamsEnumQuery `json:"enum_query,omitempty"`
}

// GetKekParamsEnumQuery defines parameters for GetKek.
type GetKekParamsEnumQuery string

So it generates GetKekParamsEnumQuery and ResponseTestEnumField but with constants only for the ResponseTestEnumField.

is it okay?

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


    Back | FazBrowse Home | New Git URL