oapi-codegen
oapi-codegen copied to clipboard
Strict server generates invalid code if response list items are polymorphic
spec.yaml
openapi: 3.0.3
info:
description: Example
version: "1.0.0"
title: Example
paths:
/test:
get:
tags:
- Tag
summary: Summary
operationId: op_id
responses:
200:
description: OK
content:
application/json:
schema:
type: object
properties:
polymorphic_list:
type: array
description: polymorphic list
items:
anyOf:
- type: string
- type: number
config.yaml
output:
out.gen.go
package: tmp
generate:
models: true
strict-server: true
chi-server: false
client: false
echo-server: false
embedded-spec: false
gin-server: false
gorilla-server: false
out.gen.go:
// Package tmp provides primitives to interact with the openapi HTTP API.
//
// Code generated by github.com/deepmap/oapi-codegen version v1.11.1-0.20221003111356-96482c12b2bc DO NOT EDIT.
package tmp
import (
"context"
"encoding/json"
"net/http"
)
type OpIdRequestObject struct {
}
type OpIdResponseObject interface {
VisitOpIdResponse(w http.ResponseWriter) error
}
type OpId200JSONResponse struct {
// PolymorphicList polymorphic list
PolymorphicList *[]OpId200JSONResponse_PolymorphicList_Item `json:"polymorphic_list,omitempty"`
}
func (response OpId200JSONResponse) VisitOpIdResponse(w http.ResponseWriter) error {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(200)
return json.NewEncoder(w).Encode(response)
}
// StrictServerInterface represents all server handlers.
type StrictServerInterface interface {
// Summary
// (GET /test)
OpId(ctx context.Context, request OpIdRequestObject) (OpIdResponseObject, error)
}
complaint from go vet:
% go vet out.gen.go
# command-line-arguments
vet: ./out.gen.go:21:21: undeclared name: OpId200JSONResponse_PolymorphicList_Item
generated with: oapi-codegen -config config.yaml spec.yaml
version:
github.com/deepmap/oapi-codegen/cmd/oapi-codegen
v1.11.1-0.20221003111356-96482c12b2bc
I expect that missing type to be generated, but it is not.