Skip to content
Merged
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/MarkRosemaker/openapi v0.0.0-20261113130942-537594635ea6
github.com/MarkRosemaker/openapi-compress v0.0.0-20261113131228-7b6bdcd65ed0
github.com/MarkRosemaker/openapi-edit v0.0.0-20261113131039-6e51bd94c90a
github.com/MarkRosemaker/openapi-flatten v0.0.0-20261113131039-558dca5cc800
github.com/MarkRosemaker/openapi-flatten v0.0.0-20261113185414-039b4b0776ce
github.com/MarkRosemaker/ordmap v0.0.0-20261113130919-027ff7850b50
github.com/ettle/strcase v0.2.0
github.com/go-api-libs/api v0.0.0-20261113130130-277524695333
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ github.com/MarkRosemaker/openapi-edit v0.0.0-20261113131039-6e51bd94c90a h1:mPvS
github.com/MarkRosemaker/openapi-edit v0.0.0-20261113131039-6e51bd94c90a/go.mod h1:s1CNo5eZ9SoSjPXct1NozCbVHZy2mzpQ3pjRUaUcqtQ=
github.com/MarkRosemaker/openapi-enrich v0.0.0-20261010200623-3b942fefdf03 h1:RHXZfeyefM1V/GaxZJ+RAUVGBpAtdb2u6k6f7grWLiw=
github.com/MarkRosemaker/openapi-enrich v0.0.0-20261010200623-3b942fefdf03/go.mod h1:autrmEPWisPks3aJzJHcxKf8K6Mpk1Ph3jg1XywizDk=
github.com/MarkRosemaker/openapi-flatten v0.0.0-20261113131039-558dca5cc800 h1:HfWccZDJLpNFCesFvfBdKwTAXtiCfikX4LD6n86ziIA=
github.com/MarkRosemaker/openapi-flatten v0.0.0-20261113131039-558dca5cc800/go.mod h1:LCd6/pMJnpomikNTX3umKx+p1lUCqoKz08kQrqJTeqk=
github.com/MarkRosemaker/openapi-flatten v0.0.0-20261113185414-039b4b0776ce h1:Zh3CZXvuD3jdI83/2BO9s+q+KV2BECKroNyyK66IKa8=
github.com/MarkRosemaker/openapi-flatten v0.0.0-20261113185414-039b4b0776ce/go.mod h1:LCd6/pMJnpomikNTX3umKx+p1lUCqoKz08kQrqJTeqk=
github.com/MarkRosemaker/openapi-merge v0.0.0-20261009220258-57c4bc8ba894 h1:fK6ld3zdSy1tJcVa7S9kixkn5e/IyLVQHowed2yLLOU=
github.com/MarkRosemaker/openapi-merge v0.0.0-20261009220258-57c4bc8ba894/go.mod h1:JAAF3M82LuQyQ7+ByxhADsiy9e8ZxJQ8viAOsjrwS0c=
github.com/MarkRosemaker/ordmap v0.0.0-20261113130919-027ff7850b50 h1:jcbQ0v5NTZIus/UhQi/YtJT21+9bOMnlqndDBzynnjE=
Expand Down
7 changes: 6 additions & 1 deletion ir/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -576,12 +576,17 @@ func getField(jsonName string, propRef *openapi.Schema, requiredSet map[string]b
tag = strings.TrimSuffix(tag, `"`) + `,string"` // written as the string it mostly is
}

description := cmp.Or(propRef.Description, v.Description)
if nv := nullableVariant(v); description == "" && nv != nil {
description = cmp.Or(nv.Description, deref(nv).Description) // what X or null holds says what the field is
}

return Field{
Name: fieldName,
JSONName: jsonName,
Type: goType.String(),
JSONTag: tag,
Description: cmp.Or(propRef.Description, v.Description),
Description: description,
Required: required,
ReadOnly: propRef.ReadOnly || v.ReadOnly,
WriteOnly: propRef.WriteOnly || v.WriteOnly,
Expand Down
26 changes: 26 additions & 0 deletions ir/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ func TestFromDocument_FieldTypesAndTags(t *testing.T) {
"nullCount": {"oneOf": [{"type": "integer"}, {"type": "null"}]},
"nullName": {"oneOf": [{"type": "string"}, {"type": "null"}]},
"seed": {"anyOf": [{"type": "integer"}, {"type": "null"}], "default": 0},
"nullLimit": {"anyOf": [{"type": "integer"}, {"type": "null"}]},
"nullArchived": {"anyOf": [{"type": "boolean"}, {"type": "null"}], "default": false},
"limit": {"type": "integer"},
"pageSize": {"type": "integer", "minimum": 1},
Expand Down Expand Up @@ -296,6 +297,7 @@ func TestFromDocument_FieldTypesAndTags(t *testing.T) {
"tags": `[]string json:"tags"`,
"nullCount": `int json:"nullCount"`,
"seed": `int json:"seed,omitzero"`,
"nullLimit": `*int json:"nullLimit,omitzero"`,
"nullArchived": `bool json:"nullArchived,omitzero"`,
"nullName": `string json:"nullName"`,
"limit": `*int json:"limit,omitzero"`,
Expand All @@ -320,6 +322,30 @@ func TestFromDocument_FieldTypesAndTags(t *testing.T) {
}
}

func TestFromDocument_NullableRefDescription(t *testing.T) {
doc := loadSchemas(t, `{
"Pet": {
"type": "object",
"properties": {
"owner": {"anyOf": [{"$ref": "#/components/schemas/Owner"}, {"type": "null"}]},
"sitter": {"description": "Who looks after it", "anyOf": [{"$ref": "#/components/schemas/Owner"}, {"type": "null"}]},
"vet": {"anyOf": [{"description": "Who treats it", "$ref": "#/components/schemas/Owner"}, {"type": "null"}]}
}
},
"Owner": {"description": "A person", "type": "object", "required": ["id"], "properties": {"id": {"type": "string"}}}
}`)

got := map[string]string{}
for _, f := range schemaNamed(t, doc, "Pet").Fields {
got[f.JSONName] = f.Description
}

// a field of X or null says what X is, unless it or the reference to X says something of its own
if got["owner"] != "A person" || got["sitter"] != "Who looks after it" || got["vet"] != "Who treats it" {
t.Errorf("got %q", got)
}
}

func TestFromDocument_UnionFieldTypes(t *testing.T) {
t.Parallel()

Expand Down
4 changes: 4 additions & 0 deletions vendor/github.com/MarkRosemaker/openapi-flatten/README.md

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

23 changes: 23 additions & 0 deletions vendor/github.com/MarkRosemaker/openapi-flatten/schema.go

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

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ github.com/MarkRosemaker/openapi-compress
# github.com/MarkRosemaker/openapi-edit v0.0.0-20261113131039-6e51bd94c90a
## explicit; go 1.27
github.com/MarkRosemaker/openapi-edit
# github.com/MarkRosemaker/openapi-flatten v0.0.0-20261113131039-558dca5cc800
# github.com/MarkRosemaker/openapi-flatten v0.0.0-20261113185414-039b4b0776ce
## explicit; go 1.27
github.com/MarkRosemaker/openapi-flatten
# github.com/MarkRosemaker/ordmap v0.0.0-20261113130919-027ff7850b50
Expand Down
Loading