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

Support parsing oneOf and x-stripeErrors #1301

Merged
merged 1 commit into from
Feb 11, 2025
Merged
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
9 changes: 9 additions & 0 deletions pkg/spec/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,19 @@ type StripeEvent struct {
EventType string `json:"type"`
}

type StripeError struct {
Code string `json:"code"`
HttpStatusCode int `json:"httpStatusCode"`
}

// This is a list of fields that either we handle properly or we're confident
// it's safe to ignore. If a field not in this list appears in the OpenAPI spec,
// then we'll get an error so we remember to update stripe-mock to support it.
var supportedSchemaFields = []string{
"$ref",
"additionalProperties",
"anyOf",
"oneOf",
"description",
"enum",
"format",
Expand All @@ -97,6 +103,7 @@ var supportedSchemaFields = []string{
"x-stripeMostCommon",
"x-stripeEvent",
"x-stripeNotPublic",
"x-stripeError",

// This is currently being used to store additional metadata for our SDKs. It's
// passed through our Spec and should be ignored
Expand All @@ -121,6 +128,7 @@ type Schema struct {
AdditionalProperties interface{} `json:"additionalProperties,omitempty"`

AnyOf []*Schema `json:"anyOf,omitempty"`
OneOf []*Schema `json:"oneOf,omitempty"`
Enum []interface{} `json:"enum,omitempty"`
Format string `json:"format,omitempty"`
Items *Schema `json:"items,omitempty"`
Expand All @@ -142,6 +150,7 @@ type Schema struct {
XStripeMostCommon []string `json:"x-stripeMostCommon,omitempty"`
XStripeEvent *StripeEvent `json:"x-stripeEvent,omitempty"`
XStripeNotPublic bool `json:"x-stripeNotPublic,omitempty"`
XStripeError *StripeError `json:"x-stripeError"`
}

func (s *Schema) String() string {
Expand Down
Loading