Skip to content

Commit

Permalink
fix: support all oauth2 flows in sdk auth
Browse files Browse the repository at this point in the history
  • Loading branch information
mrlubos committed Jan 21, 2025
1 parent 1b73773 commit 194f941
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 40 deletions.
5 changes: 5 additions & 0 deletions .changeset/rotten-rabbits-bow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@hey-api/openapi-ts': patch
---

fix: support all oauth2 flows in sdk auth
8 changes: 6 additions & 2 deletions packages/openapi-ts/src/plugins/@hey-api/sdk/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,12 @@ const securitySchemeObjectToAuthObject = ({
securitySchemeObject: IR.SecurityObject;
}): Auth | undefined => {
if (securitySchemeObject.type === 'oauth2') {
// TODO: parser - handle more/multiple oauth2 flows
if (securitySchemeObject.flows.password) {
if (
securitySchemeObject.flows.password ||
securitySchemeObject.flows.authorizationCode ||
securitySchemeObject.flows.clientCredentials ||
securitySchemeObject.flows.implicit
) {

Check warning on line 136 in packages/openapi-ts/src/plugins/@hey-api/sdk/plugin.ts

View check run for this annotation

Codecov / codecov/patch

packages/openapi-ts/src/plugins/@hey-api/sdk/plugin.ts#L131-L136

Added lines #L131 - L136 were not covered by tests
return {
scheme: 'bearer',
type: 'http',
Expand Down
4 changes: 2 additions & 2 deletions packages/openapi-ts/test/3.1.x.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ describe(`OpenAPI ${version}`, () => {
},
{
config: createConfig({
input: 'security-oauth2.json',
input: 'security-oauth2.yaml',
output: 'security-oauth2',
plugins: [
{
Expand All @@ -535,7 +535,7 @@ describe(`OpenAPI ${version}`, () => {
},
{
config: createConfig({
input: 'security-oauth2.json',
input: 'security-oauth2.yaml',
output: 'security-false',
plugins: [
{
Expand Down
36 changes: 0 additions & 36 deletions packages/openapi-ts/test/spec/3.1.x/security-oauth2.json

This file was deleted.

20 changes: 20 additions & 0 deletions packages/openapi-ts/test/spec/3.1.x/security-oauth2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
openapi: 3.1.1
info:
title: OpenAPI 3.1.1 security oauth2 example
version: '1'
paths:
/foo:
get:
responses:
'200':
description: OK
security:
- foo: []
components:
securitySchemes:
foo:
flows:
password:
scopes: {}
tokenUrl: '/'
type: 'oauth2'

0 comments on commit 194f941

Please sign in to comment.