Skip to content

Commit

Permalink
Merge branch 'master' into issue709
Browse files Browse the repository at this point in the history
  • Loading branch information
Steve Lessard committed Dec 16, 2022
2 parents 09bb970 + 35bb627 commit db1cc91
Show file tree
Hide file tree
Showing 27 changed files with 248 additions and 65 deletions.
2 changes: 1 addition & 1 deletion openapi3/callback.go
Expand Up @@ -26,7 +26,7 @@ func (c Callbacks) JSONLookup(token string) (interface{}, error) {
}

// Callback is specified by OpenAPI/Swagger standard version 3.
// See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#callbackObject
// See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#callback-object
type Callback map[string]*PathItem

// Validate returns an error if Callback does not comply with the OpenAPI spec.
Expand Down
2 changes: 1 addition & 1 deletion openapi3/components.go
Expand Up @@ -10,7 +10,7 @@ import (
)

// Components is specified by OpenAPI/Swagger standard version 3.
// See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#componentsObject
// See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#components-object
type Components struct {
ExtensionProps `json:"-" yaml:"-"`

Expand Down
2 changes: 1 addition & 1 deletion openapi3/discriminator.go
Expand Up @@ -7,7 +7,7 @@ import (
)

// Discriminator is specified by OpenAPI/Swagger standard version 3.
// See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#discriminatorObject
// See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#discriminator-object
type Discriminator struct {
ExtensionProps `json:"-" yaml:"-"`

Expand Down
2 changes: 1 addition & 1 deletion openapi3/doc.go
@@ -1,4 +1,4 @@
// Package openapi3 parses and writes OpenAPI 3 specification documents.
//
// See https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md
// See https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md
package openapi3
2 changes: 1 addition & 1 deletion openapi3/encoding.go
Expand Up @@ -9,7 +9,7 @@ import (
)

// Encoding is specified by OpenAPI/Swagger 3.0 standard.
// See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#encodingObject
// See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#encoding-object
type Encoding struct {
ExtensionProps `json:"-" yaml:"-"`

Expand Down
2 changes: 1 addition & 1 deletion openapi3/example.go
Expand Up @@ -28,7 +28,7 @@ func (e Examples) JSONLookup(token string) (interface{}, error) {
}

// Example is specified by OpenAPI/Swagger 3.0 standard.
// See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#exampleObject
// See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#example-object
type Example struct {
ExtensionProps `json:"-" yaml:"-"`

Expand Down
2 changes: 1 addition & 1 deletion openapi3/header.go
Expand Up @@ -28,7 +28,7 @@ func (h Headers) JSONLookup(token string) (interface{}, error) {
}

// Header is specified by OpenAPI/Swagger 3.0 standard.
// See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#headerObject
// See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#header-object
type Header struct {
Parameter
}
Expand Down
6 changes: 3 additions & 3 deletions openapi3/info.go
Expand Up @@ -8,7 +8,7 @@ import (
)

// Info is specified by OpenAPI/Swagger standard version 3.
// See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#infoObject
// See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#info-object
type Info struct {
ExtensionProps `json:"-" yaml:"-"`

Expand Down Expand Up @@ -58,7 +58,7 @@ func (info *Info) Validate(ctx context.Context, opts ...ValidationOption) error
}

// Contact is specified by OpenAPI/Swagger standard version 3.
// See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#contactObject
// See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#contact-object
type Contact struct {
ExtensionProps `json:"-" yaml:"-"`

Expand All @@ -85,7 +85,7 @@ func (contact *Contact) Validate(ctx context.Context, opts ...ValidationOption)
}

// License is specified by OpenAPI/Swagger standard version 3.
// See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#licenseObject
// See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#license-object
type License struct {
ExtensionProps `json:"-" yaml:"-"`

Expand Down
2 changes: 1 addition & 1 deletion openapi3/link.go
Expand Up @@ -28,7 +28,7 @@ func (links Links) JSONLookup(token string) (interface{}, error) {
var _ jsonpointer.JSONPointable = (*Links)(nil)

// Link is specified by OpenAPI/Swagger standard version 3.
// See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#linkObject
// See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#link-object
type Link struct {
ExtensionProps `json:"-" yaml:"-"`

Expand Down
2 changes: 1 addition & 1 deletion openapi3/media_type.go
Expand Up @@ -12,7 +12,7 @@ import (
)

// MediaType is specified by OpenAPI/Swagger 3.0 standard.
// See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#mediaTypeObject
// See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#media-type-object
type MediaType struct {
ExtensionProps `json:"-" yaml:"-"`

Expand Down
2 changes: 1 addition & 1 deletion openapi3/openapi3.go
Expand Up @@ -9,7 +9,7 @@ import (
)

// T is the root of an OpenAPI v3 document
// See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#oasObject
// See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#openapi-object
type T struct {
ExtensionProps `json:"-" yaml:"-"`

Expand Down
2 changes: 1 addition & 1 deletion openapi3/path_item.go
Expand Up @@ -10,7 +10,7 @@ import (
)

// PathItem is specified by OpenAPI/Swagger standard version 3.
// See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#pathItemObject
// See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#path-item-object
type PathItem struct {
ExtensionProps `json:"-" yaml:"-"`

Expand Down
2 changes: 1 addition & 1 deletion openapi3/refs.go
Expand Up @@ -9,7 +9,7 @@ import (
)

// Ref is specified by OpenAPI/Swagger 3.0 standard.
// See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#referenceObject
// See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#reference-object
type Ref struct {
Ref string `json:"$ref" yaml:"$ref"`
}
Expand Down
2 changes: 1 addition & 1 deletion openapi3/request_body.go
Expand Up @@ -28,7 +28,7 @@ func (r RequestBodies) JSONLookup(token string) (interface{}, error) {
}

// RequestBody is specified by OpenAPI/Swagger 3.0 standard.
// See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#requestBodyObject
// See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#request-body-object
type RequestBody struct {
ExtensionProps `json:"-" yaml:"-"`

Expand Down
4 changes: 2 additions & 2 deletions openapi3/response.go
Expand Up @@ -13,7 +13,7 @@ import (
)

// Responses is specified by OpenAPI/Swagger 3.0 standard.
// See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#responsesObject
// See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#responses-object
type Responses map[string]*ResponseRef

var _ jsonpointer.JSONPointable = (*Responses)(nil)
Expand Down Expand Up @@ -68,7 +68,7 @@ func (responses Responses) JSONLookup(token string) (interface{}, error) {
}

// Response is specified by OpenAPI/Swagger 3.0 standard.
// See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#responseObject
// See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#response-object
type Response struct {
ExtensionProps `json:"-" yaml:"-"`

Expand Down
2 changes: 1 addition & 1 deletion openapi3/schema.go
Expand Up @@ -111,7 +111,7 @@ func (s SchemaRefs) JSONLookup(token string) (interface{}, error) {
}

// Schema is specified by OpenAPI/Swagger 3.0 standard.
// See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#schemaObject
// See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#schema-object
type Schema struct {
ExtensionProps `json:"-" yaml:"-"`

Expand Down
2 changes: 1 addition & 1 deletion openapi3/security_requirements.go
Expand Up @@ -28,7 +28,7 @@ func (srs SecurityRequirements) Validate(ctx context.Context, opts ...Validation
}

// SecurityRequirement is specified by OpenAPI/Swagger standard version 3.
// See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#securityRequirementObject
// See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#security-requirement-object
type SecurityRequirement map[string][]string

func NewSecurityRequirement() SecurityRequirement {
Expand Down
6 changes: 3 additions & 3 deletions openapi3/security_scheme.go
Expand Up @@ -29,7 +29,7 @@ func (s SecuritySchemes) JSONLookup(token string) (interface{}, error) {
var _ jsonpointer.JSONPointable = (*SecuritySchemes)(nil)

// SecurityScheme is specified by OpenAPI/Swagger standard version 3.
// See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#securitySchemeObject
// See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#security-scheme-object
type SecurityScheme struct {
ExtensionProps `json:"-" yaml:"-"`

Expand Down Expand Up @@ -177,7 +177,7 @@ func (ss *SecurityScheme) Validate(ctx context.Context, opts ...ValidationOption
}

// OAuthFlows is specified by OpenAPI/Swagger standard version 3.
// See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#oauthFlowsObject
// See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#oauth-flows-object
type OAuthFlows struct {
ExtensionProps `json:"-" yaml:"-"`

Expand Down Expand Up @@ -234,7 +234,7 @@ func (flows *OAuthFlows) Validate(ctx context.Context, opts ...ValidationOption)
}

// OAuthFlow is specified by OpenAPI/Swagger standard version 3.
// See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#oauthFlowObject
// See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#oauth-flow-object
type OAuthFlow struct {
ExtensionProps `json:"-" yaml:"-"`

Expand Down
2 changes: 1 addition & 1 deletion openapi3/security_scheme_test.go
Expand Up @@ -30,7 +30,7 @@ func TestSecuritySchemaExample(t *testing.T) {
}
}

// from https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#fixed-fields-23
// from https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md#fixed-fields-23
var securitySchemeExamples = []securitySchemeExample{
{
title: "Basic Authentication Sample",
Expand Down
2 changes: 1 addition & 1 deletion openapi3/server.go
Expand Up @@ -50,7 +50,7 @@ func (servers Servers) MatchURL(parsedURL *url.URL) (*Server, []string, string)
}

// Server is specified by OpenAPI/Swagger standard version 3.
// See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#serverObject
// See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#server-object
type Server struct {
ExtensionProps `json:"-" yaml:"-"`

Expand Down
2 changes: 1 addition & 1 deletion openapi3/tag.go
Expand Up @@ -32,7 +32,7 @@ func (tags Tags) Validate(ctx context.Context, opts ...ValidationOption) error {
}

// Tag is specified by OpenAPI/Swagger 3.0 standard.
// See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#tagObject
// See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#tag-object
type Tag struct {
ExtensionProps `json:"-" yaml:"-"`

Expand Down
2 changes: 1 addition & 1 deletion openapi3/xml.go
Expand Up @@ -7,7 +7,7 @@ import (
)

// XML is specified by OpenAPI/Swagger standard version 3.
// See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#xmlObject
// See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#xml-object
type XML struct {
ExtensionProps `json:"-" yaml:"-"`

Expand Down
2 changes: 1 addition & 1 deletion openapi3filter/issue625_test.go
Expand Up @@ -72,7 +72,7 @@ paths:
name: "failed allof object array",
spec: allOfArraySpec,
req: `/items?test=1.2,3.1`,
errStr: `parameter "test" in query has an error: Error at "/0": value "1.2" must be an integer`,
errStr: `parameter "test" in query has an error: path 0: value 1.2: an invalid integer: invalid syntax`,
},
{
name: "success oneof object array",
Expand Down
9 changes: 8 additions & 1 deletion openapi3filter/req_resp_decoder.go
Expand Up @@ -895,7 +895,14 @@ func parsePrimitive(raw string, schema *openapi3.SchemaRef) (interface{}, error)
}
switch schema.Value.Type {
case "integer":
v, err := strconv.ParseFloat(raw, 64)
if schema.Value.Format == "int32" {
v, err := strconv.ParseInt(raw, 0, 32)
if err != nil {
return nil, &ParseError{Kind: KindInvalidFormat, Value: raw, Reason: "an invalid " + schema.Value.Type, Cause: err.(*strconv.NumError).Err}
}
return int32(v), nil
}
v, err := strconv.ParseInt(raw, 0, 64)
if err != nil {
return nil, &ParseError{Kind: KindInvalidFormat, Value: raw, Reason: "an invalid " + schema.Value.Type, Cause: err.(*strconv.NumError).Err}
}
Expand Down
25 changes: 16 additions & 9 deletions openapi3filter/req_resp_decoder_test.go
Expand Up @@ -175,7 +175,7 @@ func TestDecodeParameter(t *testing.T) {
name: "integer",
param: &openapi3.Parameter{Name: "param", In: "path", Schema: integerSchema},
path: "/1",
want: float64(1),
want: int64(1),
found: true,
},
{
Expand Down Expand Up @@ -456,7 +456,7 @@ func TestDecodeParameter(t *testing.T) {
name: "integer",
param: &openapi3.Parameter{Name: "param", In: "query", Schema: integerSchema},
query: "param=1",
want: float64(1),
want: int64(1),
found: true,
},
{
Expand Down Expand Up @@ -522,7 +522,7 @@ func TestDecodeParameter(t *testing.T) {
name: "anyofSchema integer",
param: &openapi3.Parameter{Name: "param", In: "query", Schema: anyofSchema},
query: "param=1",
want: float64(1),
want: int64(1),
found: true,
},
{
Expand All @@ -548,7 +548,7 @@ func TestDecodeParameter(t *testing.T) {
name: "oneofSchema int",
param: &openapi3.Parameter{Name: "param", In: "query", Schema: oneofSchema},
query: "param=1122",
want: float64(1122),
want: int64(1122),
found: true,
},
{
Expand Down Expand Up @@ -724,7 +724,7 @@ func TestDecodeParameter(t *testing.T) {
name: "integer",
param: &openapi3.Parameter{Name: "X-Param", In: "header", Schema: integerSchema},
header: "X-Param:1",
want: float64(1),
want: int64(1),
found: true,
},
{
Expand Down Expand Up @@ -835,6 +835,13 @@ func TestDecodeParameter(t *testing.T) {
want: map[string]interface{}{"id": "foo", "name": "bar"},
found: true,
},
{
name: "valid integer prop",
param: &openapi3.Parameter{Name: "X-Param", In: "header", Schema: integerSchema},
header: "X-Param:88",
found: true,
want: int64(88),
},
{
name: "invalid integer prop",
param: &openapi3.Parameter{Name: "X-Param", In: "header", Schema: objectOf("foo", integerSchema)},
Expand Down Expand Up @@ -893,7 +900,7 @@ func TestDecodeParameter(t *testing.T) {
name: "integer",
param: &openapi3.Parameter{Name: "X-Param", In: "cookie", Schema: integerSchema},
cookie: "X-Param:1",
want: float64(1),
want: int64(1),
found: true,
},
{
Expand Down Expand Up @@ -1180,7 +1187,7 @@ func TestDecodeBody(t *testing.T) {
WithProperty("a", openapi3.NewStringSchema()).
WithProperty("b", openapi3.NewIntegerSchema()).
WithProperty("c", openapi3.NewArraySchema().WithItems(openapi3.NewStringSchema())),
want: map[string]interface{}{"a": "a1", "b": float64(10), "c": []interface{}{"c1", "c2"}},
want: map[string]interface{}{"a": "a1", "b": int64(10), "c": []interface{}{"c1", "c2"}},
},
{
name: "urlencoded space delimited",
Expand All @@ -1193,7 +1200,7 @@ func TestDecodeBody(t *testing.T) {
encoding: map[string]*openapi3.Encoding{
"c": {Style: openapi3.SerializationSpaceDelimited, Explode: boolPtr(false)},
},
want: map[string]interface{}{"a": "a1", "b": float64(10), "c": []interface{}{"c1", "c2"}},
want: map[string]interface{}{"a": "a1", "b": int64(10), "c": []interface{}{"c1", "c2"}},
},
{
name: "urlencoded pipe delimited",
Expand All @@ -1206,7 +1213,7 @@ func TestDecodeBody(t *testing.T) {
encoding: map[string]*openapi3.Encoding{
"c": {Style: openapi3.SerializationPipeDelimited, Explode: boolPtr(false)},
},
want: map[string]interface{}{"a": "a1", "b": float64(10), "c": []interface{}{"c1", "c2"}},
want: map[string]interface{}{"a": "a1", "b": int64(10), "c": []interface{}{"c1", "c2"}},
},
{
name: "multipart",
Expand Down

0 comments on commit db1cc91

Please sign in to comment.