Skip to content

Commit

Permalink
ClientCredentials conversion to OpenAPI v2 (#449)
Browse files Browse the repository at this point in the history
  • Loading branch information
Luukvdm authored Nov 18, 2021
1 parent 1cb0303 commit 41c2da7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
24 changes: 24 additions & 0 deletions openapi2conv/issue187_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
4 changes: 4 additions & 0 deletions openapi2conv/openapi2_conv.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 41c2da7

Please sign in to comment.