Skip to content

Commit 41c2da7

Browse files
authored
ClientCredentials conversion to OpenAPI v2 (#449)
1 parent 1cb0303 commit 41c2da7

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

openapi2conv/issue187_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,3 +167,27 @@ paths:
167167
err = doc3.Validate(context.Background())
168168
require.NoError(t, err)
169169
}
170+
171+
func TestPR449(t *testing.T) {
172+
spec := `
173+
swagger: '2.0'
174+
info:
175+
version: 1.0.0
176+
title: title
177+
178+
securityDefinitions:
179+
OAuth2Application:
180+
type: "oauth2"
181+
flow: "application"
182+
tokenUrl: "example.com/oauth2/token"
183+
`
184+
doc3, err := v2v3YAML([]byte(spec))
185+
require.NoError(t, err)
186+
require.NotNil(t, doc3.Components.SecuritySchemes["OAuth2Application"].Value.Flows.ClientCredentials)
187+
_, err = yaml.Marshal(doc3)
188+
require.NoError(t, err)
189+
190+
doc2, err := FromV3(doc3)
191+
require.NoError(t, err)
192+
require.Equal(t, doc2.SecurityDefinitions["OAuth2Application"].Flow, "application")
193+
}

openapi2conv/openapi2_conv.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,8 @@ func ToV3SecurityScheme(securityScheme *openapi2.SecurityScheme) (*openapi3.Secu
525525
flows.AuthorizationCode = flow
526526
case "password":
527527
flows.Password = flow
528+
case "application":
529+
flows.ClientCredentials = flow
528530
default:
529531
return nil, fmt.Errorf("unsupported flow %q", securityScheme.Flow)
530532
}
@@ -1076,6 +1078,8 @@ func FromV3SecurityScheme(doc3 *openapi3.T, ref *openapi3.SecuritySchemeRef) (*o
10761078
result.Flow = "accessCode"
10771079
} else if flow = flows.Password; flow != nil {
10781080
result.Flow = "password"
1081+
} else if flow = flows.ClientCredentials; flow != nil {
1082+
result.Flow = "application"
10791083
} else {
10801084
return nil, nil
10811085
}

0 commit comments

Comments
 (0)