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: process discriminator mapping values as refs #1022

Merged
merged 2 commits into from
Oct 24, 2024
Merged
Changes from 1 commit
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
Next Next commit
openapi3: make StringMap generic over value
This allows us to support more use cases than just a string, allowing us to
attach more metadata onto these StringMap types that we cannot encode in just a
string.
jgresty committed Oct 24, 2024
commit 32eae066d85976acd6deb861759a4aa21f5252ce
4 changes: 2 additions & 2 deletions openapi3/discriminator.go
Original file line number Diff line number Diff line change
@@ -11,8 +11,8 @@ type Discriminator struct {
Extensions map[string]any `json:"-" yaml:"-"`
Origin *Origin `json:"origin,omitempty" yaml:"origin,omitempty"`

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

// MarshalJSON returns the JSON encoding of Discriminator.
8 changes: 4 additions & 4 deletions openapi3/security_scheme.go
Original file line number Diff line number Diff line change
@@ -322,10 +322,10 @@ type OAuthFlow struct {
Extensions map[string]any `json:"-" yaml:"-"`
Origin *Origin `json:"origin,omitempty" yaml:"origin,omitempty"`

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
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[string] `json:"scopes" yaml:"scopes"` // required
}

// MarshalJSON returns the JSON encoding of OAuthFlow.
6 changes: 3 additions & 3 deletions openapi3/stringmap.go
Original file line number Diff line number Diff line change
@@ -3,11 +3,11 @@ package openapi3
import "encoding/json"

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

// UnmarshalJSON sets StringMap to a copy of data.
func (stringMap *StringMap) UnmarshalJSON(data []byte) (err error) {
*stringMap, _, err = unmarshalStringMap[string](data)
func (stringMap *StringMap[V]) UnmarshalJSON(data []byte) (err error) {
*stringMap, _, err = unmarshalStringMap[V](data)
return
}