Skip to content

Commit

Permalink
openapi3: introduce StringMap type to enable unmarshalling of maps wi…
Browse files Browse the repository at this point in the history
…th Origin (#1018)
  • Loading branch information
reuvenharrison authored Oct 16, 2024
1 parent 75728b3 commit 56505dc
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 12 deletions.
16 changes: 10 additions & 6 deletions .github/docs/openapi3.txt
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,8 @@ func (content Content) Validate(ctx context.Context, opts ...ValidationOption) e
type Discriminator struct {
Extensions map[string]any `json:"-" yaml:"-"`

PropertyName string `json:"propertyName" yaml:"propertyName"` // required
Mapping map[string]string `json:"mapping,omitempty" yaml:"mapping,omitempty"`
PropertyName string `json:"propertyName" yaml:"propertyName"` // required
Mapping StringMap `json:"mapping,omitempty" yaml:"mapping,omitempty"`
}
Discriminator is specified by OpenAPI/Swagger standard version 3. See
https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#discriminator-object
Expand Down Expand Up @@ -873,10 +873,10 @@ type NumberFormatValidator = FormatValidator[float64]
type OAuthFlow struct {
Extensions map[string]any `json:"-" yaml:"-"`

AuthorizationURL string `json:"authorizationUrl,omitempty" yaml:"authorizationUrl,omitempty"`
TokenURL string `json:"tokenUrl,omitempty" yaml:"tokenUrl,omitempty"`
RefreshURL string `json:"refreshUrl,omitempty" yaml:"refreshUrl,omitempty"`
Scopes map[string]string `json:"scopes" yaml:"scopes"` // required
AuthorizationURL string `json:"authorizationUrl,omitempty" yaml:"authorizationUrl,omitempty"`
TokenURL string `json:"tokenUrl,omitempty" yaml:"tokenUrl,omitempty"`
RefreshURL string `json:"refreshUrl,omitempty" yaml:"refreshUrl,omitempty"`
Scopes StringMap `json:"scopes" yaml:"scopes"` // required
}
OAuthFlow is specified by OpenAPI/Swagger standard version 3. See
https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#oauth-flow-object
Expand Down Expand Up @@ -1983,6 +1983,10 @@ func NewRegexpFormatValidator(pattern string) StringFormatValidator
NewRegexpFormatValidator creates a new FormatValidator that uses a regular
expression to validate the value.

type StringMap map[string]string
StringMap is a map[string]string that ignores the origin in the underlying
json representation.

type T struct {
Extensions map[string]any `json:"-" yaml:"-"`

Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,9 @@ for _, path := range doc.Paths.InMatchingOrder() {

## CHANGELOG: Sub-v1 breaking API changes

### v0.129.0
* `openapi3.Discriminator.Mapping` and `openapi3.OAuthFlow.Scopes` fields went from a `map[string]string` to the new type `StringMap`

### v0.127.0
* Downgraded `github.com/gorilla/mux` dep from `1.8.1` to `1.8.0`.

Expand Down
4 changes: 2 additions & 2 deletions openapi3/discriminator.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
type Discriminator struct {
Extensions map[string]any `json:"-" yaml:"-"`

PropertyName string `json:"propertyName" yaml:"propertyName"` // required
Mapping map[string]string `json:"mapping,omitempty" yaml:"mapping,omitempty"`
PropertyName string `json:"propertyName" yaml:"propertyName"` // required
Mapping StringMap `json:"mapping,omitempty" yaml:"mapping,omitempty"`
}

// MarshalJSON returns the JSON encoding of Discriminator.
Expand Down
8 changes: 4 additions & 4 deletions openapi3/security_scheme.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,10 +317,10 @@ func (flows *OAuthFlows) Validate(ctx context.Context, opts ...ValidationOption)
type OAuthFlow struct {
Extensions map[string]any `json:"-" yaml:"-"`

AuthorizationURL string `json:"authorizationUrl,omitempty" yaml:"authorizationUrl,omitempty"`
TokenURL string `json:"tokenUrl,omitempty" yaml:"tokenUrl,omitempty"`
RefreshURL string `json:"refreshUrl,omitempty" yaml:"refreshUrl,omitempty"`
Scopes map[string]string `json:"scopes" yaml:"scopes"` // required
AuthorizationURL string `json:"authorizationUrl,omitempty" yaml:"authorizationUrl,omitempty"`
TokenURL string `json:"tokenUrl,omitempty" yaml:"tokenUrl,omitempty"`
RefreshURL string `json:"refreshUrl,omitempty" yaml:"refreshUrl,omitempty"`
Scopes StringMap `json:"scopes" yaml:"scopes"` // required
}

// MarshalJSON returns the JSON encoding of OAuthFlow.
Expand Down
4 changes: 4 additions & 0 deletions openapi3/stringmap.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package openapi3

// StringMap is a map[string]string that ignores the origin in the underlying json representation.
type StringMap map[string]string

0 comments on commit 56505dc

Please sign in to comment.