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
4 changes: 4 additions & 0 deletions examples/extensions/xdeprecatedreason/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,7 @@ components:
type: number
# NOTE that this doesn't generate, as no `deprecated: true` is set
x-deprecated-reason: NOTE you shouldn't see this, as you've not deprecated this field
deprecated_without_reason:
type: string
deprecated: true
# no `x-deprecated-reason` is set
4 changes: 3 additions & 1 deletion examples/extensions/xdeprecatedreason/gen.go

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

4 changes: 2 additions & 2 deletions internal/test/schemas/schemas.gen.go

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

4 changes: 2 additions & 2 deletions pkg/codegen/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -705,8 +705,8 @@ func GenFieldsFromProperties(props []Property) []string {
// This comment has to be on its own line for godoc & IDEs to pick up
var deprecationReason string
if extension, ok := p.Extensions[extDeprecationReason]; ok {
if extOmitEmpty, err := extParseDeprecationReason(extension); err == nil {
deprecationReason = extOmitEmpty
if extDeprecationReason, err := extParseDeprecationReason(extension); err == nil {
deprecationReason = extDeprecationReason
}
}

Expand Down
2 changes: 2 additions & 0 deletions pkg/codegen/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,8 @@ func DeprecationComment(reason string) string {
content := "Deprecated:" // The colon is required at the end even without reason
if reason != "" {
content += fmt.Sprintf(" %s", reason)
} else {
content += " this property has been marked as deprecated upstream, but no `x-deprecated-reason` was set"
}

return stringToGoCommentWithPrefix(content, "")
Expand Down