Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions internal/test/all_of/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ package allof

//go:generate go run github.com/deepmap/oapi-codegen/cmd/oapi-codegen --config=config1.yaml openapi.yaml
//go:generate go run github.com/deepmap/oapi-codegen/cmd/oapi-codegen --config=config2.yaml openapi.yaml
//go:generate go run github.com/deepmap/oapi-codegen/cmd/oapi-codegen --config=embed-config.yaml embed-openapi.yaml
7 changes: 7 additions & 0 deletions internal/test/all_of/embed-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package: v2
generate:
models: true
embedded-spec: true
output-options:
skip-prune: true
output: embed/openapi.gen.go
44 changes: 44 additions & 0 deletions internal/test/all_of/embed-openapi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
openapi: "3.0.1"
info:
version: 1.0.0
title: Tests AllOf composition
paths: {}
components:
schemas:
PersonProperties:
type: object
description: |
These are fields that specify a person. They are all optional, and
would be used by an `Edit` style API endpoint, where each is optional.
properties:
FirstName:
type: string
LastName:
type: string
GovernmentIDNumber:
type: integer
format: int64
FirstName:
type: object
properties:
FirstName:
type: string
Person:
type: object
x-go-allof-embed-refs: true
description: |
This is a person, with mandatory first and last name, but optional ID
number. This would be returned by a `Get` style API. We merge the person
properties with another Schema which only provides required fields.
allOf:
- $ref: "#/components/schemas/PersonProperties"
- required: [ FirstName, LastName ]
- $ref: "#/components/schemas/FirstName"
PersonAllOfSingle:
type: object
x-go-allof-embed-refs: true
description: |
This is a person record as returned from a Create endpoint. It contains
all the fields of a Person, with an additional resource UUID.
allOf:
- $ref: "#/components/schemas/Person"
124 changes: 124 additions & 0 deletions internal/test/all_of/embed/openapi.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions internal/test/all_of/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,10 @@ components:
type: integer
format: int64
required: [ ID ]
PersonAllOfSingle:
type: object
description: |
This is a person record as returned from a Create endpoint. It contains
all the fields of a Person, with an additional resource UUID.
allOf:
- $ref: "#/components/schemas/Person"
29 changes: 18 additions & 11 deletions internal/test/all_of/v1/openapi.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 19 additions & 11 deletions internal/test/all_of/v2/openapi.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 13 additions & 1 deletion internal/test/issues/issue-1087/deps/deps.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 15 additions & 1 deletion pkg/codegen/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ const (
// extGoName is used to override a field name
extGoName = "x-go-name"
// extGoTypeName is used to override a generated typename for something.
extGoTypeName = "x-go-type-name"
extGoTypeName = "x-go-type-name"
// extGoAllOfEmbedRefs is used to generate allOfs with refs that embedded structs (this generation can fail if it generates objects which have overlapping fields)
extGoAllOfEmbedRefs = "x-go-allof-embed-refs"
extPropGoJsonIgnore = "x-go-json-ignore"
extPropOmitEmpty = "x-omitempty"
extPropExtraTags = "x-oapi-codegen-extra-tags"
Expand All @@ -32,6 +34,18 @@ func extString(extPropValue interface{}) (string, error) {
return str, nil
}

func ReadExtGoAllOfEmbedRefs(extensions map[string]interface{}) (bool, error) {
extPropValue, ok := extensions[extGoAllOfEmbedRefs]
if !ok {
return false, nil
}
v, ok := extPropValue.(bool)
if !ok {
return false, fmt.Errorf("for %s failed to read as boolean: %T", extGoAllOfEmbedRefs, extPropValue)
}
return v, nil
}

func extTypeName(extPropValue interface{}) (string, error) {
return extString(extPropValue)
}
Expand Down
Loading