Skip to content

Commit 2456ccf

Browse files
author
Igor Tsiglyar
committed
use_allof_for_refs: extend to example field
1 parent b45f184 commit 2456ccf

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

protoc-gen-openapiv2/internal/genopenapi/template.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -522,13 +522,16 @@ func renderMessageAsDefinition(msg *descriptor.Message, reg *descriptor.Registry
522522
if fieldSchema.Ref != "" {
523523
// Per the JSON Reference syntax: Any members other than "$ref" in a JSON Reference object SHALL be ignored.
524524
// https://tools.ietf.org/html/draft-pbryan-zyp-json-ref-03#section-3
525-
// However, use allOf to specify Title/Description/readOnly fields.
526-
if fieldSchema.Title != "" || fieldSchema.Description != "" || fieldSchema.ReadOnly {
525+
// However, use allOf to specify Title/Description/Example/readOnly fields.
526+
if fieldSchema.Title != "" || fieldSchema.Description != "" || len(fieldSchema.Example) > 0 || fieldSchema.ReadOnly {
527527
fieldSchema = openapiSchemaObject{
528528
Title: fieldSchema.Title,
529529
Description: fieldSchema.Description,
530-
ReadOnly: fieldSchema.ReadOnly,
531-
AllOf: []allOfEntry{{Ref: fieldSchema.Ref}},
530+
schemaCore: schemaCore{
531+
Example: fieldSchema.Example,
532+
},
533+
ReadOnly: fieldSchema.ReadOnly,
534+
AllOf: []allOfEntry{{Ref: fieldSchema.Ref}},
532535
}
533536
} else {
534537
fieldSchema = openapiSchemaObject{schemaCore: schemaCore{Ref: fieldSchema.Ref}}

0 commit comments

Comments
 (0)