Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: support all oauth2 flows in sdk auth #1602

Merged
merged 1 commit into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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'
Loading