From 7bab848ae64cecf4d5b266d4b65dfc0b105484d2 Mon Sep 17 00:00:00 2001 From: Luuk van den Maagdenberg Date: Thu, 18 Nov 2021 11:24:41 +0100 Subject: [PATCH 1/2] "ClientCredentials" was called "application" in OpenAPI v2 so this needs to be converted. Specification: https://swagger.io/specification/#oauth-flows-object --- openapi2conv/openapi2_conv.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/openapi2conv/openapi2_conv.go b/openapi2conv/openapi2_conv.go index e9f3164c0..245702622 100644 --- a/openapi2conv/openapi2_conv.go +++ b/openapi2conv/openapi2_conv.go @@ -525,6 +525,8 @@ func ToV3SecurityScheme(securityScheme *openapi2.SecurityScheme) (*openapi3.Secu flows.AuthorizationCode = flow case "password": flows.Password = flow + case "application": + flows.ClientCredentials = flow default: return nil, fmt.Errorf("unsupported flow %q", securityScheme.Flow) } @@ -1076,6 +1078,8 @@ func FromV3SecurityScheme(doc3 *openapi3.T, ref *openapi3.SecuritySchemeRef) (*o result.Flow = "accessCode" } else if flow = flows.Password; flow != nil { result.Flow = "password" + } else if flow = flows.ClientCredentials; flow != nil { + result.Flow = "application" } else { return nil, nil } From 6ce78584c8dbf701153bc6c0e2b4d0f9e5aa2c58 Mon Sep 17 00:00:00 2001 From: Luuk van den Maagdenberg Date: Thu, 18 Nov 2021 16:23:31 +0100 Subject: [PATCH 2/2] Test for PR 449 --- openapi2conv/issue187_test.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/openapi2conv/issue187_test.go b/openapi2conv/issue187_test.go index 7ca85cace..1c113b708 100644 --- a/openapi2conv/issue187_test.go +++ b/openapi2conv/issue187_test.go @@ -167,3 +167,27 @@ paths: err = doc3.Validate(context.Background()) require.NoError(t, err) } + +func TestPR449(t *testing.T) { + spec := ` +swagger: '2.0' +info: + version: 1.0.0 + title: title + +securityDefinitions: + OAuth2Application: + type: "oauth2" + flow: "application" + tokenUrl: "example.com/oauth2/token" +` + doc3, err := v2v3YAML([]byte(spec)) + require.NoError(t, err) + require.NotNil(t, doc3.Components.SecuritySchemes["OAuth2Application"].Value.Flows.ClientCredentials) + _, err = yaml.Marshal(doc3) + require.NoError(t, err) + + doc2, err := FromV3(doc3) + require.NoError(t, err) + require.Equal(t, doc2.SecurityDefinitions["OAuth2Application"].Flow, "application") +}