Generated code references missing enum type
openapi: 3.0.2
servers:
- url: /api
info:
title: Demo
version: 0.0.1
paths:
/demo:
get:
responses:
200:
$ref: "#/components/responses/DemoBrokenResponse"
components:
responses:
DemoBrokenResponse:
description: |
Generated struct tries to reference an enum,
but no type gets generated for that enum.
Code does not compile.
content:
application/json:
schema:
type: object
required: [some_property]
properties:
some_property:
type: string
enum: ["Some Value", "Some Other Value"]
Running oapi-codegen -o repro.gen.go -package openapi -generate types repro.yml gives you
// Package openapi provides primitives to interact with the openapi HTTP API.
//
// Code generated by github.com/deepmap/oapi-codegen version v1.8.3 DO NOT EDIT.
package openapi
// DemoBrokenResponse defines model for DemoBrokenResponse.
type DemoBrokenResponse struct {
SomeProperty DemoBrokenResponseSomeProperty `json:"some_property"`
}
The DemoBrokenResponseSomeProperty type is missing.

Running v1.8.3
I have confirmed this to be the case on my end. One work around is to specify a schema and then reference the schema in the response.
components:
schemas:
this-worky:
title: this-worky
description: this should worky
type: object
properties:
some_property:
type: string
enum: ["Some Value", "Some Other Value"]
responses:
this-worky:
content:
application/json:
schema:
$ref: '#/components/schemas/this-worky'
description: this is a workaround
Are there any updates on this one? We are facing the same issue and our workaround is to define it as a string instead which is not great. Thank you!
any updates?
I think I have got to the same issue
Bumping this issue up. While referencing in a schema works as a workaround, it would be ideal to have this resolved to avoid cluttering schemas with types that are only used once in this specific context.
I am having the same issue and workaround doesnt work for me as i have separate my spec into multiple packages :|