Skip to content

Commit

Permalink
Splits the auto-response declaration and response body into two separ…
Browse files Browse the repository at this point in the history
…ate steps
  • Loading branch information
EwenQuim committed Dec 9, 2024
1 parent c790479 commit 63cf58a
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions openapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,18 @@ func RegisterOpenAPIOperation[T, B any](s *Server, route Route[T, B]) (*openapi3
}

// Automatically add non-declared 200 Response
if route.Operation.Responses.Value("200") == nil {
response200 := route.Operation.Responses.Value("200")
if response200 == nil {
response := openapi3.NewResponse().WithDescription("OK")
route.Operation.AddResponse(200, response)
response200 = route.Operation.Responses.Value("200")
}

// Automatically add non-declared Content for 200 Response
if response200.Value.Content == nil {
responseSchema := SchemaTagFromType(s, *new(T))
content := openapi3.NewContentWithSchemaRef(&responseSchema.SchemaRef, []string{"application/json", "application/xml"})
response := openapi3.NewResponse().WithDescription("OK").WithContent(content)
route.Operation.AddResponse(200, response)
response200.Value.WithContent(content)
}

// Automatically add non-declared Path parameters
Expand Down

0 comments on commit 63cf58a

Please sign in to comment.