diff --git a/.schema/openapi/gen.go.yml b/.schema/openapi/gen.go.yml index 48cee4db3b58..0ca7bcda46b9 100644 --- a/.schema/openapi/gen.go.yml +++ b/.schema/openapi/gen.go.yml @@ -4,3 +4,4 @@ generateInterfaces: true isGoSubmodule: false structPrefix: true enumClassPrefix: true +useOneOfDiscriminatorLookup: true diff --git a/internal/client-go/model_continue_with.go b/internal/client-go/model_continue_with.go index ee84e74692fb..9e97dbf479e7 100644 --- a/internal/client-go/model_continue_with.go +++ b/internal/client-go/model_continue_with.go @@ -55,72 +55,110 @@ func ContinueWithVerificationUiAsContinueWith(v *ContinueWithVerificationUi) Con // Unmarshal JSON data into one of the pointers in the struct func (dst *ContinueWith) UnmarshalJSON(data []byte) error { var err error - match := 0 - // try to unmarshal data into ContinueWithRecoveryUi - err = newStrictDecoder(data).Decode(&dst.ContinueWithRecoveryUi) - if err == nil { - jsonContinueWithRecoveryUi, _ := json.Marshal(dst.ContinueWithRecoveryUi) - if string(jsonContinueWithRecoveryUi) == "{}" { // empty struct - dst.ContinueWithRecoveryUi = nil + // use discriminator value to speed up the lookup + var jsonDict map[string]interface{} + err = newStrictDecoder(data).Decode(&jsonDict) + if err != nil { + return fmt.Errorf("Failed to unmarshal JSON into map for the discrimintor lookup.") + } + + // check if the discriminator value is 'set_ory_session_token' + if jsonDict["action"] == "set_ory_session_token" { + // try to unmarshal JSON data into ContinueWithSetOrySessionToken + err = json.Unmarshal(data, &dst.ContinueWithSetOrySessionToken) + if err == nil { + return nil // data stored in dst.ContinueWithSetOrySessionToken, return on the first match } else { - match++ + dst.ContinueWithSetOrySessionToken = nil + return fmt.Errorf("Failed to unmarshal ContinueWith as ContinueWithSetOrySessionToken: %s", err.Error()) } - } else { - dst.ContinueWithRecoveryUi = nil } - // try to unmarshal data into ContinueWithSetOrySessionToken - err = newStrictDecoder(data).Decode(&dst.ContinueWithSetOrySessionToken) - if err == nil { - jsonContinueWithSetOrySessionToken, _ := json.Marshal(dst.ContinueWithSetOrySessionToken) - if string(jsonContinueWithSetOrySessionToken) == "{}" { // empty struct - dst.ContinueWithSetOrySessionToken = nil + // check if the discriminator value is 'show_recovery_ui' + if jsonDict["action"] == "show_recovery_ui" { + // try to unmarshal JSON data into ContinueWithRecoveryUi + err = json.Unmarshal(data, &dst.ContinueWithRecoveryUi) + if err == nil { + return nil // data stored in dst.ContinueWithRecoveryUi, return on the first match } else { - match++ + dst.ContinueWithRecoveryUi = nil + return fmt.Errorf("Failed to unmarshal ContinueWith as ContinueWithRecoveryUi: %s", err.Error()) } - } else { - dst.ContinueWithSetOrySessionToken = nil } - // try to unmarshal data into ContinueWithSettingsUi - err = newStrictDecoder(data).Decode(&dst.ContinueWithSettingsUi) - if err == nil { - jsonContinueWithSettingsUi, _ := json.Marshal(dst.ContinueWithSettingsUi) - if string(jsonContinueWithSettingsUi) == "{}" { // empty struct - dst.ContinueWithSettingsUi = nil + // check if the discriminator value is 'show_settings_ui' + if jsonDict["action"] == "show_settings_ui" { + // try to unmarshal JSON data into ContinueWithSettingsUi + err = json.Unmarshal(data, &dst.ContinueWithSettingsUi) + if err == nil { + return nil // data stored in dst.ContinueWithSettingsUi, return on the first match } else { - match++ + dst.ContinueWithSettingsUi = nil + return fmt.Errorf("Failed to unmarshal ContinueWith as ContinueWithSettingsUi: %s", err.Error()) } - } else { - dst.ContinueWithSettingsUi = nil } - // try to unmarshal data into ContinueWithVerificationUi - err = newStrictDecoder(data).Decode(&dst.ContinueWithVerificationUi) - if err == nil { - jsonContinueWithVerificationUi, _ := json.Marshal(dst.ContinueWithVerificationUi) - if string(jsonContinueWithVerificationUi) == "{}" { // empty struct + // check if the discriminator value is 'show_verification_ui' + if jsonDict["action"] == "show_verification_ui" { + // try to unmarshal JSON data into ContinueWithVerificationUi + err = json.Unmarshal(data, &dst.ContinueWithVerificationUi) + if err == nil { + return nil // data stored in dst.ContinueWithVerificationUi, return on the first match + } else { dst.ContinueWithVerificationUi = nil + return fmt.Errorf("Failed to unmarshal ContinueWith as ContinueWithVerificationUi: %s", err.Error()) + } + } + + // check if the discriminator value is 'continueWithRecoveryUi' + if jsonDict["action"] == "continueWithRecoveryUi" { + // try to unmarshal JSON data into ContinueWithRecoveryUi + err = json.Unmarshal(data, &dst.ContinueWithRecoveryUi) + if err == nil { + return nil // data stored in dst.ContinueWithRecoveryUi, return on the first match } else { - match++ + dst.ContinueWithRecoveryUi = nil + return fmt.Errorf("Failed to unmarshal ContinueWith as ContinueWithRecoveryUi: %s", err.Error()) } - } else { - dst.ContinueWithVerificationUi = nil } - if match > 1 { // more than 1 match - // reset to nil - dst.ContinueWithRecoveryUi = nil - dst.ContinueWithSetOrySessionToken = nil - dst.ContinueWithSettingsUi = nil - dst.ContinueWithVerificationUi = nil + // check if the discriminator value is 'continueWithSetOrySessionToken' + if jsonDict["action"] == "continueWithSetOrySessionToken" { + // try to unmarshal JSON data into ContinueWithSetOrySessionToken + err = json.Unmarshal(data, &dst.ContinueWithSetOrySessionToken) + if err == nil { + return nil // data stored in dst.ContinueWithSetOrySessionToken, return on the first match + } else { + dst.ContinueWithSetOrySessionToken = nil + return fmt.Errorf("Failed to unmarshal ContinueWith as ContinueWithSetOrySessionToken: %s", err.Error()) + } + } + + // check if the discriminator value is 'continueWithSettingsUi' + if jsonDict["action"] == "continueWithSettingsUi" { + // try to unmarshal JSON data into ContinueWithSettingsUi + err = json.Unmarshal(data, &dst.ContinueWithSettingsUi) + if err == nil { + return nil // data stored in dst.ContinueWithSettingsUi, return on the first match + } else { + dst.ContinueWithSettingsUi = nil + return fmt.Errorf("Failed to unmarshal ContinueWith as ContinueWithSettingsUi: %s", err.Error()) + } + } - return fmt.Errorf("Data matches more than one schema in oneOf(ContinueWith)") - } else if match == 1 { - return nil // exactly one match - } else { // no match - return fmt.Errorf("Data failed to match schemas in oneOf(ContinueWith)") + // check if the discriminator value is 'continueWithVerificationUi' + if jsonDict["action"] == "continueWithVerificationUi" { + // try to unmarshal JSON data into ContinueWithVerificationUi + err = json.Unmarshal(data, &dst.ContinueWithVerificationUi) + if err == nil { + return nil // data stored in dst.ContinueWithVerificationUi, return on the first match + } else { + dst.ContinueWithVerificationUi = nil + return fmt.Errorf("Failed to unmarshal ContinueWith as ContinueWithVerificationUi: %s", err.Error()) + } } + + return nil } // Marshal data from the first non-nil pointers in the struct to JSON diff --git a/internal/client-go/model_ui_node_anchor_attributes.go b/internal/client-go/model_ui_node_anchor_attributes.go index 15cb492fe8eb..ad2cc992a119 100644 --- a/internal/client-go/model_ui_node_anchor_attributes.go +++ b/internal/client-go/model_ui_node_anchor_attributes.go @@ -21,7 +21,7 @@ type UiNodeAnchorAttributes struct { Href string `json:"href"` // A unique identifier Id string `json:"id"` - // NodeType represents this node's types. It is a mirror of `node.type` and is primarily used to allow compatibility with OpenAPI 3.0. In this struct it technically always is \"a\". + // NodeType represents this node's types. It is a mirror of `node.type` and is primarily used to allow compatibility with OpenAPI 3.0. In this struct it technically always is \"a\". text Text input Input img Image a Anchor script Script NodeType string `json:"node_type"` Title UiText `json:"title"` } diff --git a/internal/client-go/model_ui_node_attributes.go b/internal/client-go/model_ui_node_attributes.go index 347be6f44a72..510dc20f8564 100644 --- a/internal/client-go/model_ui_node_attributes.go +++ b/internal/client-go/model_ui_node_attributes.go @@ -63,86 +63,134 @@ func UiNodeTextAttributesAsUiNodeAttributes(v *UiNodeTextAttributes) UiNodeAttri // Unmarshal JSON data into one of the pointers in the struct func (dst *UiNodeAttributes) UnmarshalJSON(data []byte) error { var err error - match := 0 - // try to unmarshal data into UiNodeAnchorAttributes - err = newStrictDecoder(data).Decode(&dst.UiNodeAnchorAttributes) - if err == nil { - jsonUiNodeAnchorAttributes, _ := json.Marshal(dst.UiNodeAnchorAttributes) - if string(jsonUiNodeAnchorAttributes) == "{}" { // empty struct - dst.UiNodeAnchorAttributes = nil + // use discriminator value to speed up the lookup + var jsonDict map[string]interface{} + err = newStrictDecoder(data).Decode(&jsonDict) + if err != nil { + return fmt.Errorf("Failed to unmarshal JSON into map for the discrimintor lookup.") + } + + // check if the discriminator value is 'a' + if jsonDict["node_type"] == "a" { + // try to unmarshal JSON data into UiNodeAnchorAttributes + err = json.Unmarshal(data, &dst.UiNodeAnchorAttributes) + if err == nil { + return nil // data stored in dst.UiNodeAnchorAttributes, return on the first match } else { - match++ + dst.UiNodeAnchorAttributes = nil + return fmt.Errorf("Failed to unmarshal UiNodeAttributes as UiNodeAnchorAttributes: %s", err.Error()) } - } else { - dst.UiNodeAnchorAttributes = nil } - // try to unmarshal data into UiNodeImageAttributes - err = newStrictDecoder(data).Decode(&dst.UiNodeImageAttributes) - if err == nil { - jsonUiNodeImageAttributes, _ := json.Marshal(dst.UiNodeImageAttributes) - if string(jsonUiNodeImageAttributes) == "{}" { // empty struct - dst.UiNodeImageAttributes = nil + // check if the discriminator value is 'img' + if jsonDict["node_type"] == "img" { + // try to unmarshal JSON data into UiNodeImageAttributes + err = json.Unmarshal(data, &dst.UiNodeImageAttributes) + if err == nil { + return nil // data stored in dst.UiNodeImageAttributes, return on the first match } else { - match++ + dst.UiNodeImageAttributes = nil + return fmt.Errorf("Failed to unmarshal UiNodeAttributes as UiNodeImageAttributes: %s", err.Error()) } - } else { - dst.UiNodeImageAttributes = nil } - // try to unmarshal data into UiNodeInputAttributes - err = newStrictDecoder(data).Decode(&dst.UiNodeInputAttributes) - if err == nil { - jsonUiNodeInputAttributes, _ := json.Marshal(dst.UiNodeInputAttributes) - if string(jsonUiNodeInputAttributes) == "{}" { // empty struct - dst.UiNodeInputAttributes = nil + // check if the discriminator value is 'input' + if jsonDict["node_type"] == "input" { + // try to unmarshal JSON data into UiNodeInputAttributes + err = json.Unmarshal(data, &dst.UiNodeInputAttributes) + if err == nil { + return nil // data stored in dst.UiNodeInputAttributes, return on the first match } else { - match++ + dst.UiNodeInputAttributes = nil + return fmt.Errorf("Failed to unmarshal UiNodeAttributes as UiNodeInputAttributes: %s", err.Error()) } - } else { - dst.UiNodeInputAttributes = nil } - // try to unmarshal data into UiNodeScriptAttributes - err = newStrictDecoder(data).Decode(&dst.UiNodeScriptAttributes) - if err == nil { - jsonUiNodeScriptAttributes, _ := json.Marshal(dst.UiNodeScriptAttributes) - if string(jsonUiNodeScriptAttributes) == "{}" { // empty struct - dst.UiNodeScriptAttributes = nil + // check if the discriminator value is 'script' + if jsonDict["node_type"] == "script" { + // try to unmarshal JSON data into UiNodeScriptAttributes + err = json.Unmarshal(data, &dst.UiNodeScriptAttributes) + if err == nil { + return nil // data stored in dst.UiNodeScriptAttributes, return on the first match } else { - match++ + dst.UiNodeScriptAttributes = nil + return fmt.Errorf("Failed to unmarshal UiNodeAttributes as UiNodeScriptAttributes: %s", err.Error()) } - } else { - dst.UiNodeScriptAttributes = nil } - // try to unmarshal data into UiNodeTextAttributes - err = newStrictDecoder(data).Decode(&dst.UiNodeTextAttributes) - if err == nil { - jsonUiNodeTextAttributes, _ := json.Marshal(dst.UiNodeTextAttributes) - if string(jsonUiNodeTextAttributes) == "{}" { // empty struct + // check if the discriminator value is 'text' + if jsonDict["node_type"] == "text" { + // try to unmarshal JSON data into UiNodeTextAttributes + err = json.Unmarshal(data, &dst.UiNodeTextAttributes) + if err == nil { + return nil // data stored in dst.UiNodeTextAttributes, return on the first match + } else { dst.UiNodeTextAttributes = nil + return fmt.Errorf("Failed to unmarshal UiNodeAttributes as UiNodeTextAttributes: %s", err.Error()) + } + } + + // check if the discriminator value is 'uiNodeAnchorAttributes' + if jsonDict["node_type"] == "uiNodeAnchorAttributes" { + // try to unmarshal JSON data into UiNodeAnchorAttributes + err = json.Unmarshal(data, &dst.UiNodeAnchorAttributes) + if err == nil { + return nil // data stored in dst.UiNodeAnchorAttributes, return on the first match + } else { + dst.UiNodeAnchorAttributes = nil + return fmt.Errorf("Failed to unmarshal UiNodeAttributes as UiNodeAnchorAttributes: %s", err.Error()) + } + } + + // check if the discriminator value is 'uiNodeImageAttributes' + if jsonDict["node_type"] == "uiNodeImageAttributes" { + // try to unmarshal JSON data into UiNodeImageAttributes + err = json.Unmarshal(data, &dst.UiNodeImageAttributes) + if err == nil { + return nil // data stored in dst.UiNodeImageAttributes, return on the first match } else { - match++ + dst.UiNodeImageAttributes = nil + return fmt.Errorf("Failed to unmarshal UiNodeAttributes as UiNodeImageAttributes: %s", err.Error()) } - } else { - dst.UiNodeTextAttributes = nil } - if match > 1 { // more than 1 match - // reset to nil - dst.UiNodeAnchorAttributes = nil - dst.UiNodeImageAttributes = nil - dst.UiNodeInputAttributes = nil - dst.UiNodeScriptAttributes = nil - dst.UiNodeTextAttributes = nil + // check if the discriminator value is 'uiNodeInputAttributes' + if jsonDict["node_type"] == "uiNodeInputAttributes" { + // try to unmarshal JSON data into UiNodeInputAttributes + err = json.Unmarshal(data, &dst.UiNodeInputAttributes) + if err == nil { + return nil // data stored in dst.UiNodeInputAttributes, return on the first match + } else { + dst.UiNodeInputAttributes = nil + return fmt.Errorf("Failed to unmarshal UiNodeAttributes as UiNodeInputAttributes: %s", err.Error()) + } + } - return fmt.Errorf("Data matches more than one schema in oneOf(UiNodeAttributes)") - } else if match == 1 { - return nil // exactly one match - } else { // no match - return fmt.Errorf("Data failed to match schemas in oneOf(UiNodeAttributes)") + // check if the discriminator value is 'uiNodeScriptAttributes' + if jsonDict["node_type"] == "uiNodeScriptAttributes" { + // try to unmarshal JSON data into UiNodeScriptAttributes + err = json.Unmarshal(data, &dst.UiNodeScriptAttributes) + if err == nil { + return nil // data stored in dst.UiNodeScriptAttributes, return on the first match + } else { + dst.UiNodeScriptAttributes = nil + return fmt.Errorf("Failed to unmarshal UiNodeAttributes as UiNodeScriptAttributes: %s", err.Error()) + } + } + + // check if the discriminator value is 'uiNodeTextAttributes' + if jsonDict["node_type"] == "uiNodeTextAttributes" { + // try to unmarshal JSON data into UiNodeTextAttributes + err = json.Unmarshal(data, &dst.UiNodeTextAttributes) + if err == nil { + return nil // data stored in dst.UiNodeTextAttributes, return on the first match + } else { + dst.UiNodeTextAttributes = nil + return fmt.Errorf("Failed to unmarshal UiNodeAttributes as UiNodeTextAttributes: %s", err.Error()) + } } + + return nil } // Marshal data from the first non-nil pointers in the struct to JSON diff --git a/internal/client-go/model_ui_node_image_attributes.go b/internal/client-go/model_ui_node_image_attributes.go index 5b300b9548bd..6eef160e3d67 100644 --- a/internal/client-go/model_ui_node_image_attributes.go +++ b/internal/client-go/model_ui_node_image_attributes.go @@ -21,7 +21,7 @@ type UiNodeImageAttributes struct { Height int64 `json:"height"` // A unique identifier Id string `json:"id"` - // NodeType represents this node's types. It is a mirror of `node.type` and is primarily used to allow compatibility with OpenAPI 3.0. In this struct it technically always is \"img\". + // NodeType represents this node's types. It is a mirror of `node.type` and is primarily used to allow compatibility with OpenAPI 3.0. In this struct it technically always is \"img\". text Text input Input img Image a Anchor script Script NodeType string `json:"node_type"` // The image's source URL. format: uri Src string `json:"src"` diff --git a/internal/client-go/model_ui_node_input_attributes.go b/internal/client-go/model_ui_node_input_attributes.go index fbf7e0f1b04e..b373dda7ccfd 100644 --- a/internal/client-go/model_ui_node_input_attributes.go +++ b/internal/client-go/model_ui_node_input_attributes.go @@ -24,7 +24,7 @@ type UiNodeInputAttributes struct { Label *UiText `json:"label,omitempty"` // The input's element name. Name string `json:"name"` - // NodeType represents this node's types. It is a mirror of `node.type` and is primarily used to allow compatibility with OpenAPI 3.0. In this struct it technically always is \"input\". + // NodeType represents this node's types. It is a mirror of `node.type` and is primarily used to allow compatibility with OpenAPI 3.0. In this struct it technically always is \"input\". text Text input Input img Image a Anchor script Script NodeType string `json:"node_type"` // OnClick may contain javascript which should be executed on click. This is primarily used for WebAuthn. Onclick *string `json:"onclick,omitempty"` diff --git a/internal/client-go/model_ui_node_script_attributes.go b/internal/client-go/model_ui_node_script_attributes.go index 21dca70cbe86..d867c1c66dba 100644 --- a/internal/client-go/model_ui_node_script_attributes.go +++ b/internal/client-go/model_ui_node_script_attributes.go @@ -25,7 +25,7 @@ type UiNodeScriptAttributes struct { Id string `json:"id"` // The script's integrity hash Integrity string `json:"integrity"` - // NodeType represents this node's types. It is a mirror of `node.type` and is primarily used to allow compatibility with OpenAPI 3.0. In this struct it technically always is \"script\". + // NodeType represents this node's types. It is a mirror of `node.type` and is primarily used to allow compatibility with OpenAPI 3.0. In this struct it technically always is \"script\". text Text input Input img Image a Anchor script Script NodeType string `json:"node_type"` // Nonce for CSP A nonce you may want to use to improve your Content Security Policy. You do not have to use this value but if you want to improve your CSP policies you may use it. You can also choose to use your own nonce value! Nonce string `json:"nonce"` diff --git a/internal/client-go/model_ui_node_text_attributes.go b/internal/client-go/model_ui_node_text_attributes.go index 6199187b5d75..93e0f8314191 100644 --- a/internal/client-go/model_ui_node_text_attributes.go +++ b/internal/client-go/model_ui_node_text_attributes.go @@ -19,7 +19,7 @@ import ( type UiNodeTextAttributes struct { // A unique identifier Id string `json:"id"` - // NodeType represents this node's types. It is a mirror of `node.type` and is primarily used to allow compatibility with OpenAPI 3.0. In this struct it technically always is \"text\". + // NodeType represents this node's types. It is a mirror of `node.type` and is primarily used to allow compatibility with OpenAPI 3.0. In this struct it technically always is \"text\". text Text input Input img Image a Anchor script Script NodeType string `json:"node_type"` Text UiText `json:"text"` } diff --git a/internal/client-go/model_update_login_flow_body.go b/internal/client-go/model_update_login_flow_body.go index 36033328e78d..ac3e4f503292 100644 --- a/internal/client-go/model_update_login_flow_body.go +++ b/internal/client-go/model_update_login_flow_body.go @@ -71,100 +71,158 @@ func UpdateLoginFlowWithWebAuthnMethodAsUpdateLoginFlowBody(v *UpdateLoginFlowWi // Unmarshal JSON data into one of the pointers in the struct func (dst *UpdateLoginFlowBody) UnmarshalJSON(data []byte) error { var err error - match := 0 - // try to unmarshal data into UpdateLoginFlowWithCodeMethod - err = newStrictDecoder(data).Decode(&dst.UpdateLoginFlowWithCodeMethod) - if err == nil { - jsonUpdateLoginFlowWithCodeMethod, _ := json.Marshal(dst.UpdateLoginFlowWithCodeMethod) - if string(jsonUpdateLoginFlowWithCodeMethod) == "{}" { // empty struct - dst.UpdateLoginFlowWithCodeMethod = nil + // use discriminator value to speed up the lookup + var jsonDict map[string]interface{} + err = newStrictDecoder(data).Decode(&jsonDict) + if err != nil { + return fmt.Errorf("Failed to unmarshal JSON into map for the discrimintor lookup.") + } + + // check if the discriminator value is 'code' + if jsonDict["method"] == "code" { + // try to unmarshal JSON data into UpdateLoginFlowWithCodeMethod + err = json.Unmarshal(data, &dst.UpdateLoginFlowWithCodeMethod) + if err == nil { + return nil // data stored in dst.UpdateLoginFlowWithCodeMethod, return on the first match } else { - match++ + dst.UpdateLoginFlowWithCodeMethod = nil + return fmt.Errorf("Failed to unmarshal UpdateLoginFlowBody as UpdateLoginFlowWithCodeMethod: %s", err.Error()) } - } else { - dst.UpdateLoginFlowWithCodeMethod = nil } - // try to unmarshal data into UpdateLoginFlowWithLookupSecretMethod - err = newStrictDecoder(data).Decode(&dst.UpdateLoginFlowWithLookupSecretMethod) - if err == nil { - jsonUpdateLoginFlowWithLookupSecretMethod, _ := json.Marshal(dst.UpdateLoginFlowWithLookupSecretMethod) - if string(jsonUpdateLoginFlowWithLookupSecretMethod) == "{}" { // empty struct - dst.UpdateLoginFlowWithLookupSecretMethod = nil + // check if the discriminator value is 'lookup_secret' + if jsonDict["method"] == "lookup_secret" { + // try to unmarshal JSON data into UpdateLoginFlowWithLookupSecretMethod + err = json.Unmarshal(data, &dst.UpdateLoginFlowWithLookupSecretMethod) + if err == nil { + return nil // data stored in dst.UpdateLoginFlowWithLookupSecretMethod, return on the first match } else { - match++ + dst.UpdateLoginFlowWithLookupSecretMethod = nil + return fmt.Errorf("Failed to unmarshal UpdateLoginFlowBody as UpdateLoginFlowWithLookupSecretMethod: %s", err.Error()) } - } else { - dst.UpdateLoginFlowWithLookupSecretMethod = nil } - // try to unmarshal data into UpdateLoginFlowWithOidcMethod - err = newStrictDecoder(data).Decode(&dst.UpdateLoginFlowWithOidcMethod) - if err == nil { - jsonUpdateLoginFlowWithOidcMethod, _ := json.Marshal(dst.UpdateLoginFlowWithOidcMethod) - if string(jsonUpdateLoginFlowWithOidcMethod) == "{}" { // empty struct - dst.UpdateLoginFlowWithOidcMethod = nil + // check if the discriminator value is 'oidc' + if jsonDict["method"] == "oidc" { + // try to unmarshal JSON data into UpdateLoginFlowWithOidcMethod + err = json.Unmarshal(data, &dst.UpdateLoginFlowWithOidcMethod) + if err == nil { + return nil // data stored in dst.UpdateLoginFlowWithOidcMethod, return on the first match } else { - match++ + dst.UpdateLoginFlowWithOidcMethod = nil + return fmt.Errorf("Failed to unmarshal UpdateLoginFlowBody as UpdateLoginFlowWithOidcMethod: %s", err.Error()) } - } else { - dst.UpdateLoginFlowWithOidcMethod = nil } - // try to unmarshal data into UpdateLoginFlowWithPasswordMethod - err = newStrictDecoder(data).Decode(&dst.UpdateLoginFlowWithPasswordMethod) - if err == nil { - jsonUpdateLoginFlowWithPasswordMethod, _ := json.Marshal(dst.UpdateLoginFlowWithPasswordMethod) - if string(jsonUpdateLoginFlowWithPasswordMethod) == "{}" { // empty struct - dst.UpdateLoginFlowWithPasswordMethod = nil + // check if the discriminator value is 'password' + if jsonDict["method"] == "password" { + // try to unmarshal JSON data into UpdateLoginFlowWithPasswordMethod + err = json.Unmarshal(data, &dst.UpdateLoginFlowWithPasswordMethod) + if err == nil { + return nil // data stored in dst.UpdateLoginFlowWithPasswordMethod, return on the first match } else { - match++ + dst.UpdateLoginFlowWithPasswordMethod = nil + return fmt.Errorf("Failed to unmarshal UpdateLoginFlowBody as UpdateLoginFlowWithPasswordMethod: %s", err.Error()) } - } else { - dst.UpdateLoginFlowWithPasswordMethod = nil } - // try to unmarshal data into UpdateLoginFlowWithTotpMethod - err = newStrictDecoder(data).Decode(&dst.UpdateLoginFlowWithTotpMethod) - if err == nil { - jsonUpdateLoginFlowWithTotpMethod, _ := json.Marshal(dst.UpdateLoginFlowWithTotpMethod) - if string(jsonUpdateLoginFlowWithTotpMethod) == "{}" { // empty struct - dst.UpdateLoginFlowWithTotpMethod = nil + // check if the discriminator value is 'totp' + if jsonDict["method"] == "totp" { + // try to unmarshal JSON data into UpdateLoginFlowWithTotpMethod + err = json.Unmarshal(data, &dst.UpdateLoginFlowWithTotpMethod) + if err == nil { + return nil // data stored in dst.UpdateLoginFlowWithTotpMethod, return on the first match } else { - match++ + dst.UpdateLoginFlowWithTotpMethod = nil + return fmt.Errorf("Failed to unmarshal UpdateLoginFlowBody as UpdateLoginFlowWithTotpMethod: %s", err.Error()) } - } else { - dst.UpdateLoginFlowWithTotpMethod = nil } - // try to unmarshal data into UpdateLoginFlowWithWebAuthnMethod - err = newStrictDecoder(data).Decode(&dst.UpdateLoginFlowWithWebAuthnMethod) - if err == nil { - jsonUpdateLoginFlowWithWebAuthnMethod, _ := json.Marshal(dst.UpdateLoginFlowWithWebAuthnMethod) - if string(jsonUpdateLoginFlowWithWebAuthnMethod) == "{}" { // empty struct + // check if the discriminator value is 'webauthn' + if jsonDict["method"] == "webauthn" { + // try to unmarshal JSON data into UpdateLoginFlowWithWebAuthnMethod + err = json.Unmarshal(data, &dst.UpdateLoginFlowWithWebAuthnMethod) + if err == nil { + return nil // data stored in dst.UpdateLoginFlowWithWebAuthnMethod, return on the first match + } else { dst.UpdateLoginFlowWithWebAuthnMethod = nil + return fmt.Errorf("Failed to unmarshal UpdateLoginFlowBody as UpdateLoginFlowWithWebAuthnMethod: %s", err.Error()) + } + } + + // check if the discriminator value is 'updateLoginFlowWithCodeMethod' + if jsonDict["method"] == "updateLoginFlowWithCodeMethod" { + // try to unmarshal JSON data into UpdateLoginFlowWithCodeMethod + err = json.Unmarshal(data, &dst.UpdateLoginFlowWithCodeMethod) + if err == nil { + return nil // data stored in dst.UpdateLoginFlowWithCodeMethod, return on the first match } else { - match++ + dst.UpdateLoginFlowWithCodeMethod = nil + return fmt.Errorf("Failed to unmarshal UpdateLoginFlowBody as UpdateLoginFlowWithCodeMethod: %s", err.Error()) } - } else { - dst.UpdateLoginFlowWithWebAuthnMethod = nil } - if match > 1 { // more than 1 match - // reset to nil - dst.UpdateLoginFlowWithCodeMethod = nil - dst.UpdateLoginFlowWithLookupSecretMethod = nil - dst.UpdateLoginFlowWithOidcMethod = nil - dst.UpdateLoginFlowWithPasswordMethod = nil - dst.UpdateLoginFlowWithTotpMethod = nil - dst.UpdateLoginFlowWithWebAuthnMethod = nil + // check if the discriminator value is 'updateLoginFlowWithLookupSecretMethod' + if jsonDict["method"] == "updateLoginFlowWithLookupSecretMethod" { + // try to unmarshal JSON data into UpdateLoginFlowWithLookupSecretMethod + err = json.Unmarshal(data, &dst.UpdateLoginFlowWithLookupSecretMethod) + if err == nil { + return nil // data stored in dst.UpdateLoginFlowWithLookupSecretMethod, return on the first match + } else { + dst.UpdateLoginFlowWithLookupSecretMethod = nil + return fmt.Errorf("Failed to unmarshal UpdateLoginFlowBody as UpdateLoginFlowWithLookupSecretMethod: %s", err.Error()) + } + } - return fmt.Errorf("Data matches more than one schema in oneOf(UpdateLoginFlowBody)") - } else if match == 1 { - return nil // exactly one match - } else { // no match - return fmt.Errorf("Data failed to match schemas in oneOf(UpdateLoginFlowBody)") + // check if the discriminator value is 'updateLoginFlowWithOidcMethod' + if jsonDict["method"] == "updateLoginFlowWithOidcMethod" { + // try to unmarshal JSON data into UpdateLoginFlowWithOidcMethod + err = json.Unmarshal(data, &dst.UpdateLoginFlowWithOidcMethod) + if err == nil { + return nil // data stored in dst.UpdateLoginFlowWithOidcMethod, return on the first match + } else { + dst.UpdateLoginFlowWithOidcMethod = nil + return fmt.Errorf("Failed to unmarshal UpdateLoginFlowBody as UpdateLoginFlowWithOidcMethod: %s", err.Error()) + } + } + + // check if the discriminator value is 'updateLoginFlowWithPasswordMethod' + if jsonDict["method"] == "updateLoginFlowWithPasswordMethod" { + // try to unmarshal JSON data into UpdateLoginFlowWithPasswordMethod + err = json.Unmarshal(data, &dst.UpdateLoginFlowWithPasswordMethod) + if err == nil { + return nil // data stored in dst.UpdateLoginFlowWithPasswordMethod, return on the first match + } else { + dst.UpdateLoginFlowWithPasswordMethod = nil + return fmt.Errorf("Failed to unmarshal UpdateLoginFlowBody as UpdateLoginFlowWithPasswordMethod: %s", err.Error()) + } + } + + // check if the discriminator value is 'updateLoginFlowWithTotpMethod' + if jsonDict["method"] == "updateLoginFlowWithTotpMethod" { + // try to unmarshal JSON data into UpdateLoginFlowWithTotpMethod + err = json.Unmarshal(data, &dst.UpdateLoginFlowWithTotpMethod) + if err == nil { + return nil // data stored in dst.UpdateLoginFlowWithTotpMethod, return on the first match + } else { + dst.UpdateLoginFlowWithTotpMethod = nil + return fmt.Errorf("Failed to unmarshal UpdateLoginFlowBody as UpdateLoginFlowWithTotpMethod: %s", err.Error()) + } + } + + // check if the discriminator value is 'updateLoginFlowWithWebAuthnMethod' + if jsonDict["method"] == "updateLoginFlowWithWebAuthnMethod" { + // try to unmarshal JSON data into UpdateLoginFlowWithWebAuthnMethod + err = json.Unmarshal(data, &dst.UpdateLoginFlowWithWebAuthnMethod) + if err == nil { + return nil // data stored in dst.UpdateLoginFlowWithWebAuthnMethod, return on the first match + } else { + dst.UpdateLoginFlowWithWebAuthnMethod = nil + return fmt.Errorf("Failed to unmarshal UpdateLoginFlowBody as UpdateLoginFlowWithWebAuthnMethod: %s", err.Error()) + } } + + return nil } // Marshal data from the first non-nil pointers in the struct to JSON diff --git a/internal/client-go/model_update_recovery_flow_body.go b/internal/client-go/model_update_recovery_flow_body.go index 6eea1d5d6b6a..b0f6de861b4f 100644 --- a/internal/client-go/model_update_recovery_flow_body.go +++ b/internal/client-go/model_update_recovery_flow_body.go @@ -39,44 +39,62 @@ func UpdateRecoveryFlowWithLinkMethodAsUpdateRecoveryFlowBody(v *UpdateRecoveryF // Unmarshal JSON data into one of the pointers in the struct func (dst *UpdateRecoveryFlowBody) UnmarshalJSON(data []byte) error { var err error - match := 0 - // try to unmarshal data into UpdateRecoveryFlowWithCodeMethod - err = newStrictDecoder(data).Decode(&dst.UpdateRecoveryFlowWithCodeMethod) - if err == nil { - jsonUpdateRecoveryFlowWithCodeMethod, _ := json.Marshal(dst.UpdateRecoveryFlowWithCodeMethod) - if string(jsonUpdateRecoveryFlowWithCodeMethod) == "{}" { // empty struct - dst.UpdateRecoveryFlowWithCodeMethod = nil + // use discriminator value to speed up the lookup + var jsonDict map[string]interface{} + err = newStrictDecoder(data).Decode(&jsonDict) + if err != nil { + return fmt.Errorf("Failed to unmarshal JSON into map for the discrimintor lookup.") + } + + // check if the discriminator value is 'code' + if jsonDict["method"] == "code" { + // try to unmarshal JSON data into UpdateRecoveryFlowWithCodeMethod + err = json.Unmarshal(data, &dst.UpdateRecoveryFlowWithCodeMethod) + if err == nil { + return nil // data stored in dst.UpdateRecoveryFlowWithCodeMethod, return on the first match } else { - match++ + dst.UpdateRecoveryFlowWithCodeMethod = nil + return fmt.Errorf("Failed to unmarshal UpdateRecoveryFlowBody as UpdateRecoveryFlowWithCodeMethod: %s", err.Error()) } - } else { - dst.UpdateRecoveryFlowWithCodeMethod = nil } - // try to unmarshal data into UpdateRecoveryFlowWithLinkMethod - err = newStrictDecoder(data).Decode(&dst.UpdateRecoveryFlowWithLinkMethod) - if err == nil { - jsonUpdateRecoveryFlowWithLinkMethod, _ := json.Marshal(dst.UpdateRecoveryFlowWithLinkMethod) - if string(jsonUpdateRecoveryFlowWithLinkMethod) == "{}" { // empty struct - dst.UpdateRecoveryFlowWithLinkMethod = nil + // check if the discriminator value is 'link' + if jsonDict["method"] == "link" { + // try to unmarshal JSON data into UpdateRecoveryFlowWithLinkMethod + err = json.Unmarshal(data, &dst.UpdateRecoveryFlowWithLinkMethod) + if err == nil { + return nil // data stored in dst.UpdateRecoveryFlowWithLinkMethod, return on the first match } else { - match++ + dst.UpdateRecoveryFlowWithLinkMethod = nil + return fmt.Errorf("Failed to unmarshal UpdateRecoveryFlowBody as UpdateRecoveryFlowWithLinkMethod: %s", err.Error()) } - } else { - dst.UpdateRecoveryFlowWithLinkMethod = nil } - if match > 1 { // more than 1 match - // reset to nil - dst.UpdateRecoveryFlowWithCodeMethod = nil - dst.UpdateRecoveryFlowWithLinkMethod = nil + // check if the discriminator value is 'updateRecoveryFlowWithCodeMethod' + if jsonDict["method"] == "updateRecoveryFlowWithCodeMethod" { + // try to unmarshal JSON data into UpdateRecoveryFlowWithCodeMethod + err = json.Unmarshal(data, &dst.UpdateRecoveryFlowWithCodeMethod) + if err == nil { + return nil // data stored in dst.UpdateRecoveryFlowWithCodeMethod, return on the first match + } else { + dst.UpdateRecoveryFlowWithCodeMethod = nil + return fmt.Errorf("Failed to unmarshal UpdateRecoveryFlowBody as UpdateRecoveryFlowWithCodeMethod: %s", err.Error()) + } + } - return fmt.Errorf("Data matches more than one schema in oneOf(UpdateRecoveryFlowBody)") - } else if match == 1 { - return nil // exactly one match - } else { // no match - return fmt.Errorf("Data failed to match schemas in oneOf(UpdateRecoveryFlowBody)") + // check if the discriminator value is 'updateRecoveryFlowWithLinkMethod' + if jsonDict["method"] == "updateRecoveryFlowWithLinkMethod" { + // try to unmarshal JSON data into UpdateRecoveryFlowWithLinkMethod + err = json.Unmarshal(data, &dst.UpdateRecoveryFlowWithLinkMethod) + if err == nil { + return nil // data stored in dst.UpdateRecoveryFlowWithLinkMethod, return on the first match + } else { + dst.UpdateRecoveryFlowWithLinkMethod = nil + return fmt.Errorf("Failed to unmarshal UpdateRecoveryFlowBody as UpdateRecoveryFlowWithLinkMethod: %s", err.Error()) + } } + + return nil } // Marshal data from the first non-nil pointers in the struct to JSON diff --git a/internal/client-go/model_update_registration_flow_body.go b/internal/client-go/model_update_registration_flow_body.go index 0e36a95f635f..7272ea1ace1a 100644 --- a/internal/client-go/model_update_registration_flow_body.go +++ b/internal/client-go/model_update_registration_flow_body.go @@ -55,72 +55,110 @@ func UpdateRegistrationFlowWithWebAuthnMethodAsUpdateRegistrationFlowBody(v *Upd // Unmarshal JSON data into one of the pointers in the struct func (dst *UpdateRegistrationFlowBody) UnmarshalJSON(data []byte) error { var err error - match := 0 - // try to unmarshal data into UpdateRegistrationFlowWithCodeMethod - err = newStrictDecoder(data).Decode(&dst.UpdateRegistrationFlowWithCodeMethod) - if err == nil { - jsonUpdateRegistrationFlowWithCodeMethod, _ := json.Marshal(dst.UpdateRegistrationFlowWithCodeMethod) - if string(jsonUpdateRegistrationFlowWithCodeMethod) == "{}" { // empty struct - dst.UpdateRegistrationFlowWithCodeMethod = nil + // use discriminator value to speed up the lookup + var jsonDict map[string]interface{} + err = newStrictDecoder(data).Decode(&jsonDict) + if err != nil { + return fmt.Errorf("Failed to unmarshal JSON into map for the discrimintor lookup.") + } + + // check if the discriminator value is 'code' + if jsonDict["method"] == "code" { + // try to unmarshal JSON data into UpdateRegistrationFlowWithCodeMethod + err = json.Unmarshal(data, &dst.UpdateRegistrationFlowWithCodeMethod) + if err == nil { + return nil // data stored in dst.UpdateRegistrationFlowWithCodeMethod, return on the first match } else { - match++ + dst.UpdateRegistrationFlowWithCodeMethod = nil + return fmt.Errorf("Failed to unmarshal UpdateRegistrationFlowBody as UpdateRegistrationFlowWithCodeMethod: %s", err.Error()) } - } else { - dst.UpdateRegistrationFlowWithCodeMethod = nil } - // try to unmarshal data into UpdateRegistrationFlowWithOidcMethod - err = newStrictDecoder(data).Decode(&dst.UpdateRegistrationFlowWithOidcMethod) - if err == nil { - jsonUpdateRegistrationFlowWithOidcMethod, _ := json.Marshal(dst.UpdateRegistrationFlowWithOidcMethod) - if string(jsonUpdateRegistrationFlowWithOidcMethod) == "{}" { // empty struct - dst.UpdateRegistrationFlowWithOidcMethod = nil + // check if the discriminator value is 'oidc' + if jsonDict["method"] == "oidc" { + // try to unmarshal JSON data into UpdateRegistrationFlowWithOidcMethod + err = json.Unmarshal(data, &dst.UpdateRegistrationFlowWithOidcMethod) + if err == nil { + return nil // data stored in dst.UpdateRegistrationFlowWithOidcMethod, return on the first match } else { - match++ + dst.UpdateRegistrationFlowWithOidcMethod = nil + return fmt.Errorf("Failed to unmarshal UpdateRegistrationFlowBody as UpdateRegistrationFlowWithOidcMethod: %s", err.Error()) } - } else { - dst.UpdateRegistrationFlowWithOidcMethod = nil } - // try to unmarshal data into UpdateRegistrationFlowWithPasswordMethod - err = newStrictDecoder(data).Decode(&dst.UpdateRegistrationFlowWithPasswordMethod) - if err == nil { - jsonUpdateRegistrationFlowWithPasswordMethod, _ := json.Marshal(dst.UpdateRegistrationFlowWithPasswordMethod) - if string(jsonUpdateRegistrationFlowWithPasswordMethod) == "{}" { // empty struct - dst.UpdateRegistrationFlowWithPasswordMethod = nil + // check if the discriminator value is 'password' + if jsonDict["method"] == "password" { + // try to unmarshal JSON data into UpdateRegistrationFlowWithPasswordMethod + err = json.Unmarshal(data, &dst.UpdateRegistrationFlowWithPasswordMethod) + if err == nil { + return nil // data stored in dst.UpdateRegistrationFlowWithPasswordMethod, return on the first match } else { - match++ + dst.UpdateRegistrationFlowWithPasswordMethod = nil + return fmt.Errorf("Failed to unmarshal UpdateRegistrationFlowBody as UpdateRegistrationFlowWithPasswordMethod: %s", err.Error()) } - } else { - dst.UpdateRegistrationFlowWithPasswordMethod = nil } - // try to unmarshal data into UpdateRegistrationFlowWithWebAuthnMethod - err = newStrictDecoder(data).Decode(&dst.UpdateRegistrationFlowWithWebAuthnMethod) - if err == nil { - jsonUpdateRegistrationFlowWithWebAuthnMethod, _ := json.Marshal(dst.UpdateRegistrationFlowWithWebAuthnMethod) - if string(jsonUpdateRegistrationFlowWithWebAuthnMethod) == "{}" { // empty struct + // check if the discriminator value is 'webauthn' + if jsonDict["method"] == "webauthn" { + // try to unmarshal JSON data into UpdateRegistrationFlowWithWebAuthnMethod + err = json.Unmarshal(data, &dst.UpdateRegistrationFlowWithWebAuthnMethod) + if err == nil { + return nil // data stored in dst.UpdateRegistrationFlowWithWebAuthnMethod, return on the first match + } else { dst.UpdateRegistrationFlowWithWebAuthnMethod = nil + return fmt.Errorf("Failed to unmarshal UpdateRegistrationFlowBody as UpdateRegistrationFlowWithWebAuthnMethod: %s", err.Error()) + } + } + + // check if the discriminator value is 'updateRegistrationFlowWithCodeMethod' + if jsonDict["method"] == "updateRegistrationFlowWithCodeMethod" { + // try to unmarshal JSON data into UpdateRegistrationFlowWithCodeMethod + err = json.Unmarshal(data, &dst.UpdateRegistrationFlowWithCodeMethod) + if err == nil { + return nil // data stored in dst.UpdateRegistrationFlowWithCodeMethod, return on the first match } else { - match++ + dst.UpdateRegistrationFlowWithCodeMethod = nil + return fmt.Errorf("Failed to unmarshal UpdateRegistrationFlowBody as UpdateRegistrationFlowWithCodeMethod: %s", err.Error()) } - } else { - dst.UpdateRegistrationFlowWithWebAuthnMethod = nil } - if match > 1 { // more than 1 match - // reset to nil - dst.UpdateRegistrationFlowWithCodeMethod = nil - dst.UpdateRegistrationFlowWithOidcMethod = nil - dst.UpdateRegistrationFlowWithPasswordMethod = nil - dst.UpdateRegistrationFlowWithWebAuthnMethod = nil + // check if the discriminator value is 'updateRegistrationFlowWithOidcMethod' + if jsonDict["method"] == "updateRegistrationFlowWithOidcMethod" { + // try to unmarshal JSON data into UpdateRegistrationFlowWithOidcMethod + err = json.Unmarshal(data, &dst.UpdateRegistrationFlowWithOidcMethod) + if err == nil { + return nil // data stored in dst.UpdateRegistrationFlowWithOidcMethod, return on the first match + } else { + dst.UpdateRegistrationFlowWithOidcMethod = nil + return fmt.Errorf("Failed to unmarshal UpdateRegistrationFlowBody as UpdateRegistrationFlowWithOidcMethod: %s", err.Error()) + } + } + + // check if the discriminator value is 'updateRegistrationFlowWithPasswordMethod' + if jsonDict["method"] == "updateRegistrationFlowWithPasswordMethod" { + // try to unmarshal JSON data into UpdateRegistrationFlowWithPasswordMethod + err = json.Unmarshal(data, &dst.UpdateRegistrationFlowWithPasswordMethod) + if err == nil { + return nil // data stored in dst.UpdateRegistrationFlowWithPasswordMethod, return on the first match + } else { + dst.UpdateRegistrationFlowWithPasswordMethod = nil + return fmt.Errorf("Failed to unmarshal UpdateRegistrationFlowBody as UpdateRegistrationFlowWithPasswordMethod: %s", err.Error()) + } + } - return fmt.Errorf("Data matches more than one schema in oneOf(UpdateRegistrationFlowBody)") - } else if match == 1 { - return nil // exactly one match - } else { // no match - return fmt.Errorf("Data failed to match schemas in oneOf(UpdateRegistrationFlowBody)") + // check if the discriminator value is 'updateRegistrationFlowWithWebAuthnMethod' + if jsonDict["method"] == "updateRegistrationFlowWithWebAuthnMethod" { + // try to unmarshal JSON data into UpdateRegistrationFlowWithWebAuthnMethod + err = json.Unmarshal(data, &dst.UpdateRegistrationFlowWithWebAuthnMethod) + if err == nil { + return nil // data stored in dst.UpdateRegistrationFlowWithWebAuthnMethod, return on the first match + } else { + dst.UpdateRegistrationFlowWithWebAuthnMethod = nil + return fmt.Errorf("Failed to unmarshal UpdateRegistrationFlowBody as UpdateRegistrationFlowWithWebAuthnMethod: %s", err.Error()) + } } + + return nil } // Marshal data from the first non-nil pointers in the struct to JSON diff --git a/internal/client-go/model_update_settings_flow_body.go b/internal/client-go/model_update_settings_flow_body.go index 064ff9b771dd..e2aec380a586 100644 --- a/internal/client-go/model_update_settings_flow_body.go +++ b/internal/client-go/model_update_settings_flow_body.go @@ -71,100 +71,158 @@ func UpdateSettingsFlowWithWebAuthnMethodAsUpdateSettingsFlowBody(v *UpdateSetti // Unmarshal JSON data into one of the pointers in the struct func (dst *UpdateSettingsFlowBody) UnmarshalJSON(data []byte) error { var err error - match := 0 - // try to unmarshal data into UpdateSettingsFlowWithLookupMethod - err = newStrictDecoder(data).Decode(&dst.UpdateSettingsFlowWithLookupMethod) - if err == nil { - jsonUpdateSettingsFlowWithLookupMethod, _ := json.Marshal(dst.UpdateSettingsFlowWithLookupMethod) - if string(jsonUpdateSettingsFlowWithLookupMethod) == "{}" { // empty struct - dst.UpdateSettingsFlowWithLookupMethod = nil + // use discriminator value to speed up the lookup + var jsonDict map[string]interface{} + err = newStrictDecoder(data).Decode(&jsonDict) + if err != nil { + return fmt.Errorf("Failed to unmarshal JSON into map for the discrimintor lookup.") + } + + // check if the discriminator value is 'lookup_secret' + if jsonDict["method"] == "lookup_secret" { + // try to unmarshal JSON data into UpdateSettingsFlowWithLookupMethod + err = json.Unmarshal(data, &dst.UpdateSettingsFlowWithLookupMethod) + if err == nil { + return nil // data stored in dst.UpdateSettingsFlowWithLookupMethod, return on the first match } else { - match++ + dst.UpdateSettingsFlowWithLookupMethod = nil + return fmt.Errorf("Failed to unmarshal UpdateSettingsFlowBody as UpdateSettingsFlowWithLookupMethod: %s", err.Error()) } - } else { - dst.UpdateSettingsFlowWithLookupMethod = nil } - // try to unmarshal data into UpdateSettingsFlowWithOidcMethod - err = newStrictDecoder(data).Decode(&dst.UpdateSettingsFlowWithOidcMethod) - if err == nil { - jsonUpdateSettingsFlowWithOidcMethod, _ := json.Marshal(dst.UpdateSettingsFlowWithOidcMethod) - if string(jsonUpdateSettingsFlowWithOidcMethod) == "{}" { // empty struct - dst.UpdateSettingsFlowWithOidcMethod = nil + // check if the discriminator value is 'oidc' + if jsonDict["method"] == "oidc" { + // try to unmarshal JSON data into UpdateSettingsFlowWithOidcMethod + err = json.Unmarshal(data, &dst.UpdateSettingsFlowWithOidcMethod) + if err == nil { + return nil // data stored in dst.UpdateSettingsFlowWithOidcMethod, return on the first match } else { - match++ + dst.UpdateSettingsFlowWithOidcMethod = nil + return fmt.Errorf("Failed to unmarshal UpdateSettingsFlowBody as UpdateSettingsFlowWithOidcMethod: %s", err.Error()) } - } else { - dst.UpdateSettingsFlowWithOidcMethod = nil } - // try to unmarshal data into UpdateSettingsFlowWithPasswordMethod - err = newStrictDecoder(data).Decode(&dst.UpdateSettingsFlowWithPasswordMethod) - if err == nil { - jsonUpdateSettingsFlowWithPasswordMethod, _ := json.Marshal(dst.UpdateSettingsFlowWithPasswordMethod) - if string(jsonUpdateSettingsFlowWithPasswordMethod) == "{}" { // empty struct - dst.UpdateSettingsFlowWithPasswordMethod = nil + // check if the discriminator value is 'password' + if jsonDict["method"] == "password" { + // try to unmarshal JSON data into UpdateSettingsFlowWithPasswordMethod + err = json.Unmarshal(data, &dst.UpdateSettingsFlowWithPasswordMethod) + if err == nil { + return nil // data stored in dst.UpdateSettingsFlowWithPasswordMethod, return on the first match } else { - match++ + dst.UpdateSettingsFlowWithPasswordMethod = nil + return fmt.Errorf("Failed to unmarshal UpdateSettingsFlowBody as UpdateSettingsFlowWithPasswordMethod: %s", err.Error()) } - } else { - dst.UpdateSettingsFlowWithPasswordMethod = nil } - // try to unmarshal data into UpdateSettingsFlowWithProfileMethod - err = newStrictDecoder(data).Decode(&dst.UpdateSettingsFlowWithProfileMethod) - if err == nil { - jsonUpdateSettingsFlowWithProfileMethod, _ := json.Marshal(dst.UpdateSettingsFlowWithProfileMethod) - if string(jsonUpdateSettingsFlowWithProfileMethod) == "{}" { // empty struct - dst.UpdateSettingsFlowWithProfileMethod = nil + // check if the discriminator value is 'profile' + if jsonDict["method"] == "profile" { + // try to unmarshal JSON data into UpdateSettingsFlowWithProfileMethod + err = json.Unmarshal(data, &dst.UpdateSettingsFlowWithProfileMethod) + if err == nil { + return nil // data stored in dst.UpdateSettingsFlowWithProfileMethod, return on the first match } else { - match++ + dst.UpdateSettingsFlowWithProfileMethod = nil + return fmt.Errorf("Failed to unmarshal UpdateSettingsFlowBody as UpdateSettingsFlowWithProfileMethod: %s", err.Error()) } - } else { - dst.UpdateSettingsFlowWithProfileMethod = nil } - // try to unmarshal data into UpdateSettingsFlowWithTotpMethod - err = newStrictDecoder(data).Decode(&dst.UpdateSettingsFlowWithTotpMethod) - if err == nil { - jsonUpdateSettingsFlowWithTotpMethod, _ := json.Marshal(dst.UpdateSettingsFlowWithTotpMethod) - if string(jsonUpdateSettingsFlowWithTotpMethod) == "{}" { // empty struct - dst.UpdateSettingsFlowWithTotpMethod = nil + // check if the discriminator value is 'totp' + if jsonDict["method"] == "totp" { + // try to unmarshal JSON data into UpdateSettingsFlowWithTotpMethod + err = json.Unmarshal(data, &dst.UpdateSettingsFlowWithTotpMethod) + if err == nil { + return nil // data stored in dst.UpdateSettingsFlowWithTotpMethod, return on the first match } else { - match++ + dst.UpdateSettingsFlowWithTotpMethod = nil + return fmt.Errorf("Failed to unmarshal UpdateSettingsFlowBody as UpdateSettingsFlowWithTotpMethod: %s", err.Error()) } - } else { - dst.UpdateSettingsFlowWithTotpMethod = nil } - // try to unmarshal data into UpdateSettingsFlowWithWebAuthnMethod - err = newStrictDecoder(data).Decode(&dst.UpdateSettingsFlowWithWebAuthnMethod) - if err == nil { - jsonUpdateSettingsFlowWithWebAuthnMethod, _ := json.Marshal(dst.UpdateSettingsFlowWithWebAuthnMethod) - if string(jsonUpdateSettingsFlowWithWebAuthnMethod) == "{}" { // empty struct + // check if the discriminator value is 'webauthn' + if jsonDict["method"] == "webauthn" { + // try to unmarshal JSON data into UpdateSettingsFlowWithWebAuthnMethod + err = json.Unmarshal(data, &dst.UpdateSettingsFlowWithWebAuthnMethod) + if err == nil { + return nil // data stored in dst.UpdateSettingsFlowWithWebAuthnMethod, return on the first match + } else { dst.UpdateSettingsFlowWithWebAuthnMethod = nil + return fmt.Errorf("Failed to unmarshal UpdateSettingsFlowBody as UpdateSettingsFlowWithWebAuthnMethod: %s", err.Error()) + } + } + + // check if the discriminator value is 'updateSettingsFlowWithLookupMethod' + if jsonDict["method"] == "updateSettingsFlowWithLookupMethod" { + // try to unmarshal JSON data into UpdateSettingsFlowWithLookupMethod + err = json.Unmarshal(data, &dst.UpdateSettingsFlowWithLookupMethod) + if err == nil { + return nil // data stored in dst.UpdateSettingsFlowWithLookupMethod, return on the first match } else { - match++ + dst.UpdateSettingsFlowWithLookupMethod = nil + return fmt.Errorf("Failed to unmarshal UpdateSettingsFlowBody as UpdateSettingsFlowWithLookupMethod: %s", err.Error()) } - } else { - dst.UpdateSettingsFlowWithWebAuthnMethod = nil } - if match > 1 { // more than 1 match - // reset to nil - dst.UpdateSettingsFlowWithLookupMethod = nil - dst.UpdateSettingsFlowWithOidcMethod = nil - dst.UpdateSettingsFlowWithPasswordMethod = nil - dst.UpdateSettingsFlowWithProfileMethod = nil - dst.UpdateSettingsFlowWithTotpMethod = nil - dst.UpdateSettingsFlowWithWebAuthnMethod = nil + // check if the discriminator value is 'updateSettingsFlowWithOidcMethod' + if jsonDict["method"] == "updateSettingsFlowWithOidcMethod" { + // try to unmarshal JSON data into UpdateSettingsFlowWithOidcMethod + err = json.Unmarshal(data, &dst.UpdateSettingsFlowWithOidcMethod) + if err == nil { + return nil // data stored in dst.UpdateSettingsFlowWithOidcMethod, return on the first match + } else { + dst.UpdateSettingsFlowWithOidcMethod = nil + return fmt.Errorf("Failed to unmarshal UpdateSettingsFlowBody as UpdateSettingsFlowWithOidcMethod: %s", err.Error()) + } + } - return fmt.Errorf("Data matches more than one schema in oneOf(UpdateSettingsFlowBody)") - } else if match == 1 { - return nil // exactly one match - } else { // no match - return fmt.Errorf("Data failed to match schemas in oneOf(UpdateSettingsFlowBody)") + // check if the discriminator value is 'updateSettingsFlowWithPasswordMethod' + if jsonDict["method"] == "updateSettingsFlowWithPasswordMethod" { + // try to unmarshal JSON data into UpdateSettingsFlowWithPasswordMethod + err = json.Unmarshal(data, &dst.UpdateSettingsFlowWithPasswordMethod) + if err == nil { + return nil // data stored in dst.UpdateSettingsFlowWithPasswordMethod, return on the first match + } else { + dst.UpdateSettingsFlowWithPasswordMethod = nil + return fmt.Errorf("Failed to unmarshal UpdateSettingsFlowBody as UpdateSettingsFlowWithPasswordMethod: %s", err.Error()) + } + } + + // check if the discriminator value is 'updateSettingsFlowWithProfileMethod' + if jsonDict["method"] == "updateSettingsFlowWithProfileMethod" { + // try to unmarshal JSON data into UpdateSettingsFlowWithProfileMethod + err = json.Unmarshal(data, &dst.UpdateSettingsFlowWithProfileMethod) + if err == nil { + return nil // data stored in dst.UpdateSettingsFlowWithProfileMethod, return on the first match + } else { + dst.UpdateSettingsFlowWithProfileMethod = nil + return fmt.Errorf("Failed to unmarshal UpdateSettingsFlowBody as UpdateSettingsFlowWithProfileMethod: %s", err.Error()) + } + } + + // check if the discriminator value is 'updateSettingsFlowWithTotpMethod' + if jsonDict["method"] == "updateSettingsFlowWithTotpMethod" { + // try to unmarshal JSON data into UpdateSettingsFlowWithTotpMethod + err = json.Unmarshal(data, &dst.UpdateSettingsFlowWithTotpMethod) + if err == nil { + return nil // data stored in dst.UpdateSettingsFlowWithTotpMethod, return on the first match + } else { + dst.UpdateSettingsFlowWithTotpMethod = nil + return fmt.Errorf("Failed to unmarshal UpdateSettingsFlowBody as UpdateSettingsFlowWithTotpMethod: %s", err.Error()) + } + } + + // check if the discriminator value is 'updateSettingsFlowWithWebAuthnMethod' + if jsonDict["method"] == "updateSettingsFlowWithWebAuthnMethod" { + // try to unmarshal JSON data into UpdateSettingsFlowWithWebAuthnMethod + err = json.Unmarshal(data, &dst.UpdateSettingsFlowWithWebAuthnMethod) + if err == nil { + return nil // data stored in dst.UpdateSettingsFlowWithWebAuthnMethod, return on the first match + } else { + dst.UpdateSettingsFlowWithWebAuthnMethod = nil + return fmt.Errorf("Failed to unmarshal UpdateSettingsFlowBody as UpdateSettingsFlowWithWebAuthnMethod: %s", err.Error()) + } } + + return nil } // Marshal data from the first non-nil pointers in the struct to JSON diff --git a/internal/client-go/model_update_verification_flow_body.go b/internal/client-go/model_update_verification_flow_body.go index f4e995d222c3..9065bfdbc58e 100644 --- a/internal/client-go/model_update_verification_flow_body.go +++ b/internal/client-go/model_update_verification_flow_body.go @@ -39,44 +39,62 @@ func UpdateVerificationFlowWithLinkMethodAsUpdateVerificationFlowBody(v *UpdateV // Unmarshal JSON data into one of the pointers in the struct func (dst *UpdateVerificationFlowBody) UnmarshalJSON(data []byte) error { var err error - match := 0 - // try to unmarshal data into UpdateVerificationFlowWithCodeMethod - err = newStrictDecoder(data).Decode(&dst.UpdateVerificationFlowWithCodeMethod) - if err == nil { - jsonUpdateVerificationFlowWithCodeMethod, _ := json.Marshal(dst.UpdateVerificationFlowWithCodeMethod) - if string(jsonUpdateVerificationFlowWithCodeMethod) == "{}" { // empty struct - dst.UpdateVerificationFlowWithCodeMethod = nil + // use discriminator value to speed up the lookup + var jsonDict map[string]interface{} + err = newStrictDecoder(data).Decode(&jsonDict) + if err != nil { + return fmt.Errorf("Failed to unmarshal JSON into map for the discrimintor lookup.") + } + + // check if the discriminator value is 'code' + if jsonDict["method"] == "code" { + // try to unmarshal JSON data into UpdateVerificationFlowWithCodeMethod + err = json.Unmarshal(data, &dst.UpdateVerificationFlowWithCodeMethod) + if err == nil { + return nil // data stored in dst.UpdateVerificationFlowWithCodeMethod, return on the first match } else { - match++ + dst.UpdateVerificationFlowWithCodeMethod = nil + return fmt.Errorf("Failed to unmarshal UpdateVerificationFlowBody as UpdateVerificationFlowWithCodeMethod: %s", err.Error()) } - } else { - dst.UpdateVerificationFlowWithCodeMethod = nil } - // try to unmarshal data into UpdateVerificationFlowWithLinkMethod - err = newStrictDecoder(data).Decode(&dst.UpdateVerificationFlowWithLinkMethod) - if err == nil { - jsonUpdateVerificationFlowWithLinkMethod, _ := json.Marshal(dst.UpdateVerificationFlowWithLinkMethod) - if string(jsonUpdateVerificationFlowWithLinkMethod) == "{}" { // empty struct - dst.UpdateVerificationFlowWithLinkMethod = nil + // check if the discriminator value is 'link' + if jsonDict["method"] == "link" { + // try to unmarshal JSON data into UpdateVerificationFlowWithLinkMethod + err = json.Unmarshal(data, &dst.UpdateVerificationFlowWithLinkMethod) + if err == nil { + return nil // data stored in dst.UpdateVerificationFlowWithLinkMethod, return on the first match } else { - match++ + dst.UpdateVerificationFlowWithLinkMethod = nil + return fmt.Errorf("Failed to unmarshal UpdateVerificationFlowBody as UpdateVerificationFlowWithLinkMethod: %s", err.Error()) } - } else { - dst.UpdateVerificationFlowWithLinkMethod = nil } - if match > 1 { // more than 1 match - // reset to nil - dst.UpdateVerificationFlowWithCodeMethod = nil - dst.UpdateVerificationFlowWithLinkMethod = nil + // check if the discriminator value is 'updateVerificationFlowWithCodeMethod' + if jsonDict["method"] == "updateVerificationFlowWithCodeMethod" { + // try to unmarshal JSON data into UpdateVerificationFlowWithCodeMethod + err = json.Unmarshal(data, &dst.UpdateVerificationFlowWithCodeMethod) + if err == nil { + return nil // data stored in dst.UpdateVerificationFlowWithCodeMethod, return on the first match + } else { + dst.UpdateVerificationFlowWithCodeMethod = nil + return fmt.Errorf("Failed to unmarshal UpdateVerificationFlowBody as UpdateVerificationFlowWithCodeMethod: %s", err.Error()) + } + } - return fmt.Errorf("Data matches more than one schema in oneOf(UpdateVerificationFlowBody)") - } else if match == 1 { - return nil // exactly one match - } else { // no match - return fmt.Errorf("Data failed to match schemas in oneOf(UpdateVerificationFlowBody)") + // check if the discriminator value is 'updateVerificationFlowWithLinkMethod' + if jsonDict["method"] == "updateVerificationFlowWithLinkMethod" { + // try to unmarshal JSON data into UpdateVerificationFlowWithLinkMethod + err = json.Unmarshal(data, &dst.UpdateVerificationFlowWithLinkMethod) + if err == nil { + return nil // data stored in dst.UpdateVerificationFlowWithLinkMethod, return on the first match + } else { + dst.UpdateVerificationFlowWithLinkMethod = nil + return fmt.Errorf("Failed to unmarshal UpdateVerificationFlowBody as UpdateVerificationFlowWithLinkMethod: %s", err.Error()) + } } + + return nil } // Marshal data from the first non-nil pointers in the struct to JSON diff --git a/internal/httpclient/model_continue_with.go b/internal/httpclient/model_continue_with.go index ee84e74692fb..9e97dbf479e7 100644 --- a/internal/httpclient/model_continue_with.go +++ b/internal/httpclient/model_continue_with.go @@ -55,72 +55,110 @@ func ContinueWithVerificationUiAsContinueWith(v *ContinueWithVerificationUi) Con // Unmarshal JSON data into one of the pointers in the struct func (dst *ContinueWith) UnmarshalJSON(data []byte) error { var err error - match := 0 - // try to unmarshal data into ContinueWithRecoveryUi - err = newStrictDecoder(data).Decode(&dst.ContinueWithRecoveryUi) - if err == nil { - jsonContinueWithRecoveryUi, _ := json.Marshal(dst.ContinueWithRecoveryUi) - if string(jsonContinueWithRecoveryUi) == "{}" { // empty struct - dst.ContinueWithRecoveryUi = nil + // use discriminator value to speed up the lookup + var jsonDict map[string]interface{} + err = newStrictDecoder(data).Decode(&jsonDict) + if err != nil { + return fmt.Errorf("Failed to unmarshal JSON into map for the discrimintor lookup.") + } + + // check if the discriminator value is 'set_ory_session_token' + if jsonDict["action"] == "set_ory_session_token" { + // try to unmarshal JSON data into ContinueWithSetOrySessionToken + err = json.Unmarshal(data, &dst.ContinueWithSetOrySessionToken) + if err == nil { + return nil // data stored in dst.ContinueWithSetOrySessionToken, return on the first match } else { - match++ + dst.ContinueWithSetOrySessionToken = nil + return fmt.Errorf("Failed to unmarshal ContinueWith as ContinueWithSetOrySessionToken: %s", err.Error()) } - } else { - dst.ContinueWithRecoveryUi = nil } - // try to unmarshal data into ContinueWithSetOrySessionToken - err = newStrictDecoder(data).Decode(&dst.ContinueWithSetOrySessionToken) - if err == nil { - jsonContinueWithSetOrySessionToken, _ := json.Marshal(dst.ContinueWithSetOrySessionToken) - if string(jsonContinueWithSetOrySessionToken) == "{}" { // empty struct - dst.ContinueWithSetOrySessionToken = nil + // check if the discriminator value is 'show_recovery_ui' + if jsonDict["action"] == "show_recovery_ui" { + // try to unmarshal JSON data into ContinueWithRecoveryUi + err = json.Unmarshal(data, &dst.ContinueWithRecoveryUi) + if err == nil { + return nil // data stored in dst.ContinueWithRecoveryUi, return on the first match } else { - match++ + dst.ContinueWithRecoveryUi = nil + return fmt.Errorf("Failed to unmarshal ContinueWith as ContinueWithRecoveryUi: %s", err.Error()) } - } else { - dst.ContinueWithSetOrySessionToken = nil } - // try to unmarshal data into ContinueWithSettingsUi - err = newStrictDecoder(data).Decode(&dst.ContinueWithSettingsUi) - if err == nil { - jsonContinueWithSettingsUi, _ := json.Marshal(dst.ContinueWithSettingsUi) - if string(jsonContinueWithSettingsUi) == "{}" { // empty struct - dst.ContinueWithSettingsUi = nil + // check if the discriminator value is 'show_settings_ui' + if jsonDict["action"] == "show_settings_ui" { + // try to unmarshal JSON data into ContinueWithSettingsUi + err = json.Unmarshal(data, &dst.ContinueWithSettingsUi) + if err == nil { + return nil // data stored in dst.ContinueWithSettingsUi, return on the first match } else { - match++ + dst.ContinueWithSettingsUi = nil + return fmt.Errorf("Failed to unmarshal ContinueWith as ContinueWithSettingsUi: %s", err.Error()) } - } else { - dst.ContinueWithSettingsUi = nil } - // try to unmarshal data into ContinueWithVerificationUi - err = newStrictDecoder(data).Decode(&dst.ContinueWithVerificationUi) - if err == nil { - jsonContinueWithVerificationUi, _ := json.Marshal(dst.ContinueWithVerificationUi) - if string(jsonContinueWithVerificationUi) == "{}" { // empty struct + // check if the discriminator value is 'show_verification_ui' + if jsonDict["action"] == "show_verification_ui" { + // try to unmarshal JSON data into ContinueWithVerificationUi + err = json.Unmarshal(data, &dst.ContinueWithVerificationUi) + if err == nil { + return nil // data stored in dst.ContinueWithVerificationUi, return on the first match + } else { dst.ContinueWithVerificationUi = nil + return fmt.Errorf("Failed to unmarshal ContinueWith as ContinueWithVerificationUi: %s", err.Error()) + } + } + + // check if the discriminator value is 'continueWithRecoveryUi' + if jsonDict["action"] == "continueWithRecoveryUi" { + // try to unmarshal JSON data into ContinueWithRecoveryUi + err = json.Unmarshal(data, &dst.ContinueWithRecoveryUi) + if err == nil { + return nil // data stored in dst.ContinueWithRecoveryUi, return on the first match } else { - match++ + dst.ContinueWithRecoveryUi = nil + return fmt.Errorf("Failed to unmarshal ContinueWith as ContinueWithRecoveryUi: %s", err.Error()) } - } else { - dst.ContinueWithVerificationUi = nil } - if match > 1 { // more than 1 match - // reset to nil - dst.ContinueWithRecoveryUi = nil - dst.ContinueWithSetOrySessionToken = nil - dst.ContinueWithSettingsUi = nil - dst.ContinueWithVerificationUi = nil + // check if the discriminator value is 'continueWithSetOrySessionToken' + if jsonDict["action"] == "continueWithSetOrySessionToken" { + // try to unmarshal JSON data into ContinueWithSetOrySessionToken + err = json.Unmarshal(data, &dst.ContinueWithSetOrySessionToken) + if err == nil { + return nil // data stored in dst.ContinueWithSetOrySessionToken, return on the first match + } else { + dst.ContinueWithSetOrySessionToken = nil + return fmt.Errorf("Failed to unmarshal ContinueWith as ContinueWithSetOrySessionToken: %s", err.Error()) + } + } + + // check if the discriminator value is 'continueWithSettingsUi' + if jsonDict["action"] == "continueWithSettingsUi" { + // try to unmarshal JSON data into ContinueWithSettingsUi + err = json.Unmarshal(data, &dst.ContinueWithSettingsUi) + if err == nil { + return nil // data stored in dst.ContinueWithSettingsUi, return on the first match + } else { + dst.ContinueWithSettingsUi = nil + return fmt.Errorf("Failed to unmarshal ContinueWith as ContinueWithSettingsUi: %s", err.Error()) + } + } - return fmt.Errorf("Data matches more than one schema in oneOf(ContinueWith)") - } else if match == 1 { - return nil // exactly one match - } else { // no match - return fmt.Errorf("Data failed to match schemas in oneOf(ContinueWith)") + // check if the discriminator value is 'continueWithVerificationUi' + if jsonDict["action"] == "continueWithVerificationUi" { + // try to unmarshal JSON data into ContinueWithVerificationUi + err = json.Unmarshal(data, &dst.ContinueWithVerificationUi) + if err == nil { + return nil // data stored in dst.ContinueWithVerificationUi, return on the first match + } else { + dst.ContinueWithVerificationUi = nil + return fmt.Errorf("Failed to unmarshal ContinueWith as ContinueWithVerificationUi: %s", err.Error()) + } } + + return nil } // Marshal data from the first non-nil pointers in the struct to JSON diff --git a/internal/httpclient/model_ui_node_anchor_attributes.go b/internal/httpclient/model_ui_node_anchor_attributes.go index 15cb492fe8eb..ad2cc992a119 100644 --- a/internal/httpclient/model_ui_node_anchor_attributes.go +++ b/internal/httpclient/model_ui_node_anchor_attributes.go @@ -21,7 +21,7 @@ type UiNodeAnchorAttributes struct { Href string `json:"href"` // A unique identifier Id string `json:"id"` - // NodeType represents this node's types. It is a mirror of `node.type` and is primarily used to allow compatibility with OpenAPI 3.0. In this struct it technically always is \"a\". + // NodeType represents this node's types. It is a mirror of `node.type` and is primarily used to allow compatibility with OpenAPI 3.0. In this struct it technically always is \"a\". text Text input Input img Image a Anchor script Script NodeType string `json:"node_type"` Title UiText `json:"title"` } diff --git a/internal/httpclient/model_ui_node_attributes.go b/internal/httpclient/model_ui_node_attributes.go index 347be6f44a72..510dc20f8564 100644 --- a/internal/httpclient/model_ui_node_attributes.go +++ b/internal/httpclient/model_ui_node_attributes.go @@ -63,86 +63,134 @@ func UiNodeTextAttributesAsUiNodeAttributes(v *UiNodeTextAttributes) UiNodeAttri // Unmarshal JSON data into one of the pointers in the struct func (dst *UiNodeAttributes) UnmarshalJSON(data []byte) error { var err error - match := 0 - // try to unmarshal data into UiNodeAnchorAttributes - err = newStrictDecoder(data).Decode(&dst.UiNodeAnchorAttributes) - if err == nil { - jsonUiNodeAnchorAttributes, _ := json.Marshal(dst.UiNodeAnchorAttributes) - if string(jsonUiNodeAnchorAttributes) == "{}" { // empty struct - dst.UiNodeAnchorAttributes = nil + // use discriminator value to speed up the lookup + var jsonDict map[string]interface{} + err = newStrictDecoder(data).Decode(&jsonDict) + if err != nil { + return fmt.Errorf("Failed to unmarshal JSON into map for the discrimintor lookup.") + } + + // check if the discriminator value is 'a' + if jsonDict["node_type"] == "a" { + // try to unmarshal JSON data into UiNodeAnchorAttributes + err = json.Unmarshal(data, &dst.UiNodeAnchorAttributes) + if err == nil { + return nil // data stored in dst.UiNodeAnchorAttributes, return on the first match } else { - match++ + dst.UiNodeAnchorAttributes = nil + return fmt.Errorf("Failed to unmarshal UiNodeAttributes as UiNodeAnchorAttributes: %s", err.Error()) } - } else { - dst.UiNodeAnchorAttributes = nil } - // try to unmarshal data into UiNodeImageAttributes - err = newStrictDecoder(data).Decode(&dst.UiNodeImageAttributes) - if err == nil { - jsonUiNodeImageAttributes, _ := json.Marshal(dst.UiNodeImageAttributes) - if string(jsonUiNodeImageAttributes) == "{}" { // empty struct - dst.UiNodeImageAttributes = nil + // check if the discriminator value is 'img' + if jsonDict["node_type"] == "img" { + // try to unmarshal JSON data into UiNodeImageAttributes + err = json.Unmarshal(data, &dst.UiNodeImageAttributes) + if err == nil { + return nil // data stored in dst.UiNodeImageAttributes, return on the first match } else { - match++ + dst.UiNodeImageAttributes = nil + return fmt.Errorf("Failed to unmarshal UiNodeAttributes as UiNodeImageAttributes: %s", err.Error()) } - } else { - dst.UiNodeImageAttributes = nil } - // try to unmarshal data into UiNodeInputAttributes - err = newStrictDecoder(data).Decode(&dst.UiNodeInputAttributes) - if err == nil { - jsonUiNodeInputAttributes, _ := json.Marshal(dst.UiNodeInputAttributes) - if string(jsonUiNodeInputAttributes) == "{}" { // empty struct - dst.UiNodeInputAttributes = nil + // check if the discriminator value is 'input' + if jsonDict["node_type"] == "input" { + // try to unmarshal JSON data into UiNodeInputAttributes + err = json.Unmarshal(data, &dst.UiNodeInputAttributes) + if err == nil { + return nil // data stored in dst.UiNodeInputAttributes, return on the first match } else { - match++ + dst.UiNodeInputAttributes = nil + return fmt.Errorf("Failed to unmarshal UiNodeAttributes as UiNodeInputAttributes: %s", err.Error()) } - } else { - dst.UiNodeInputAttributes = nil } - // try to unmarshal data into UiNodeScriptAttributes - err = newStrictDecoder(data).Decode(&dst.UiNodeScriptAttributes) - if err == nil { - jsonUiNodeScriptAttributes, _ := json.Marshal(dst.UiNodeScriptAttributes) - if string(jsonUiNodeScriptAttributes) == "{}" { // empty struct - dst.UiNodeScriptAttributes = nil + // check if the discriminator value is 'script' + if jsonDict["node_type"] == "script" { + // try to unmarshal JSON data into UiNodeScriptAttributes + err = json.Unmarshal(data, &dst.UiNodeScriptAttributes) + if err == nil { + return nil // data stored in dst.UiNodeScriptAttributes, return on the first match } else { - match++ + dst.UiNodeScriptAttributes = nil + return fmt.Errorf("Failed to unmarshal UiNodeAttributes as UiNodeScriptAttributes: %s", err.Error()) } - } else { - dst.UiNodeScriptAttributes = nil } - // try to unmarshal data into UiNodeTextAttributes - err = newStrictDecoder(data).Decode(&dst.UiNodeTextAttributes) - if err == nil { - jsonUiNodeTextAttributes, _ := json.Marshal(dst.UiNodeTextAttributes) - if string(jsonUiNodeTextAttributes) == "{}" { // empty struct + // check if the discriminator value is 'text' + if jsonDict["node_type"] == "text" { + // try to unmarshal JSON data into UiNodeTextAttributes + err = json.Unmarshal(data, &dst.UiNodeTextAttributes) + if err == nil { + return nil // data stored in dst.UiNodeTextAttributes, return on the first match + } else { dst.UiNodeTextAttributes = nil + return fmt.Errorf("Failed to unmarshal UiNodeAttributes as UiNodeTextAttributes: %s", err.Error()) + } + } + + // check if the discriminator value is 'uiNodeAnchorAttributes' + if jsonDict["node_type"] == "uiNodeAnchorAttributes" { + // try to unmarshal JSON data into UiNodeAnchorAttributes + err = json.Unmarshal(data, &dst.UiNodeAnchorAttributes) + if err == nil { + return nil // data stored in dst.UiNodeAnchorAttributes, return on the first match + } else { + dst.UiNodeAnchorAttributes = nil + return fmt.Errorf("Failed to unmarshal UiNodeAttributes as UiNodeAnchorAttributes: %s", err.Error()) + } + } + + // check if the discriminator value is 'uiNodeImageAttributes' + if jsonDict["node_type"] == "uiNodeImageAttributes" { + // try to unmarshal JSON data into UiNodeImageAttributes + err = json.Unmarshal(data, &dst.UiNodeImageAttributes) + if err == nil { + return nil // data stored in dst.UiNodeImageAttributes, return on the first match } else { - match++ + dst.UiNodeImageAttributes = nil + return fmt.Errorf("Failed to unmarshal UiNodeAttributes as UiNodeImageAttributes: %s", err.Error()) } - } else { - dst.UiNodeTextAttributes = nil } - if match > 1 { // more than 1 match - // reset to nil - dst.UiNodeAnchorAttributes = nil - dst.UiNodeImageAttributes = nil - dst.UiNodeInputAttributes = nil - dst.UiNodeScriptAttributes = nil - dst.UiNodeTextAttributes = nil + // check if the discriminator value is 'uiNodeInputAttributes' + if jsonDict["node_type"] == "uiNodeInputAttributes" { + // try to unmarshal JSON data into UiNodeInputAttributes + err = json.Unmarshal(data, &dst.UiNodeInputAttributes) + if err == nil { + return nil // data stored in dst.UiNodeInputAttributes, return on the first match + } else { + dst.UiNodeInputAttributes = nil + return fmt.Errorf("Failed to unmarshal UiNodeAttributes as UiNodeInputAttributes: %s", err.Error()) + } + } - return fmt.Errorf("Data matches more than one schema in oneOf(UiNodeAttributes)") - } else if match == 1 { - return nil // exactly one match - } else { // no match - return fmt.Errorf("Data failed to match schemas in oneOf(UiNodeAttributes)") + // check if the discriminator value is 'uiNodeScriptAttributes' + if jsonDict["node_type"] == "uiNodeScriptAttributes" { + // try to unmarshal JSON data into UiNodeScriptAttributes + err = json.Unmarshal(data, &dst.UiNodeScriptAttributes) + if err == nil { + return nil // data stored in dst.UiNodeScriptAttributes, return on the first match + } else { + dst.UiNodeScriptAttributes = nil + return fmt.Errorf("Failed to unmarshal UiNodeAttributes as UiNodeScriptAttributes: %s", err.Error()) + } + } + + // check if the discriminator value is 'uiNodeTextAttributes' + if jsonDict["node_type"] == "uiNodeTextAttributes" { + // try to unmarshal JSON data into UiNodeTextAttributes + err = json.Unmarshal(data, &dst.UiNodeTextAttributes) + if err == nil { + return nil // data stored in dst.UiNodeTextAttributes, return on the first match + } else { + dst.UiNodeTextAttributes = nil + return fmt.Errorf("Failed to unmarshal UiNodeAttributes as UiNodeTextAttributes: %s", err.Error()) + } } + + return nil } // Marshal data from the first non-nil pointers in the struct to JSON diff --git a/internal/httpclient/model_ui_node_image_attributes.go b/internal/httpclient/model_ui_node_image_attributes.go index 5b300b9548bd..6eef160e3d67 100644 --- a/internal/httpclient/model_ui_node_image_attributes.go +++ b/internal/httpclient/model_ui_node_image_attributes.go @@ -21,7 +21,7 @@ type UiNodeImageAttributes struct { Height int64 `json:"height"` // A unique identifier Id string `json:"id"` - // NodeType represents this node's types. It is a mirror of `node.type` and is primarily used to allow compatibility with OpenAPI 3.0. In this struct it technically always is \"img\". + // NodeType represents this node's types. It is a mirror of `node.type` and is primarily used to allow compatibility with OpenAPI 3.0. In this struct it technically always is \"img\". text Text input Input img Image a Anchor script Script NodeType string `json:"node_type"` // The image's source URL. format: uri Src string `json:"src"` diff --git a/internal/httpclient/model_ui_node_input_attributes.go b/internal/httpclient/model_ui_node_input_attributes.go index fbf7e0f1b04e..b373dda7ccfd 100644 --- a/internal/httpclient/model_ui_node_input_attributes.go +++ b/internal/httpclient/model_ui_node_input_attributes.go @@ -24,7 +24,7 @@ type UiNodeInputAttributes struct { Label *UiText `json:"label,omitempty"` // The input's element name. Name string `json:"name"` - // NodeType represents this node's types. It is a mirror of `node.type` and is primarily used to allow compatibility with OpenAPI 3.0. In this struct it technically always is \"input\". + // NodeType represents this node's types. It is a mirror of `node.type` and is primarily used to allow compatibility with OpenAPI 3.0. In this struct it technically always is \"input\". text Text input Input img Image a Anchor script Script NodeType string `json:"node_type"` // OnClick may contain javascript which should be executed on click. This is primarily used for WebAuthn. Onclick *string `json:"onclick,omitempty"` diff --git a/internal/httpclient/model_ui_node_script_attributes.go b/internal/httpclient/model_ui_node_script_attributes.go index 21dca70cbe86..d867c1c66dba 100644 --- a/internal/httpclient/model_ui_node_script_attributes.go +++ b/internal/httpclient/model_ui_node_script_attributes.go @@ -25,7 +25,7 @@ type UiNodeScriptAttributes struct { Id string `json:"id"` // The script's integrity hash Integrity string `json:"integrity"` - // NodeType represents this node's types. It is a mirror of `node.type` and is primarily used to allow compatibility with OpenAPI 3.0. In this struct it technically always is \"script\". + // NodeType represents this node's types. It is a mirror of `node.type` and is primarily used to allow compatibility with OpenAPI 3.0. In this struct it technically always is \"script\". text Text input Input img Image a Anchor script Script NodeType string `json:"node_type"` // Nonce for CSP A nonce you may want to use to improve your Content Security Policy. You do not have to use this value but if you want to improve your CSP policies you may use it. You can also choose to use your own nonce value! Nonce string `json:"nonce"` diff --git a/internal/httpclient/model_ui_node_text_attributes.go b/internal/httpclient/model_ui_node_text_attributes.go index 6199187b5d75..93e0f8314191 100644 --- a/internal/httpclient/model_ui_node_text_attributes.go +++ b/internal/httpclient/model_ui_node_text_attributes.go @@ -19,7 +19,7 @@ import ( type UiNodeTextAttributes struct { // A unique identifier Id string `json:"id"` - // NodeType represents this node's types. It is a mirror of `node.type` and is primarily used to allow compatibility with OpenAPI 3.0. In this struct it technically always is \"text\". + // NodeType represents this node's types. It is a mirror of `node.type` and is primarily used to allow compatibility with OpenAPI 3.0. In this struct it technically always is \"text\". text Text input Input img Image a Anchor script Script NodeType string `json:"node_type"` Text UiText `json:"text"` } diff --git a/internal/httpclient/model_update_login_flow_body.go b/internal/httpclient/model_update_login_flow_body.go index 36033328e78d..ac3e4f503292 100644 --- a/internal/httpclient/model_update_login_flow_body.go +++ b/internal/httpclient/model_update_login_flow_body.go @@ -71,100 +71,158 @@ func UpdateLoginFlowWithWebAuthnMethodAsUpdateLoginFlowBody(v *UpdateLoginFlowWi // Unmarshal JSON data into one of the pointers in the struct func (dst *UpdateLoginFlowBody) UnmarshalJSON(data []byte) error { var err error - match := 0 - // try to unmarshal data into UpdateLoginFlowWithCodeMethod - err = newStrictDecoder(data).Decode(&dst.UpdateLoginFlowWithCodeMethod) - if err == nil { - jsonUpdateLoginFlowWithCodeMethod, _ := json.Marshal(dst.UpdateLoginFlowWithCodeMethod) - if string(jsonUpdateLoginFlowWithCodeMethod) == "{}" { // empty struct - dst.UpdateLoginFlowWithCodeMethod = nil + // use discriminator value to speed up the lookup + var jsonDict map[string]interface{} + err = newStrictDecoder(data).Decode(&jsonDict) + if err != nil { + return fmt.Errorf("Failed to unmarshal JSON into map for the discrimintor lookup.") + } + + // check if the discriminator value is 'code' + if jsonDict["method"] == "code" { + // try to unmarshal JSON data into UpdateLoginFlowWithCodeMethod + err = json.Unmarshal(data, &dst.UpdateLoginFlowWithCodeMethod) + if err == nil { + return nil // data stored in dst.UpdateLoginFlowWithCodeMethod, return on the first match } else { - match++ + dst.UpdateLoginFlowWithCodeMethod = nil + return fmt.Errorf("Failed to unmarshal UpdateLoginFlowBody as UpdateLoginFlowWithCodeMethod: %s", err.Error()) } - } else { - dst.UpdateLoginFlowWithCodeMethod = nil } - // try to unmarshal data into UpdateLoginFlowWithLookupSecretMethod - err = newStrictDecoder(data).Decode(&dst.UpdateLoginFlowWithLookupSecretMethod) - if err == nil { - jsonUpdateLoginFlowWithLookupSecretMethod, _ := json.Marshal(dst.UpdateLoginFlowWithLookupSecretMethod) - if string(jsonUpdateLoginFlowWithLookupSecretMethod) == "{}" { // empty struct - dst.UpdateLoginFlowWithLookupSecretMethod = nil + // check if the discriminator value is 'lookup_secret' + if jsonDict["method"] == "lookup_secret" { + // try to unmarshal JSON data into UpdateLoginFlowWithLookupSecretMethod + err = json.Unmarshal(data, &dst.UpdateLoginFlowWithLookupSecretMethod) + if err == nil { + return nil // data stored in dst.UpdateLoginFlowWithLookupSecretMethod, return on the first match } else { - match++ + dst.UpdateLoginFlowWithLookupSecretMethod = nil + return fmt.Errorf("Failed to unmarshal UpdateLoginFlowBody as UpdateLoginFlowWithLookupSecretMethod: %s", err.Error()) } - } else { - dst.UpdateLoginFlowWithLookupSecretMethod = nil } - // try to unmarshal data into UpdateLoginFlowWithOidcMethod - err = newStrictDecoder(data).Decode(&dst.UpdateLoginFlowWithOidcMethod) - if err == nil { - jsonUpdateLoginFlowWithOidcMethod, _ := json.Marshal(dst.UpdateLoginFlowWithOidcMethod) - if string(jsonUpdateLoginFlowWithOidcMethod) == "{}" { // empty struct - dst.UpdateLoginFlowWithOidcMethod = nil + // check if the discriminator value is 'oidc' + if jsonDict["method"] == "oidc" { + // try to unmarshal JSON data into UpdateLoginFlowWithOidcMethod + err = json.Unmarshal(data, &dst.UpdateLoginFlowWithOidcMethod) + if err == nil { + return nil // data stored in dst.UpdateLoginFlowWithOidcMethod, return on the first match } else { - match++ + dst.UpdateLoginFlowWithOidcMethod = nil + return fmt.Errorf("Failed to unmarshal UpdateLoginFlowBody as UpdateLoginFlowWithOidcMethod: %s", err.Error()) } - } else { - dst.UpdateLoginFlowWithOidcMethod = nil } - // try to unmarshal data into UpdateLoginFlowWithPasswordMethod - err = newStrictDecoder(data).Decode(&dst.UpdateLoginFlowWithPasswordMethod) - if err == nil { - jsonUpdateLoginFlowWithPasswordMethod, _ := json.Marshal(dst.UpdateLoginFlowWithPasswordMethod) - if string(jsonUpdateLoginFlowWithPasswordMethod) == "{}" { // empty struct - dst.UpdateLoginFlowWithPasswordMethod = nil + // check if the discriminator value is 'password' + if jsonDict["method"] == "password" { + // try to unmarshal JSON data into UpdateLoginFlowWithPasswordMethod + err = json.Unmarshal(data, &dst.UpdateLoginFlowWithPasswordMethod) + if err == nil { + return nil // data stored in dst.UpdateLoginFlowWithPasswordMethod, return on the first match } else { - match++ + dst.UpdateLoginFlowWithPasswordMethod = nil + return fmt.Errorf("Failed to unmarshal UpdateLoginFlowBody as UpdateLoginFlowWithPasswordMethod: %s", err.Error()) } - } else { - dst.UpdateLoginFlowWithPasswordMethod = nil } - // try to unmarshal data into UpdateLoginFlowWithTotpMethod - err = newStrictDecoder(data).Decode(&dst.UpdateLoginFlowWithTotpMethod) - if err == nil { - jsonUpdateLoginFlowWithTotpMethod, _ := json.Marshal(dst.UpdateLoginFlowWithTotpMethod) - if string(jsonUpdateLoginFlowWithTotpMethod) == "{}" { // empty struct - dst.UpdateLoginFlowWithTotpMethod = nil + // check if the discriminator value is 'totp' + if jsonDict["method"] == "totp" { + // try to unmarshal JSON data into UpdateLoginFlowWithTotpMethod + err = json.Unmarshal(data, &dst.UpdateLoginFlowWithTotpMethod) + if err == nil { + return nil // data stored in dst.UpdateLoginFlowWithTotpMethod, return on the first match } else { - match++ + dst.UpdateLoginFlowWithTotpMethod = nil + return fmt.Errorf("Failed to unmarshal UpdateLoginFlowBody as UpdateLoginFlowWithTotpMethod: %s", err.Error()) } - } else { - dst.UpdateLoginFlowWithTotpMethod = nil } - // try to unmarshal data into UpdateLoginFlowWithWebAuthnMethod - err = newStrictDecoder(data).Decode(&dst.UpdateLoginFlowWithWebAuthnMethod) - if err == nil { - jsonUpdateLoginFlowWithWebAuthnMethod, _ := json.Marshal(dst.UpdateLoginFlowWithWebAuthnMethod) - if string(jsonUpdateLoginFlowWithWebAuthnMethod) == "{}" { // empty struct + // check if the discriminator value is 'webauthn' + if jsonDict["method"] == "webauthn" { + // try to unmarshal JSON data into UpdateLoginFlowWithWebAuthnMethod + err = json.Unmarshal(data, &dst.UpdateLoginFlowWithWebAuthnMethod) + if err == nil { + return nil // data stored in dst.UpdateLoginFlowWithWebAuthnMethod, return on the first match + } else { dst.UpdateLoginFlowWithWebAuthnMethod = nil + return fmt.Errorf("Failed to unmarshal UpdateLoginFlowBody as UpdateLoginFlowWithWebAuthnMethod: %s", err.Error()) + } + } + + // check if the discriminator value is 'updateLoginFlowWithCodeMethod' + if jsonDict["method"] == "updateLoginFlowWithCodeMethod" { + // try to unmarshal JSON data into UpdateLoginFlowWithCodeMethod + err = json.Unmarshal(data, &dst.UpdateLoginFlowWithCodeMethod) + if err == nil { + return nil // data stored in dst.UpdateLoginFlowWithCodeMethod, return on the first match } else { - match++ + dst.UpdateLoginFlowWithCodeMethod = nil + return fmt.Errorf("Failed to unmarshal UpdateLoginFlowBody as UpdateLoginFlowWithCodeMethod: %s", err.Error()) } - } else { - dst.UpdateLoginFlowWithWebAuthnMethod = nil } - if match > 1 { // more than 1 match - // reset to nil - dst.UpdateLoginFlowWithCodeMethod = nil - dst.UpdateLoginFlowWithLookupSecretMethod = nil - dst.UpdateLoginFlowWithOidcMethod = nil - dst.UpdateLoginFlowWithPasswordMethod = nil - dst.UpdateLoginFlowWithTotpMethod = nil - dst.UpdateLoginFlowWithWebAuthnMethod = nil + // check if the discriminator value is 'updateLoginFlowWithLookupSecretMethod' + if jsonDict["method"] == "updateLoginFlowWithLookupSecretMethod" { + // try to unmarshal JSON data into UpdateLoginFlowWithLookupSecretMethod + err = json.Unmarshal(data, &dst.UpdateLoginFlowWithLookupSecretMethod) + if err == nil { + return nil // data stored in dst.UpdateLoginFlowWithLookupSecretMethod, return on the first match + } else { + dst.UpdateLoginFlowWithLookupSecretMethod = nil + return fmt.Errorf("Failed to unmarshal UpdateLoginFlowBody as UpdateLoginFlowWithLookupSecretMethod: %s", err.Error()) + } + } - return fmt.Errorf("Data matches more than one schema in oneOf(UpdateLoginFlowBody)") - } else if match == 1 { - return nil // exactly one match - } else { // no match - return fmt.Errorf("Data failed to match schemas in oneOf(UpdateLoginFlowBody)") + // check if the discriminator value is 'updateLoginFlowWithOidcMethod' + if jsonDict["method"] == "updateLoginFlowWithOidcMethod" { + // try to unmarshal JSON data into UpdateLoginFlowWithOidcMethod + err = json.Unmarshal(data, &dst.UpdateLoginFlowWithOidcMethod) + if err == nil { + return nil // data stored in dst.UpdateLoginFlowWithOidcMethod, return on the first match + } else { + dst.UpdateLoginFlowWithOidcMethod = nil + return fmt.Errorf("Failed to unmarshal UpdateLoginFlowBody as UpdateLoginFlowWithOidcMethod: %s", err.Error()) + } + } + + // check if the discriminator value is 'updateLoginFlowWithPasswordMethod' + if jsonDict["method"] == "updateLoginFlowWithPasswordMethod" { + // try to unmarshal JSON data into UpdateLoginFlowWithPasswordMethod + err = json.Unmarshal(data, &dst.UpdateLoginFlowWithPasswordMethod) + if err == nil { + return nil // data stored in dst.UpdateLoginFlowWithPasswordMethod, return on the first match + } else { + dst.UpdateLoginFlowWithPasswordMethod = nil + return fmt.Errorf("Failed to unmarshal UpdateLoginFlowBody as UpdateLoginFlowWithPasswordMethod: %s", err.Error()) + } + } + + // check if the discriminator value is 'updateLoginFlowWithTotpMethod' + if jsonDict["method"] == "updateLoginFlowWithTotpMethod" { + // try to unmarshal JSON data into UpdateLoginFlowWithTotpMethod + err = json.Unmarshal(data, &dst.UpdateLoginFlowWithTotpMethod) + if err == nil { + return nil // data stored in dst.UpdateLoginFlowWithTotpMethod, return on the first match + } else { + dst.UpdateLoginFlowWithTotpMethod = nil + return fmt.Errorf("Failed to unmarshal UpdateLoginFlowBody as UpdateLoginFlowWithTotpMethod: %s", err.Error()) + } + } + + // check if the discriminator value is 'updateLoginFlowWithWebAuthnMethod' + if jsonDict["method"] == "updateLoginFlowWithWebAuthnMethod" { + // try to unmarshal JSON data into UpdateLoginFlowWithWebAuthnMethod + err = json.Unmarshal(data, &dst.UpdateLoginFlowWithWebAuthnMethod) + if err == nil { + return nil // data stored in dst.UpdateLoginFlowWithWebAuthnMethod, return on the first match + } else { + dst.UpdateLoginFlowWithWebAuthnMethod = nil + return fmt.Errorf("Failed to unmarshal UpdateLoginFlowBody as UpdateLoginFlowWithWebAuthnMethod: %s", err.Error()) + } } + + return nil } // Marshal data from the first non-nil pointers in the struct to JSON diff --git a/internal/httpclient/model_update_recovery_flow_body.go b/internal/httpclient/model_update_recovery_flow_body.go index 6eea1d5d6b6a..b0f6de861b4f 100644 --- a/internal/httpclient/model_update_recovery_flow_body.go +++ b/internal/httpclient/model_update_recovery_flow_body.go @@ -39,44 +39,62 @@ func UpdateRecoveryFlowWithLinkMethodAsUpdateRecoveryFlowBody(v *UpdateRecoveryF // Unmarshal JSON data into one of the pointers in the struct func (dst *UpdateRecoveryFlowBody) UnmarshalJSON(data []byte) error { var err error - match := 0 - // try to unmarshal data into UpdateRecoveryFlowWithCodeMethod - err = newStrictDecoder(data).Decode(&dst.UpdateRecoveryFlowWithCodeMethod) - if err == nil { - jsonUpdateRecoveryFlowWithCodeMethod, _ := json.Marshal(dst.UpdateRecoveryFlowWithCodeMethod) - if string(jsonUpdateRecoveryFlowWithCodeMethod) == "{}" { // empty struct - dst.UpdateRecoveryFlowWithCodeMethod = nil + // use discriminator value to speed up the lookup + var jsonDict map[string]interface{} + err = newStrictDecoder(data).Decode(&jsonDict) + if err != nil { + return fmt.Errorf("Failed to unmarshal JSON into map for the discrimintor lookup.") + } + + // check if the discriminator value is 'code' + if jsonDict["method"] == "code" { + // try to unmarshal JSON data into UpdateRecoveryFlowWithCodeMethod + err = json.Unmarshal(data, &dst.UpdateRecoveryFlowWithCodeMethod) + if err == nil { + return nil // data stored in dst.UpdateRecoveryFlowWithCodeMethod, return on the first match } else { - match++ + dst.UpdateRecoveryFlowWithCodeMethod = nil + return fmt.Errorf("Failed to unmarshal UpdateRecoveryFlowBody as UpdateRecoveryFlowWithCodeMethod: %s", err.Error()) } - } else { - dst.UpdateRecoveryFlowWithCodeMethod = nil } - // try to unmarshal data into UpdateRecoveryFlowWithLinkMethod - err = newStrictDecoder(data).Decode(&dst.UpdateRecoveryFlowWithLinkMethod) - if err == nil { - jsonUpdateRecoveryFlowWithLinkMethod, _ := json.Marshal(dst.UpdateRecoveryFlowWithLinkMethod) - if string(jsonUpdateRecoveryFlowWithLinkMethod) == "{}" { // empty struct - dst.UpdateRecoveryFlowWithLinkMethod = nil + // check if the discriminator value is 'link' + if jsonDict["method"] == "link" { + // try to unmarshal JSON data into UpdateRecoveryFlowWithLinkMethod + err = json.Unmarshal(data, &dst.UpdateRecoveryFlowWithLinkMethod) + if err == nil { + return nil // data stored in dst.UpdateRecoveryFlowWithLinkMethod, return on the first match } else { - match++ + dst.UpdateRecoveryFlowWithLinkMethod = nil + return fmt.Errorf("Failed to unmarshal UpdateRecoveryFlowBody as UpdateRecoveryFlowWithLinkMethod: %s", err.Error()) } - } else { - dst.UpdateRecoveryFlowWithLinkMethod = nil } - if match > 1 { // more than 1 match - // reset to nil - dst.UpdateRecoveryFlowWithCodeMethod = nil - dst.UpdateRecoveryFlowWithLinkMethod = nil + // check if the discriminator value is 'updateRecoveryFlowWithCodeMethod' + if jsonDict["method"] == "updateRecoveryFlowWithCodeMethod" { + // try to unmarshal JSON data into UpdateRecoveryFlowWithCodeMethod + err = json.Unmarshal(data, &dst.UpdateRecoveryFlowWithCodeMethod) + if err == nil { + return nil // data stored in dst.UpdateRecoveryFlowWithCodeMethod, return on the first match + } else { + dst.UpdateRecoveryFlowWithCodeMethod = nil + return fmt.Errorf("Failed to unmarshal UpdateRecoveryFlowBody as UpdateRecoveryFlowWithCodeMethod: %s", err.Error()) + } + } - return fmt.Errorf("Data matches more than one schema in oneOf(UpdateRecoveryFlowBody)") - } else if match == 1 { - return nil // exactly one match - } else { // no match - return fmt.Errorf("Data failed to match schemas in oneOf(UpdateRecoveryFlowBody)") + // check if the discriminator value is 'updateRecoveryFlowWithLinkMethod' + if jsonDict["method"] == "updateRecoveryFlowWithLinkMethod" { + // try to unmarshal JSON data into UpdateRecoveryFlowWithLinkMethod + err = json.Unmarshal(data, &dst.UpdateRecoveryFlowWithLinkMethod) + if err == nil { + return nil // data stored in dst.UpdateRecoveryFlowWithLinkMethod, return on the first match + } else { + dst.UpdateRecoveryFlowWithLinkMethod = nil + return fmt.Errorf("Failed to unmarshal UpdateRecoveryFlowBody as UpdateRecoveryFlowWithLinkMethod: %s", err.Error()) + } } + + return nil } // Marshal data from the first non-nil pointers in the struct to JSON diff --git a/internal/httpclient/model_update_registration_flow_body.go b/internal/httpclient/model_update_registration_flow_body.go index 0e36a95f635f..7272ea1ace1a 100644 --- a/internal/httpclient/model_update_registration_flow_body.go +++ b/internal/httpclient/model_update_registration_flow_body.go @@ -55,72 +55,110 @@ func UpdateRegistrationFlowWithWebAuthnMethodAsUpdateRegistrationFlowBody(v *Upd // Unmarshal JSON data into one of the pointers in the struct func (dst *UpdateRegistrationFlowBody) UnmarshalJSON(data []byte) error { var err error - match := 0 - // try to unmarshal data into UpdateRegistrationFlowWithCodeMethod - err = newStrictDecoder(data).Decode(&dst.UpdateRegistrationFlowWithCodeMethod) - if err == nil { - jsonUpdateRegistrationFlowWithCodeMethod, _ := json.Marshal(dst.UpdateRegistrationFlowWithCodeMethod) - if string(jsonUpdateRegistrationFlowWithCodeMethod) == "{}" { // empty struct - dst.UpdateRegistrationFlowWithCodeMethod = nil + // use discriminator value to speed up the lookup + var jsonDict map[string]interface{} + err = newStrictDecoder(data).Decode(&jsonDict) + if err != nil { + return fmt.Errorf("Failed to unmarshal JSON into map for the discrimintor lookup.") + } + + // check if the discriminator value is 'code' + if jsonDict["method"] == "code" { + // try to unmarshal JSON data into UpdateRegistrationFlowWithCodeMethod + err = json.Unmarshal(data, &dst.UpdateRegistrationFlowWithCodeMethod) + if err == nil { + return nil // data stored in dst.UpdateRegistrationFlowWithCodeMethod, return on the first match } else { - match++ + dst.UpdateRegistrationFlowWithCodeMethod = nil + return fmt.Errorf("Failed to unmarshal UpdateRegistrationFlowBody as UpdateRegistrationFlowWithCodeMethod: %s", err.Error()) } - } else { - dst.UpdateRegistrationFlowWithCodeMethod = nil } - // try to unmarshal data into UpdateRegistrationFlowWithOidcMethod - err = newStrictDecoder(data).Decode(&dst.UpdateRegistrationFlowWithOidcMethod) - if err == nil { - jsonUpdateRegistrationFlowWithOidcMethod, _ := json.Marshal(dst.UpdateRegistrationFlowWithOidcMethod) - if string(jsonUpdateRegistrationFlowWithOidcMethod) == "{}" { // empty struct - dst.UpdateRegistrationFlowWithOidcMethod = nil + // check if the discriminator value is 'oidc' + if jsonDict["method"] == "oidc" { + // try to unmarshal JSON data into UpdateRegistrationFlowWithOidcMethod + err = json.Unmarshal(data, &dst.UpdateRegistrationFlowWithOidcMethod) + if err == nil { + return nil // data stored in dst.UpdateRegistrationFlowWithOidcMethod, return on the first match } else { - match++ + dst.UpdateRegistrationFlowWithOidcMethod = nil + return fmt.Errorf("Failed to unmarshal UpdateRegistrationFlowBody as UpdateRegistrationFlowWithOidcMethod: %s", err.Error()) } - } else { - dst.UpdateRegistrationFlowWithOidcMethod = nil } - // try to unmarshal data into UpdateRegistrationFlowWithPasswordMethod - err = newStrictDecoder(data).Decode(&dst.UpdateRegistrationFlowWithPasswordMethod) - if err == nil { - jsonUpdateRegistrationFlowWithPasswordMethod, _ := json.Marshal(dst.UpdateRegistrationFlowWithPasswordMethod) - if string(jsonUpdateRegistrationFlowWithPasswordMethod) == "{}" { // empty struct - dst.UpdateRegistrationFlowWithPasswordMethod = nil + // check if the discriminator value is 'password' + if jsonDict["method"] == "password" { + // try to unmarshal JSON data into UpdateRegistrationFlowWithPasswordMethod + err = json.Unmarshal(data, &dst.UpdateRegistrationFlowWithPasswordMethod) + if err == nil { + return nil // data stored in dst.UpdateRegistrationFlowWithPasswordMethod, return on the first match } else { - match++ + dst.UpdateRegistrationFlowWithPasswordMethod = nil + return fmt.Errorf("Failed to unmarshal UpdateRegistrationFlowBody as UpdateRegistrationFlowWithPasswordMethod: %s", err.Error()) } - } else { - dst.UpdateRegistrationFlowWithPasswordMethod = nil } - // try to unmarshal data into UpdateRegistrationFlowWithWebAuthnMethod - err = newStrictDecoder(data).Decode(&dst.UpdateRegistrationFlowWithWebAuthnMethod) - if err == nil { - jsonUpdateRegistrationFlowWithWebAuthnMethod, _ := json.Marshal(dst.UpdateRegistrationFlowWithWebAuthnMethod) - if string(jsonUpdateRegistrationFlowWithWebAuthnMethod) == "{}" { // empty struct + // check if the discriminator value is 'webauthn' + if jsonDict["method"] == "webauthn" { + // try to unmarshal JSON data into UpdateRegistrationFlowWithWebAuthnMethod + err = json.Unmarshal(data, &dst.UpdateRegistrationFlowWithWebAuthnMethod) + if err == nil { + return nil // data stored in dst.UpdateRegistrationFlowWithWebAuthnMethod, return on the first match + } else { dst.UpdateRegistrationFlowWithWebAuthnMethod = nil + return fmt.Errorf("Failed to unmarshal UpdateRegistrationFlowBody as UpdateRegistrationFlowWithWebAuthnMethod: %s", err.Error()) + } + } + + // check if the discriminator value is 'updateRegistrationFlowWithCodeMethod' + if jsonDict["method"] == "updateRegistrationFlowWithCodeMethod" { + // try to unmarshal JSON data into UpdateRegistrationFlowWithCodeMethod + err = json.Unmarshal(data, &dst.UpdateRegistrationFlowWithCodeMethod) + if err == nil { + return nil // data stored in dst.UpdateRegistrationFlowWithCodeMethod, return on the first match } else { - match++ + dst.UpdateRegistrationFlowWithCodeMethod = nil + return fmt.Errorf("Failed to unmarshal UpdateRegistrationFlowBody as UpdateRegistrationFlowWithCodeMethod: %s", err.Error()) } - } else { - dst.UpdateRegistrationFlowWithWebAuthnMethod = nil } - if match > 1 { // more than 1 match - // reset to nil - dst.UpdateRegistrationFlowWithCodeMethod = nil - dst.UpdateRegistrationFlowWithOidcMethod = nil - dst.UpdateRegistrationFlowWithPasswordMethod = nil - dst.UpdateRegistrationFlowWithWebAuthnMethod = nil + // check if the discriminator value is 'updateRegistrationFlowWithOidcMethod' + if jsonDict["method"] == "updateRegistrationFlowWithOidcMethod" { + // try to unmarshal JSON data into UpdateRegistrationFlowWithOidcMethod + err = json.Unmarshal(data, &dst.UpdateRegistrationFlowWithOidcMethod) + if err == nil { + return nil // data stored in dst.UpdateRegistrationFlowWithOidcMethod, return on the first match + } else { + dst.UpdateRegistrationFlowWithOidcMethod = nil + return fmt.Errorf("Failed to unmarshal UpdateRegistrationFlowBody as UpdateRegistrationFlowWithOidcMethod: %s", err.Error()) + } + } + + // check if the discriminator value is 'updateRegistrationFlowWithPasswordMethod' + if jsonDict["method"] == "updateRegistrationFlowWithPasswordMethod" { + // try to unmarshal JSON data into UpdateRegistrationFlowWithPasswordMethod + err = json.Unmarshal(data, &dst.UpdateRegistrationFlowWithPasswordMethod) + if err == nil { + return nil // data stored in dst.UpdateRegistrationFlowWithPasswordMethod, return on the first match + } else { + dst.UpdateRegistrationFlowWithPasswordMethod = nil + return fmt.Errorf("Failed to unmarshal UpdateRegistrationFlowBody as UpdateRegistrationFlowWithPasswordMethod: %s", err.Error()) + } + } - return fmt.Errorf("Data matches more than one schema in oneOf(UpdateRegistrationFlowBody)") - } else if match == 1 { - return nil // exactly one match - } else { // no match - return fmt.Errorf("Data failed to match schemas in oneOf(UpdateRegistrationFlowBody)") + // check if the discriminator value is 'updateRegistrationFlowWithWebAuthnMethod' + if jsonDict["method"] == "updateRegistrationFlowWithWebAuthnMethod" { + // try to unmarshal JSON data into UpdateRegistrationFlowWithWebAuthnMethod + err = json.Unmarshal(data, &dst.UpdateRegistrationFlowWithWebAuthnMethod) + if err == nil { + return nil // data stored in dst.UpdateRegistrationFlowWithWebAuthnMethod, return on the first match + } else { + dst.UpdateRegistrationFlowWithWebAuthnMethod = nil + return fmt.Errorf("Failed to unmarshal UpdateRegistrationFlowBody as UpdateRegistrationFlowWithWebAuthnMethod: %s", err.Error()) + } } + + return nil } // Marshal data from the first non-nil pointers in the struct to JSON diff --git a/internal/httpclient/model_update_settings_flow_body.go b/internal/httpclient/model_update_settings_flow_body.go index 064ff9b771dd..e2aec380a586 100644 --- a/internal/httpclient/model_update_settings_flow_body.go +++ b/internal/httpclient/model_update_settings_flow_body.go @@ -71,100 +71,158 @@ func UpdateSettingsFlowWithWebAuthnMethodAsUpdateSettingsFlowBody(v *UpdateSetti // Unmarshal JSON data into one of the pointers in the struct func (dst *UpdateSettingsFlowBody) UnmarshalJSON(data []byte) error { var err error - match := 0 - // try to unmarshal data into UpdateSettingsFlowWithLookupMethod - err = newStrictDecoder(data).Decode(&dst.UpdateSettingsFlowWithLookupMethod) - if err == nil { - jsonUpdateSettingsFlowWithLookupMethod, _ := json.Marshal(dst.UpdateSettingsFlowWithLookupMethod) - if string(jsonUpdateSettingsFlowWithLookupMethod) == "{}" { // empty struct - dst.UpdateSettingsFlowWithLookupMethod = nil + // use discriminator value to speed up the lookup + var jsonDict map[string]interface{} + err = newStrictDecoder(data).Decode(&jsonDict) + if err != nil { + return fmt.Errorf("Failed to unmarshal JSON into map for the discrimintor lookup.") + } + + // check if the discriminator value is 'lookup_secret' + if jsonDict["method"] == "lookup_secret" { + // try to unmarshal JSON data into UpdateSettingsFlowWithLookupMethod + err = json.Unmarshal(data, &dst.UpdateSettingsFlowWithLookupMethod) + if err == nil { + return nil // data stored in dst.UpdateSettingsFlowWithLookupMethod, return on the first match } else { - match++ + dst.UpdateSettingsFlowWithLookupMethod = nil + return fmt.Errorf("Failed to unmarshal UpdateSettingsFlowBody as UpdateSettingsFlowWithLookupMethod: %s", err.Error()) } - } else { - dst.UpdateSettingsFlowWithLookupMethod = nil } - // try to unmarshal data into UpdateSettingsFlowWithOidcMethod - err = newStrictDecoder(data).Decode(&dst.UpdateSettingsFlowWithOidcMethod) - if err == nil { - jsonUpdateSettingsFlowWithOidcMethod, _ := json.Marshal(dst.UpdateSettingsFlowWithOidcMethod) - if string(jsonUpdateSettingsFlowWithOidcMethod) == "{}" { // empty struct - dst.UpdateSettingsFlowWithOidcMethod = nil + // check if the discriminator value is 'oidc' + if jsonDict["method"] == "oidc" { + // try to unmarshal JSON data into UpdateSettingsFlowWithOidcMethod + err = json.Unmarshal(data, &dst.UpdateSettingsFlowWithOidcMethod) + if err == nil { + return nil // data stored in dst.UpdateSettingsFlowWithOidcMethod, return on the first match } else { - match++ + dst.UpdateSettingsFlowWithOidcMethod = nil + return fmt.Errorf("Failed to unmarshal UpdateSettingsFlowBody as UpdateSettingsFlowWithOidcMethod: %s", err.Error()) } - } else { - dst.UpdateSettingsFlowWithOidcMethod = nil } - // try to unmarshal data into UpdateSettingsFlowWithPasswordMethod - err = newStrictDecoder(data).Decode(&dst.UpdateSettingsFlowWithPasswordMethod) - if err == nil { - jsonUpdateSettingsFlowWithPasswordMethod, _ := json.Marshal(dst.UpdateSettingsFlowWithPasswordMethod) - if string(jsonUpdateSettingsFlowWithPasswordMethod) == "{}" { // empty struct - dst.UpdateSettingsFlowWithPasswordMethod = nil + // check if the discriminator value is 'password' + if jsonDict["method"] == "password" { + // try to unmarshal JSON data into UpdateSettingsFlowWithPasswordMethod + err = json.Unmarshal(data, &dst.UpdateSettingsFlowWithPasswordMethod) + if err == nil { + return nil // data stored in dst.UpdateSettingsFlowWithPasswordMethod, return on the first match } else { - match++ + dst.UpdateSettingsFlowWithPasswordMethod = nil + return fmt.Errorf("Failed to unmarshal UpdateSettingsFlowBody as UpdateSettingsFlowWithPasswordMethod: %s", err.Error()) } - } else { - dst.UpdateSettingsFlowWithPasswordMethod = nil } - // try to unmarshal data into UpdateSettingsFlowWithProfileMethod - err = newStrictDecoder(data).Decode(&dst.UpdateSettingsFlowWithProfileMethod) - if err == nil { - jsonUpdateSettingsFlowWithProfileMethod, _ := json.Marshal(dst.UpdateSettingsFlowWithProfileMethod) - if string(jsonUpdateSettingsFlowWithProfileMethod) == "{}" { // empty struct - dst.UpdateSettingsFlowWithProfileMethod = nil + // check if the discriminator value is 'profile' + if jsonDict["method"] == "profile" { + // try to unmarshal JSON data into UpdateSettingsFlowWithProfileMethod + err = json.Unmarshal(data, &dst.UpdateSettingsFlowWithProfileMethod) + if err == nil { + return nil // data stored in dst.UpdateSettingsFlowWithProfileMethod, return on the first match } else { - match++ + dst.UpdateSettingsFlowWithProfileMethod = nil + return fmt.Errorf("Failed to unmarshal UpdateSettingsFlowBody as UpdateSettingsFlowWithProfileMethod: %s", err.Error()) } - } else { - dst.UpdateSettingsFlowWithProfileMethod = nil } - // try to unmarshal data into UpdateSettingsFlowWithTotpMethod - err = newStrictDecoder(data).Decode(&dst.UpdateSettingsFlowWithTotpMethod) - if err == nil { - jsonUpdateSettingsFlowWithTotpMethod, _ := json.Marshal(dst.UpdateSettingsFlowWithTotpMethod) - if string(jsonUpdateSettingsFlowWithTotpMethod) == "{}" { // empty struct - dst.UpdateSettingsFlowWithTotpMethod = nil + // check if the discriminator value is 'totp' + if jsonDict["method"] == "totp" { + // try to unmarshal JSON data into UpdateSettingsFlowWithTotpMethod + err = json.Unmarshal(data, &dst.UpdateSettingsFlowWithTotpMethod) + if err == nil { + return nil // data stored in dst.UpdateSettingsFlowWithTotpMethod, return on the first match } else { - match++ + dst.UpdateSettingsFlowWithTotpMethod = nil + return fmt.Errorf("Failed to unmarshal UpdateSettingsFlowBody as UpdateSettingsFlowWithTotpMethod: %s", err.Error()) } - } else { - dst.UpdateSettingsFlowWithTotpMethod = nil } - // try to unmarshal data into UpdateSettingsFlowWithWebAuthnMethod - err = newStrictDecoder(data).Decode(&dst.UpdateSettingsFlowWithWebAuthnMethod) - if err == nil { - jsonUpdateSettingsFlowWithWebAuthnMethod, _ := json.Marshal(dst.UpdateSettingsFlowWithWebAuthnMethod) - if string(jsonUpdateSettingsFlowWithWebAuthnMethod) == "{}" { // empty struct + // check if the discriminator value is 'webauthn' + if jsonDict["method"] == "webauthn" { + // try to unmarshal JSON data into UpdateSettingsFlowWithWebAuthnMethod + err = json.Unmarshal(data, &dst.UpdateSettingsFlowWithWebAuthnMethod) + if err == nil { + return nil // data stored in dst.UpdateSettingsFlowWithWebAuthnMethod, return on the first match + } else { dst.UpdateSettingsFlowWithWebAuthnMethod = nil + return fmt.Errorf("Failed to unmarshal UpdateSettingsFlowBody as UpdateSettingsFlowWithWebAuthnMethod: %s", err.Error()) + } + } + + // check if the discriminator value is 'updateSettingsFlowWithLookupMethod' + if jsonDict["method"] == "updateSettingsFlowWithLookupMethod" { + // try to unmarshal JSON data into UpdateSettingsFlowWithLookupMethod + err = json.Unmarshal(data, &dst.UpdateSettingsFlowWithLookupMethod) + if err == nil { + return nil // data stored in dst.UpdateSettingsFlowWithLookupMethod, return on the first match } else { - match++ + dst.UpdateSettingsFlowWithLookupMethod = nil + return fmt.Errorf("Failed to unmarshal UpdateSettingsFlowBody as UpdateSettingsFlowWithLookupMethod: %s", err.Error()) } - } else { - dst.UpdateSettingsFlowWithWebAuthnMethod = nil } - if match > 1 { // more than 1 match - // reset to nil - dst.UpdateSettingsFlowWithLookupMethod = nil - dst.UpdateSettingsFlowWithOidcMethod = nil - dst.UpdateSettingsFlowWithPasswordMethod = nil - dst.UpdateSettingsFlowWithProfileMethod = nil - dst.UpdateSettingsFlowWithTotpMethod = nil - dst.UpdateSettingsFlowWithWebAuthnMethod = nil + // check if the discriminator value is 'updateSettingsFlowWithOidcMethod' + if jsonDict["method"] == "updateSettingsFlowWithOidcMethod" { + // try to unmarshal JSON data into UpdateSettingsFlowWithOidcMethod + err = json.Unmarshal(data, &dst.UpdateSettingsFlowWithOidcMethod) + if err == nil { + return nil // data stored in dst.UpdateSettingsFlowWithOidcMethod, return on the first match + } else { + dst.UpdateSettingsFlowWithOidcMethod = nil + return fmt.Errorf("Failed to unmarshal UpdateSettingsFlowBody as UpdateSettingsFlowWithOidcMethod: %s", err.Error()) + } + } - return fmt.Errorf("Data matches more than one schema in oneOf(UpdateSettingsFlowBody)") - } else if match == 1 { - return nil // exactly one match - } else { // no match - return fmt.Errorf("Data failed to match schemas in oneOf(UpdateSettingsFlowBody)") + // check if the discriminator value is 'updateSettingsFlowWithPasswordMethod' + if jsonDict["method"] == "updateSettingsFlowWithPasswordMethod" { + // try to unmarshal JSON data into UpdateSettingsFlowWithPasswordMethod + err = json.Unmarshal(data, &dst.UpdateSettingsFlowWithPasswordMethod) + if err == nil { + return nil // data stored in dst.UpdateSettingsFlowWithPasswordMethod, return on the first match + } else { + dst.UpdateSettingsFlowWithPasswordMethod = nil + return fmt.Errorf("Failed to unmarshal UpdateSettingsFlowBody as UpdateSettingsFlowWithPasswordMethod: %s", err.Error()) + } + } + + // check if the discriminator value is 'updateSettingsFlowWithProfileMethod' + if jsonDict["method"] == "updateSettingsFlowWithProfileMethod" { + // try to unmarshal JSON data into UpdateSettingsFlowWithProfileMethod + err = json.Unmarshal(data, &dst.UpdateSettingsFlowWithProfileMethod) + if err == nil { + return nil // data stored in dst.UpdateSettingsFlowWithProfileMethod, return on the first match + } else { + dst.UpdateSettingsFlowWithProfileMethod = nil + return fmt.Errorf("Failed to unmarshal UpdateSettingsFlowBody as UpdateSettingsFlowWithProfileMethod: %s", err.Error()) + } + } + + // check if the discriminator value is 'updateSettingsFlowWithTotpMethod' + if jsonDict["method"] == "updateSettingsFlowWithTotpMethod" { + // try to unmarshal JSON data into UpdateSettingsFlowWithTotpMethod + err = json.Unmarshal(data, &dst.UpdateSettingsFlowWithTotpMethod) + if err == nil { + return nil // data stored in dst.UpdateSettingsFlowWithTotpMethod, return on the first match + } else { + dst.UpdateSettingsFlowWithTotpMethod = nil + return fmt.Errorf("Failed to unmarshal UpdateSettingsFlowBody as UpdateSettingsFlowWithTotpMethod: %s", err.Error()) + } + } + + // check if the discriminator value is 'updateSettingsFlowWithWebAuthnMethod' + if jsonDict["method"] == "updateSettingsFlowWithWebAuthnMethod" { + // try to unmarshal JSON data into UpdateSettingsFlowWithWebAuthnMethod + err = json.Unmarshal(data, &dst.UpdateSettingsFlowWithWebAuthnMethod) + if err == nil { + return nil // data stored in dst.UpdateSettingsFlowWithWebAuthnMethod, return on the first match + } else { + dst.UpdateSettingsFlowWithWebAuthnMethod = nil + return fmt.Errorf("Failed to unmarshal UpdateSettingsFlowBody as UpdateSettingsFlowWithWebAuthnMethod: %s", err.Error()) + } } + + return nil } // Marshal data from the first non-nil pointers in the struct to JSON diff --git a/internal/httpclient/model_update_verification_flow_body.go b/internal/httpclient/model_update_verification_flow_body.go index f4e995d222c3..9065bfdbc58e 100644 --- a/internal/httpclient/model_update_verification_flow_body.go +++ b/internal/httpclient/model_update_verification_flow_body.go @@ -39,44 +39,62 @@ func UpdateVerificationFlowWithLinkMethodAsUpdateVerificationFlowBody(v *UpdateV // Unmarshal JSON data into one of the pointers in the struct func (dst *UpdateVerificationFlowBody) UnmarshalJSON(data []byte) error { var err error - match := 0 - // try to unmarshal data into UpdateVerificationFlowWithCodeMethod - err = newStrictDecoder(data).Decode(&dst.UpdateVerificationFlowWithCodeMethod) - if err == nil { - jsonUpdateVerificationFlowWithCodeMethod, _ := json.Marshal(dst.UpdateVerificationFlowWithCodeMethod) - if string(jsonUpdateVerificationFlowWithCodeMethod) == "{}" { // empty struct - dst.UpdateVerificationFlowWithCodeMethod = nil + // use discriminator value to speed up the lookup + var jsonDict map[string]interface{} + err = newStrictDecoder(data).Decode(&jsonDict) + if err != nil { + return fmt.Errorf("Failed to unmarshal JSON into map for the discrimintor lookup.") + } + + // check if the discriminator value is 'code' + if jsonDict["method"] == "code" { + // try to unmarshal JSON data into UpdateVerificationFlowWithCodeMethod + err = json.Unmarshal(data, &dst.UpdateVerificationFlowWithCodeMethod) + if err == nil { + return nil // data stored in dst.UpdateVerificationFlowWithCodeMethod, return on the first match } else { - match++ + dst.UpdateVerificationFlowWithCodeMethod = nil + return fmt.Errorf("Failed to unmarshal UpdateVerificationFlowBody as UpdateVerificationFlowWithCodeMethod: %s", err.Error()) } - } else { - dst.UpdateVerificationFlowWithCodeMethod = nil } - // try to unmarshal data into UpdateVerificationFlowWithLinkMethod - err = newStrictDecoder(data).Decode(&dst.UpdateVerificationFlowWithLinkMethod) - if err == nil { - jsonUpdateVerificationFlowWithLinkMethod, _ := json.Marshal(dst.UpdateVerificationFlowWithLinkMethod) - if string(jsonUpdateVerificationFlowWithLinkMethod) == "{}" { // empty struct - dst.UpdateVerificationFlowWithLinkMethod = nil + // check if the discriminator value is 'link' + if jsonDict["method"] == "link" { + // try to unmarshal JSON data into UpdateVerificationFlowWithLinkMethod + err = json.Unmarshal(data, &dst.UpdateVerificationFlowWithLinkMethod) + if err == nil { + return nil // data stored in dst.UpdateVerificationFlowWithLinkMethod, return on the first match } else { - match++ + dst.UpdateVerificationFlowWithLinkMethod = nil + return fmt.Errorf("Failed to unmarshal UpdateVerificationFlowBody as UpdateVerificationFlowWithLinkMethod: %s", err.Error()) } - } else { - dst.UpdateVerificationFlowWithLinkMethod = nil } - if match > 1 { // more than 1 match - // reset to nil - dst.UpdateVerificationFlowWithCodeMethod = nil - dst.UpdateVerificationFlowWithLinkMethod = nil + // check if the discriminator value is 'updateVerificationFlowWithCodeMethod' + if jsonDict["method"] == "updateVerificationFlowWithCodeMethod" { + // try to unmarshal JSON data into UpdateVerificationFlowWithCodeMethod + err = json.Unmarshal(data, &dst.UpdateVerificationFlowWithCodeMethod) + if err == nil { + return nil // data stored in dst.UpdateVerificationFlowWithCodeMethod, return on the first match + } else { + dst.UpdateVerificationFlowWithCodeMethod = nil + return fmt.Errorf("Failed to unmarshal UpdateVerificationFlowBody as UpdateVerificationFlowWithCodeMethod: %s", err.Error()) + } + } - return fmt.Errorf("Data matches more than one schema in oneOf(UpdateVerificationFlowBody)") - } else if match == 1 { - return nil // exactly one match - } else { // no match - return fmt.Errorf("Data failed to match schemas in oneOf(UpdateVerificationFlowBody)") + // check if the discriminator value is 'updateVerificationFlowWithLinkMethod' + if jsonDict["method"] == "updateVerificationFlowWithLinkMethod" { + // try to unmarshal JSON data into UpdateVerificationFlowWithLinkMethod + err = json.Unmarshal(data, &dst.UpdateVerificationFlowWithLinkMethod) + if err == nil { + return nil // data stored in dst.UpdateVerificationFlowWithLinkMethod, return on the first match + } else { + dst.UpdateVerificationFlowWithLinkMethod = nil + return fmt.Errorf("Failed to unmarshal UpdateVerificationFlowBody as UpdateVerificationFlowWithLinkMethod: %s", err.Error()) + } } + + return nil } // Marshal data from the first non-nil pointers in the struct to JSON diff --git a/spec/api.json b/spec/api.json index 4a35eaeb87bc..93437704b045 100644 --- a/spec/api.json +++ b/spec/api.json @@ -2213,8 +2213,16 @@ "type": "string" }, "node_type": { - "description": "NodeType represents this node's types. It is a mirror of `node.type` and\nis primarily used to allow compatibility with OpenAPI 3.0. In this struct it technically always is \"a\".", - "type": "string" + "description": "NodeType represents this node's types. It is a mirror of `node.type` and\nis primarily used to allow compatibility with OpenAPI 3.0. In this struct it technically always is \"a\".\ntext Text\ninput Input\nimg Image\na Anchor\nscript Script", + "enum": [ + "text", + "input", + "img", + "a", + "script" + ], + "type": "string", + "x-go-enum-desc": "text Text\ninput Input\nimg Image\na Anchor\nscript Script" }, "title": { "$ref": "#/components/schemas/uiText" @@ -2271,8 +2279,16 @@ "type": "string" }, "node_type": { - "description": "NodeType represents this node's types. It is a mirror of `node.type` and\nis primarily used to allow compatibility with OpenAPI 3.0. In this struct it technically always is \"img\".", - "type": "string" + "description": "NodeType represents this node's types. It is a mirror of `node.type` and\nis primarily used to allow compatibility with OpenAPI 3.0. In this struct it technically always is \"img\".\ntext Text\ninput Input\nimg Image\na Anchor\nscript Script", + "enum": [ + "text", + "input", + "img", + "a", + "script" + ], + "type": "string", + "x-go-enum-desc": "text Text\ninput Input\nimg Image\na Anchor\nscript Script" }, "src": { "description": "The image's source URL.\n\nformat: uri", @@ -2322,8 +2338,16 @@ "type": "string" }, "node_type": { - "description": "NodeType represents this node's types. It is a mirror of `node.type` and\nis primarily used to allow compatibility with OpenAPI 3.0. In this struct it technically always is \"input\".", - "type": "string" + "description": "NodeType represents this node's types. It is a mirror of `node.type` and\nis primarily used to allow compatibility with OpenAPI 3.0. In this struct it technically always is \"input\".\ntext Text\ninput Input\nimg Image\na Anchor\nscript Script", + "enum": [ + "text", + "input", + "img", + "a", + "script" + ], + "type": "string", + "x-go-enum-desc": "text Text\ninput Input\nimg Image\na Anchor\nscript Script" }, "onclick": { "description": "OnClick may contain javascript which should be executed on click. This is primarily\nused for WebAuthn.", @@ -2402,8 +2426,16 @@ "type": "string" }, "node_type": { - "description": "NodeType represents this node's types. It is a mirror of `node.type` and\nis primarily used to allow compatibility with OpenAPI 3.0. In this struct it technically always is \"script\".", - "type": "string" + "description": "NodeType represents this node's types. It is a mirror of `node.type` and\nis primarily used to allow compatibility with OpenAPI 3.0. In this struct it technically always is \"script\".\ntext Text\ninput Input\nimg Image\na Anchor\nscript Script", + "enum": [ + "text", + "input", + "img", + "a", + "script" + ], + "type": "string", + "x-go-enum-desc": "text Text\ninput Input\nimg Image\na Anchor\nscript Script" }, "nonce": { "description": "Nonce for CSP\n\nA nonce you may want to use to improve your Content Security Policy.\nYou do not have to use this value but if you want to improve your CSP\npolicies you may use it. You can also choose to use your own nonce value!", @@ -2443,8 +2475,16 @@ "type": "string" }, "node_type": { - "description": "NodeType represents this node's types. It is a mirror of `node.type` and\nis primarily used to allow compatibility with OpenAPI 3.0. In this struct it technically always is \"text\".", - "type": "string" + "description": "NodeType represents this node's types. It is a mirror of `node.type` and\nis primarily used to allow compatibility with OpenAPI 3.0. In this struct it technically always is \"text\".\ntext Text\ninput Input\nimg Image\na Anchor\nscript Script", + "enum": [ + "text", + "input", + "img", + "a", + "script" + ], + "type": "string", + "x-go-enum-desc": "text Text\ninput Input\nimg Image\na Anchor\nscript Script" }, "text": { "$ref": "#/components/schemas/uiText" diff --git a/spec/swagger.json b/spec/swagger.json index 4621ef4fbfca..f28bc3023c56 100755 --- a/spec/swagger.json +++ b/spec/swagger.json @@ -5316,8 +5316,16 @@ "type": "string" }, "node_type": { - "description": "NodeType represents this node's types. It is a mirror of `node.type` and\nis primarily used to allow compatibility with OpenAPI 3.0. In this struct it technically always is \"a\".", - "type": "string" + "description": "NodeType represents this node's types. It is a mirror of `node.type` and\nis primarily used to allow compatibility with OpenAPI 3.0. In this struct it technically always is \"a\".\ntext Text\ninput Input\nimg Image\na Anchor\nscript Script", + "type": "string", + "enum": [ + "text", + "input", + "img", + "a", + "script" + ], + "x-go-enum-desc": "text Text\ninput Input\nimg Image\na Anchor\nscript Script" }, "title": { "$ref": "#/definitions/uiText" @@ -5349,8 +5357,16 @@ "type": "string" }, "node_type": { - "description": "NodeType represents this node's types. It is a mirror of `node.type` and\nis primarily used to allow compatibility with OpenAPI 3.0. In this struct it technically always is \"img\".", - "type": "string" + "description": "NodeType represents this node's types. It is a mirror of `node.type` and\nis primarily used to allow compatibility with OpenAPI 3.0. In this struct it technically always is \"img\".\ntext Text\ninput Input\nimg Image\na Anchor\nscript Script", + "type": "string", + "enum": [ + "text", + "input", + "img", + "a", + "script" + ], + "x-go-enum-desc": "text Text\ninput Input\nimg Image\na Anchor\nscript Script" }, "src": { "description": "The image's source URL.\n\nformat: uri", @@ -5398,8 +5414,16 @@ "type": "string" }, "node_type": { - "description": "NodeType represents this node's types. It is a mirror of `node.type` and\nis primarily used to allow compatibility with OpenAPI 3.0. In this struct it technically always is \"input\".", - "type": "string" + "description": "NodeType represents this node's types. It is a mirror of `node.type` and\nis primarily used to allow compatibility with OpenAPI 3.0. In this struct it technically always is \"input\".\ntext Text\ninput Input\nimg Image\na Anchor\nscript Script", + "type": "string", + "enum": [ + "text", + "input", + "img", + "a", + "script" + ], + "x-go-enum-desc": "text Text\ninput Input\nimg Image\na Anchor\nscript Script" }, "onclick": { "description": "OnClick may contain javascript which should be executed on click. This is primarily\nused for WebAuthn.", @@ -5483,8 +5507,16 @@ "type": "string" }, "node_type": { - "description": "NodeType represents this node's types. It is a mirror of `node.type` and\nis primarily used to allow compatibility with OpenAPI 3.0. In this struct it technically always is \"script\".", - "type": "string" + "description": "NodeType represents this node's types. It is a mirror of `node.type` and\nis primarily used to allow compatibility with OpenAPI 3.0. In this struct it technically always is \"script\".\ntext Text\ninput Input\nimg Image\na Anchor\nscript Script", + "type": "string", + "enum": [ + "text", + "input", + "img", + "a", + "script" + ], + "x-go-enum-desc": "text Text\ninput Input\nimg Image\na Anchor\nscript Script" }, "nonce": { "description": "Nonce for CSP\n\nA nonce you may want to use to improve your Content Security Policy.\nYou do not have to use this value but if you want to improve your CSP\npolicies you may use it. You can also choose to use your own nonce value!", @@ -5518,8 +5550,16 @@ "type": "string" }, "node_type": { - "description": "NodeType represents this node's types. It is a mirror of `node.type` and\nis primarily used to allow compatibility with OpenAPI 3.0. In this struct it technically always is \"text\".", - "type": "string" + "description": "NodeType represents this node's types. It is a mirror of `node.type` and\nis primarily used to allow compatibility with OpenAPI 3.0. In this struct it technically always is \"text\".\ntext Text\ninput Input\nimg Image\na Anchor\nscript Script", + "type": "string", + "enum": [ + "text", + "input", + "img", + "a", + "script" + ], + "x-go-enum-desc": "text Text\ninput Input\nimg Image\na Anchor\nscript Script" }, "text": { "$ref": "#/definitions/uiText" diff --git a/ui/node/attributes.go b/ui/node/attributes.go index daf56c9fc675..9611b5828dff 100644 --- a/ui/node/attributes.go +++ b/ui/node/attributes.go @@ -101,7 +101,7 @@ type InputAttributes struct { // is primarily used to allow compatibility with OpenAPI 3.0. In this struct it technically always is "input". // // required: true - NodeType string `json:"node_type"` + NodeType UiNodeType `json:"node_type"` } // ImageAttributes represents the attributes of an image node. @@ -133,7 +133,7 @@ type ImageAttributes struct { // is primarily used to allow compatibility with OpenAPI 3.0. In this struct it technically always is "img". // // required: true - NodeType string `json:"node_type"` + NodeType UiNodeType `json:"node_type"` } // AnchorAttributes represents the attributes of an anchor node. @@ -160,7 +160,7 @@ type AnchorAttributes struct { // is primarily used to allow compatibility with OpenAPI 3.0. In this struct it technically always is "a". // // required: true - NodeType string `json:"node_type"` + NodeType UiNodeType `json:"node_type"` } // TextAttributes represents the attributes of a text node. @@ -181,7 +181,7 @@ type TextAttributes struct { // is primarily used to allow compatibility with OpenAPI 3.0. In this struct it technically always is "text". // // required: true - NodeType string `json:"node_type"` + NodeType UiNodeType `json:"node_type"` } // ScriptAttributes represent script nodes which load javascript. @@ -236,7 +236,7 @@ type ScriptAttributes struct { // is primarily used to allow compatibility with OpenAPI 3.0. In this struct it technically always is "script". // // required: true - NodeType string `json:"node_type"` + NodeType UiNodeType `json:"node_type"` } var ( diff --git a/ui/node/node.go b/ui/node/node.go index c4e9e05519f8..e08295b827f4 100644 --- a/ui/node/node.go +++ b/ui/node/node.go @@ -358,23 +358,23 @@ func (n *Node) UnmarshalJSON(data []byte) error { switch t := gjson.GetBytes(data, "type").String(); UiNodeType(t) { case Text: attr = &TextAttributes{ - NodeType: string(Text), + NodeType: Text, } case Input: attr = &InputAttributes{ - NodeType: string(Input), + NodeType: Input, } case Anchor: attr = &AnchorAttributes{ - NodeType: string(Anchor), + NodeType: Anchor, } case Image: attr = &ImageAttributes{ - NodeType: string(Image), + NodeType: Image, } case Script: attr = &ScriptAttributes{ - NodeType: string(Script), + NodeType: Script, } default: return fmt.Errorf("unexpected node type: %s", t) @@ -401,19 +401,19 @@ func (n *Node) MarshalJSON() ([]byte, error) { switch attr := n.Attributes.(type) { case *TextAttributes: t = Text - attr.NodeType = string(Text) + attr.NodeType = Text case *InputAttributes: t = Input - attr.NodeType = string(Input) + attr.NodeType = Input case *AnchorAttributes: t = Anchor - attr.NodeType = string(Anchor) + attr.NodeType = Anchor case *ImageAttributes: t = Image - attr.NodeType = string(Image) + attr.NodeType = Image case *ScriptAttributes: t = Script - attr.NodeType = string(Script) + attr.NodeType = Script default: return nil, errors.WithStack(fmt.Errorf("unknown node type: %T", n.Attributes)) }