Skip to content

Commit

Permalink
revert that
Browse files Browse the repository at this point in the history
Signed-off-by: Pierre Fenoll <pierrefenoll@gmail.com>
  • Loading branch information
fenollp committed Nov 27, 2023
1 parent d6bc967 commit 0bb0935
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 47 deletions.
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -277,14 +277,19 @@ This will change the schema validation errors to return only the `Reason` field,

## CHANGELOG: Sub-v0 breaking API changes

### v0.121.0
* Introduce `openapi3.RequestBodies` (an alias on `map[string]*openapi3.ResponseRef`) and use it in place of `openapi3.Responses` for field `openapi3.Components.Responses`.
### next
* `(openapi3.Responses).Get(int)` renamed to `(*openapi3.Responses).Status(int)`
* `Responses` field of `openapi3.Components` is now a pointer
* `Paths` field of `openapi3.T` is now a pointer
* Package `openapi3`'s `NewResponses() *Responses` function was renamed to `NewResponses`

### next
* `(openapi3.Responses).Get(int)` renamed to `(*openapi3.Responses).Status(int)`
* `Responses` field of `openapi3.Components` is now a pointer
* `Paths` field of `openapi3.T` is now a pointer
* Package `openapi3`'s `NewResponses() *Responses` function was renamed to `NewEmptyResponses`

### v0.121.0
* Introduce `openapi3.RequestBodies` (an alias on `map[string]*openapi3.ResponseRef`) and use it in place of `openapi3.Responses` for field `openapi3.Components.Responses`.

### v0.116.0
* Dropped `openapi3filter.DefaultOptions`. Use `&openapi3filter.Options{}` directly instead.
Expand Down
19 changes: 9 additions & 10 deletions openapi3/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,22 @@ type Responses struct {
m map[string]*ResponseRef
}

// NewEmptyResponses creates an empty yet valid responses object
func NewEmptyResponses() *Responses {
return &Responses{
m: map[string]*ResponseRef{
"default": {Value: NewResponse().WithDescription("")},
},
}
}

// NewResponsesWithCapacity builds a responses object of the given capacity.
func NewResponsesWithCapacity(cap int) *Responses {
return &Responses{m: make(map[string]*ResponseRef, cap)}
}

// NewResponses builds a responses object with response objects in insertion order.
// Given no arguments, NewResponses returns a valid responses object containing a default match-all reponse.
func NewResponses(opts ...NewResponsesOption) *Responses {
responses := NewResponsesWithCapacity(len(opts))
var responses *Responses
if n := len(opts); n != 0 {
responses = NewResponsesWithCapacity(n)
} else {
responses = &Responses{m: map[string]*ResponseRef{
"default": {Value: NewResponse().WithDescription("")},
}}
}
for _, opt := range opts {
opt(responses)
}
Expand Down
2 changes: 1 addition & 1 deletion openapi3filter/req_resp_decoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1046,7 +1046,7 @@ func TestDecodeParameter(t *testing.T) {
op := &openapi3.Operation{
OperationID: "test",
Parameters: []*openapi3.ParameterRef{{Value: tc.param}},
Responses: openapi3.NewEmptyResponses(),
Responses: openapi3.NewResponses(),
}
doc.AddOperation(path, http.MethodGet, op)
err = doc.Validate(context.Background())
Expand Down
2 changes: 1 addition & 1 deletion openapi3filter/validate_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func ValidateResponse(ctx context.Context, input *ResponseValidationInput) error
if contentType == nil {
return &ResponseError{
Input: input,
Reason: fmt.Sprintf("response header Content-Type has unexpected value: %q", inputMIME),
Reason: fmt.Sprintf("response %s: %q", prefixInvalidCT, inputMIME),
}
}

Expand Down
10 changes: 5 additions & 5 deletions openapi3filter/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,13 @@ func TestFilter(t *testing.T) {
},
},
},
Responses: openapi3.NewEmptyResponses(),
Responses: openapi3.NewResponses(),
},
}),

