From 08e20efaea1febf7b8c4debb0f3aa47edcdd5f17 Mon Sep 17 00:00:00 2001 From: Igor Tsiglyar Date: Mon, 13 Mar 2023 19:55:17 +0300 Subject: [PATCH] use_allof_for_refs: extend to example field --- protoc-gen-openapiv2/internal/genopenapi/template.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/protoc-gen-openapiv2/internal/genopenapi/template.go b/protoc-gen-openapiv2/internal/genopenapi/template.go index 3a3f539561a..09a3be23560 100644 --- a/protoc-gen-openapiv2/internal/genopenapi/template.go +++ b/protoc-gen-openapiv2/internal/genopenapi/template.go @@ -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}}