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?
Reactions are currently unavailable
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 - cheburekcommand:
oapi-codegen \ -generate=types,client \ -package oapigen \ ./example.yaml \ > ./api.gen.gothe 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 stringSo it generates GetKekParamsEnumQuery and ResponseTestEnumField but with constants only for the ResponseTestEnumField.
is it okay?