-
-
Notifications
You must be signed in to change notification settings - Fork 995
Open
Description
- Go version:
go1.24.7 linux/amd64 oapi-codegenversion:v2.5.0- Configuration: default
- OpenAPI spec: 3.0.0
- Problem:
Consider a simple api.yaml:
openapi: 3.0.0
info:
title: api
version: 1.0.0
paths:
/foo:
get:
summary: foo
responses:
"200":
description: foo
content:
application/json:
schema:
$ref: '#/components/schemas/Foo'
/bar:
get:
summary: bar
responses:
"200":
description: bar
content:
application/json:
schema:
$ref: '#/components/schemas/Bar'
components:
schemas:
Foo:
type: object
required:
- foo
properties:
foo:
type: string
Bar:
type: object
properties:
bar:
type: string
allOf:
- $ref: '#/components/schemas/Foo'
- required:
- barInvoking oapi-codegen -generate types api.yaml, one ends up with:
// Package api provides primitives to interact with the openapi HTTP API.
//
// Code generated by github.com/oapi-codegen/oapi-codegen/v2 version v2.5.0 DO NOT EDIT.
package api
// Bar defines model for Bar.
type Bar struct {
Foo string `json:"foo"`
}
// Foo defines model for Foo.
type Foo struct {
Foo string `json:"foo"`
}This output is not what is expected.
- Expected:
// Package api provides primitives to interact with the openapi HTTP API.
//
// Code generated by github.com/oapi-codegen/oapi-codegen/v2 version v2.5.0 DO NOT EDIT.
package api
// Bar defines model for Bar.
type Bar struct {
Bar string `json:"bar"`
Foo string `json:"foo"`
}
// Foo defines model for Foo.
type Foo struct {
Foo string `json:"foo"`
}The above output could be achieved by supplying the following api.yaml:
openapi: 3.0.0
info:
title: api
version: 1.0.0
paths:
/foo:
get:
summary: foo
responses:
"200":
description: foo
content:
application/json:
schema:
$ref: '#/components/schemas/Foo'
/bar:
get:
summary: bar
responses:
"200":
description: bar
content:
application/json:
schema:
$ref: '#/components/schemas/Bar'
components:
schemas:
Foo:
type: object
required:
- foo
properties:
foo:
type: string
Bar:
allOf:
- $ref: '#/components/schemas/Foo'
- type: object
required:
- bar
properties:
bar:
type: string- Additional info: the first
api.yamlexample withoutpathsis rendered bycue export --out openapi+yaml api.cue
// api.cue
#Foo: {
foo: string
...
}
#Bar: #Foo & {
bar: string
}I'm not sure which behavior is the most valid. For comparison, openapi-generator-cli gives even weirder output:
// Bar struct for Bar
type Bar struct {
Bar *string `json:"bar,omitempty"`
Foo string `json:"foo"`
}Metadata
Metadata
Assignees
Labels
No labels