Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

openapi3: introduce StringMap type to enable unmarshalling of maps with Origin #1018

Merged
merged 3 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
5 changes: 5 additions & 0 deletions openapi3/issue495_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package openapi3

import (
"os"
"testing"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -113,6 +114,10 @@ paths:
sl := NewLoader()
sl.IsExternalRefsAllowed = true

if os.Getenv("CI") == "true" {
t.Skip("Running in CI: skipping so we avoid 403 error from remote schema server")
}

doc, err := sl.LoadFromData(spec)
require.NoError(t, err)

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
Loading