openapi3.WithPath("/issue151", &openapi3.PathItem{
Get: &openapi3.Operation{
Responses: openapi3.NewEmptyResponses(),
Responses: openapi3.NewResponses(),
},
Parameters: openapi3.Parameters{
{
Expand Down Expand Up @@ -558,7 +558,7 @@ func TestRootSecurityRequirementsAreUsedIfNotProvidedAtTheOperationLevel(t *test
doc.Paths.Set(tc.name, &openapi3.PathItem{
Get: &openapi3.Operation{
Security: securityRequirements,
Responses: openapi3.NewEmptyResponses(),
Responses: openapi3.NewResponses(),
},
})
}
Expand Down Expand Up @@ -683,7 +683,7 @@ func TestAnySecurityRequirementMet(t *testing.T) {
doc.Paths.Set(tc.name, &openapi3.PathItem{
Get: &openapi3.Operation{
Security: securityRequirements,
Responses: openapi3.NewEmptyResponses(),
Responses: openapi3.NewResponses(),
},
})
}
Expand Down Expand Up @@ -785,7 +785,7 @@ func TestAllSchemesMet(t *testing.T) {
Security: &openapi3.SecurityRequirements{
securityRequirement,
},
Responses: openapi3.NewEmptyResponses(),
Responses: openapi3.NewResponses(),
},
})
}
Expand Down
28 changes: 14 additions & 14 deletions routers/gorillamux/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ import (
)

func TestRouter(t *testing.T) {
helloCONNECT := &openapi3.Operation{Responses: openapi3.NewEmptyResponses()}
helloDELETE := &openapi3.Operation{Responses: openapi3.NewEmptyResponses()}
helloGET := &openapi3.Operation{Responses: openapi3.NewEmptyResponses()}
helloHEAD := &openapi3.Operation{Responses: openapi3.NewEmptyResponses()}
helloOPTIONS := &openapi3.Operation{Responses: openapi3.NewEmptyResponses()}
helloPATCH := &openapi3.Operation{Responses: openapi3.NewEmptyResponses()}
helloPOST := &openapi3.Operation{Responses: openapi3.NewEmptyResponses()}
helloPUT := &openapi3.Operation{Responses: openapi3.NewEmptyResponses()}
helloTRACE := &openapi3.Operation{Responses: openapi3.NewEmptyResponses()}
paramsGET := &openapi3.Operation{Responses: openapi3.NewEmptyResponses()}
booksPOST := &openapi3.Operation{Responses: openapi3.NewEmptyResponses()}
partialGET := &openapi3.Operation{Responses: openapi3.NewEmptyResponses()}
helloCONNECT := &openapi3.Operation{Responses: openapi3.NewResponses()}
helloDELETE := &openapi3.Operation{Responses: openapi3.NewResponses()}
helloGET := &openapi3.Operation{Responses: openapi3.NewResponses()}
helloHEAD := &openapi3.Operation{Responses: openapi3.NewResponses()}
helloOPTIONS := &openapi3.Operation{Responses: openapi3.NewResponses()}
helloPATCH := &openapi3.Operation{Responses: openapi3.NewResponses()}
helloPOST := &openapi3.Operation{Responses: openapi3.NewResponses()}
helloPUT := &openapi3.Operation{Responses: openapi3.NewResponses()}
helloTRACE := &openapi3.Operation{Responses: openapi3.NewResponses()}
paramsGET := &openapi3.Operation{Responses: openapi3.NewResponses()}
booksPOST := &openapi3.Operation{Responses: openapi3.NewResponses()}
partialGET := &openapi3.Operation{Responses: openapi3.NewResponses()}
doc := &openapi3.T{
OpenAPI: "3.0.0",
Info: &openapi3.Info{
Expand Down Expand Up @@ -267,7 +267,7 @@ func TestServerPath(t *testing.T) {
}

func TestServerOverrideAtPathLevel(t *testing.T) {
helloGET := &openapi3.Operation{Responses: openapi3.NewEmptyResponses()}
helloGET := &openapi3.Operation{Responses: openapi3.NewResponses()}
doc := &openapi3.T{
OpenAPI: "3.0.0",
Info: &openapi3.Info{
Expand Down Expand Up @@ -308,7 +308,7 @@ func TestServerOverrideAtPathLevel(t *testing.T) {
}

func TestRelativeURL(t *testing.T) {
helloGET := &openapi3.Operation{Responses: openapi3.NewEmptyResponses()}
helloGET := &openapi3.Operation{Responses: openapi3.NewResponses()}
doc := &openapi3.T{
OpenAPI: "3.0.0",
Info: &openapi3.Info{
Expand Down
26 changes: 13 additions & 13 deletions routers/legacy/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ import (
)

func TestRouter(t *testing.T) {
helloCONNECT := &openapi3.Operation{Responses: openapi3.NewEmptyResponses()}
helloDELETE := &openapi3.Operation{Responses: openapi3.NewEmptyResponses()}
helloGET := &openapi3.Operation{Responses: openapi3.NewEmptyResponses()}
helloHEAD := &openapi3.Operation{Responses: openapi3.NewEmptyResponses()}
helloOPTIONS := &openapi3.Operation{Responses: openapi3.NewEmptyResponses()}
helloPATCH := &openapi3.Operation{Responses: openapi3.NewEmptyResponses()}
helloPOST := &openapi3.Operation{Responses: openapi3.NewEmptyResponses()}
helloPUT := &openapi3.Operation{Responses: openapi3.NewEmptyResponses()}
helloTRACE := &openapi3.Operation{Responses: openapi3.NewEmptyResponses()}
paramsGET := &openapi3.Operation{Responses: openapi3.NewEmptyResponses()}
booksPOST := &openapi3.Operation{Responses: openapi3.NewEmptyResponses()}
partialGET := &openapi3.Operation{Responses: openapi3.NewEmptyResponses()}
helloCONNECT := &openapi3.Operation{Responses: openapi3.NewResponses()}
helloDELETE := &openapi3.Operation{Responses: openapi3.NewResponses()}
helloGET := &openapi3.Operation{Responses: openapi3.NewResponses()}
helloHEAD := &openapi3.Operation{Responses: openapi3.NewResponses()}
helloOPTIONS := &openapi3.Operation{Responses: openapi3.NewResponses()}
helloPATCH := &openapi3.Operation{Responses: openapi3.NewResponses()}
helloPOST := &openapi3.Operation{Responses: openapi3.NewResponses()}
helloPUT := &openapi3.Operation{Responses: openapi3.NewResponses()}
helloTRACE := &openapi3.Operation{Responses: openapi3.NewResponses()}
paramsGET := &openapi3.Operation{Responses: openapi3.NewResponses()}
booksPOST := &openapi3.Operation{Responses: openapi3.NewResponses()}
partialGET := &openapi3.Operation{Responses: openapi3.NewResponses()}
doc := &openapi3.T{
OpenAPI: "3.0.0",
Info: &openapi3.Info{
Expand Down Expand Up @@ -199,7 +199,7 @@ func TestRouter(t *testing.T) {
Example: 3,
}
content := openapi3.NewContentWithJSONSchema(schema)
responses := openapi3.NewEmptyResponses()
responses := openapi3.NewResponses()
responses.Value("default").Value.Content = content
doc.Paths.Set("/withExamples", &openapi3.PathItem{
Get: &openapi3.Operation{Responses: responses},
Expand Down

0 comments on commit 0bb0935

Please sign in to comment.