@@ -164,25 +164,17 @@ func RegisterOpenAPIOperation[T, B any](s *Server, method, path string) (*openap
164
164
bodyTag := tagFromType (* new (B ))
165
165
if (method == http .MethodPost || method == http .MethodPut || method == http .MethodPatch ) && bodyTag != "unknown-interface" && bodyTag != "string" {
166
166
167
- bodySchema , ok := s .OpenApiSpec .Components .Schemas [bodyTag ]
168
- if ! ok {
169
- var err error
170
- bodySchema , err = generator .NewSchemaRefForValue (new (B ), s .OpenApiSpec .Components .Schemas )
171
- if err != nil {
172
- return operation , err
173
- }
174
- s .OpenApiSpec .Components .Schemas [bodyTag ] = bodySchema
167
+ bodySchema , err := generator .NewSchemaRefForValue (new (B ), s .OpenApiSpec .Components .Schemas )
168
+ if err != nil {
169
+ return operation , err
175
170
}
176
171
172
+ content := openapi3 .NewContentWithSchema (bodySchema .Value , []string {"application/json" })
173
+ content ["application/json" ].Schema .Ref = "#/components/schemas/" + bodyTag
177
174
requestBody := openapi3 .NewRequestBody ().
178
175
WithRequired (true ).
179
- WithDescription ("Request body for " + reflect .TypeOf (* new (B )).String ())
180
-
181
- if bodySchema != nil {
182
- content := openapi3 .NewContentWithSchema (bodySchema .Value , []string {"application/json" })
183
- content ["application/json" ].Schema .Ref = "#/components/schemas/" + bodyTag
184
- requestBody .WithContent (content )
185
- }
176
+ WithDescription ("Request body for " + reflect .TypeOf (* new (B )).String ()).
177
+ WithContent (content )
186
178
187
179
s .OpenApiSpec .Components .RequestBodies [bodyTag ] = & openapi3.RequestBodyRef {
188
180
Value : requestBody ,
@@ -196,23 +188,17 @@ func RegisterOpenAPIOperation[T, B any](s *Server, method, path string) (*openap
196
188
}
197
189
198
190
tag := tagFromType (* new (T ))
199
- // Response body
200
- responseSchema , ok := s .OpenApiSpec .Components .Schemas [tag ]
201
- if ! ok {
202
- var err error
203
- responseSchema , err = generator .NewSchemaRefForValue (new (T ), s .OpenApiSpec .Components .Schemas )
204
- if err != nil {
205
- return operation , err
206
- }
207
- s .OpenApiSpec .Components .Schemas [tag ] = responseSchema
191
+ responseSchema , err := generator .NewSchemaRefForValue (new (T ), s .OpenApiSpec .Components .Schemas )
192
+ if err != nil {
193
+ return operation , err
208
194
}
209
195
210
- response := openapi3 .NewResponse (). WithDescription ( "OK" )
211
- if responseSchema != nil {
212
- content := openapi3 .NewContentWithSchema ( responseSchema . Value , [] string { "application/json" })
213
- content [ "application/json" ]. Schema . Ref = "#/components/schemas/" + tag
214
- response . WithContent (content )
215
- }
196
+ content := openapi3 .NewContentWithSchema ( responseSchema . Value , [] string { "application/json" } )
197
+ content [ "application/json" ]. Schema . Ref = "#/components/schemas/" + tag
198
+ response := openapi3 .NewResponse ().
199
+ WithDescription ( "OK" ).
200
+ WithContent (content )
201
+
216
202
operation .AddResponse (200 , response )
217
203
218
204
// Path parameters
0 commit comments