Skip to content

Commit

Permalink
use_allof_for_refs: extend to example field
Browse files Browse the repository at this point in the history
  • Loading branch information
Igor Tsiglyar committed Mar 13, 2023
1 parent b45f184 commit 2456ccf
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions protoc-gen-openapiv2/internal/genopenapi/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -522,13 +522,16 @@ func renderMessageAsDefinition(msg *descriptor.Message, reg *descriptor.Registry
if fieldSchema.Ref != "" {
// Per the JSON Reference syntax: Any members other than "$ref" in a JSON Reference object SHALL be ignored.
// https://tools.ietf.org/html/draft-pbryan-zyp-json-ref-03#section-3
// However, use allOf to specify Title/Description/readOnly fields.
if fieldSchema.Title != "" || fieldSchema.Description != "" || fieldSchema.ReadOnly {
// However, use allOf to specify Title/Description/Example/readOnly fields.
if fieldSchema.Title != "" || fieldSchema.Description != "" || len(fieldSchema.Example) > 0 || fieldSchema.ReadOnly {
fieldSchema = openapiSchemaObject{
Title: fieldSchema.Title,
Description: fieldSchema.Description,
ReadOnly: fieldSchema.ReadOnly,
AllOf: []allOfEntry{{Ref: fieldSchema.Ref}},
schemaCore: schemaCore{
Example: fieldSchema.Example,
},
ReadOnly: fieldSchema.ReadOnly,
AllOf: []allOfEntry{{Ref: fieldSchema.Ref}},
}
} else {
fieldSchema = openapiSchemaObject{schemaCore: schemaCore{Ref: fieldSchema.Ref}}
Expand Down

0 comments on commit 2456ccf

Please sign in to comment.