fork of hey-api/openapi-ts because I need some additional things
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request #1648 from hey-api/feat/auth-open-id-connect

fix: add support for openIdConnect auth flow

authored by

Lubos and committed by
GitHub
b767e100 3bdc656a

+340 -77
-1
.changeset/orange-bags-hope.md
··· 1 1 --- 2 2 '@hey-api/client-axios': patch 3 3 '@hey-api/client-fetch': patch 4 - '@hey-api/client-next': patch 5 4 '@hey-api/client-nuxt': patch 6 5 --- 7 6
-1
.changeset/tiny-kings-reflect.md
··· 1 1 --- 2 2 '@hey-api/client-axios': patch 3 3 '@hey-api/client-fetch': patch 4 - '@hey-api/client-next': patch 5 4 '@hey-api/client-nuxt': patch 6 5 --- 7 6
+5
.changeset/unlucky-ligers-help.md
··· 1 + --- 2 + '@hey-api/openapi-ts': patch 3 + --- 4 + 5 + fix: add support for openIdConnect auth flow
+10
packages/client-core/src/auth.ts
··· 1 1 export type AuthToken = string | undefined; 2 2 3 3 export interface Auth { 4 + /** 5 + * Which part of the request do we use to send the auth? 6 + * 7 + * @default 'header' 8 + */ 4 9 in?: 'header' | 'query'; 10 + /** 11 + * Header or query parameter name. 12 + * 13 + * @default 'Authorization' 14 + */ 5 15 name?: string; 6 16 scheme?: 'basic' | 'bearer'; 7 17 type: 'apiKey' | 'http';
+19 -2
packages/openapi-ts/src/plugins/@hey-api/sdk/plugin.ts
··· 28 28 import { serviceFunctionIdentifier } from './plugin-legacy'; 29 29 import type { Config } from './types'; 30 30 31 - // type copied from client packages 32 - interface Auth { 31 + // copy-pasted from @hey-api/client-core 32 + export interface Auth { 33 + /** 34 + * Which part of the request do we use to send the auth? 35 + * 36 + * @default 'header' 37 + */ 33 38 in?: 'header' | 'query'; 39 + /** 40 + * Header or query parameter name. 41 + * 42 + * @default 'Authorization' 43 + */ 34 44 name?: string; 35 45 scheme?: 'basic' | 'bearer'; 36 46 type: 'apiKey' | 'http'; ··· 129 139 }: { 130 140 securitySchemeObject: IR.SecurityObject; 131 141 }): Auth | undefined => { 142 + if (securitySchemeObject.type === 'openIdConnect') { 143 + return { 144 + scheme: 'bearer', 145 + type: 'http', 146 + }; 147 + } 148 + 132 149 if (securitySchemeObject.type === 'oauth2') { 133 150 if ( 134 151 securitySchemeObject.flows.password ||
+2 -2
packages/openapi-ts/test/2.0.x.test.ts
··· 247 247 }, 248 248 { 249 249 config: createConfig({ 250 - input: 'security-oauth2.json', 250 + input: 'security-oauth2.yaml', 251 251 output: 'security-oauth2', 252 252 plugins: [ 253 253 '@hey-api/client-fetch', ··· 261 261 }, 262 262 { 263 263 config: createConfig({ 264 - input: 'security-oauth2.json', 264 + input: 'security-oauth2.yaml', 265 265 output: 'security-false', 266 266 plugins: [ 267 267 '@hey-api/client-fetch',
+16 -2
packages/openapi-ts/test/3.0.x.test.ts
··· 448 448 }, 449 449 { 450 450 config: createConfig({ 451 - input: 'security-oauth2.json', 451 + input: 'security-oauth2.yaml', 452 452 output: 'security-oauth2', 453 453 plugins: [ 454 454 '@hey-api/client-fetch', ··· 462 462 }, 463 463 { 464 464 config: createConfig({ 465 - input: 'security-oauth2.json', 465 + input: 'security-open-id-connect.yaml', 466 + output: 'security-open-id-connect', 467 + plugins: [ 468 + '@hey-api/client-fetch', 469 + { 470 + auth: true, 471 + name: '@hey-api/sdk', 472 + }, 473 + ], 474 + }), 475 + description: 'generates SDK functions with auth (OpenID Connect)', 476 + }, 477 + { 478 + config: createConfig({ 479 + input: 'security-oauth2.yaml', 466 480 output: 'security-false', 467 481 plugins: [ 468 482 '@hey-api/client-fetch',
+14
packages/openapi-ts/test/3.1.x.test.ts
··· 539 539 }, 540 540 { 541 541 config: createConfig({ 542 + input: 'security-open-id-connect.yaml', 543 + output: 'security-open-id-connect', 544 + plugins: [ 545 + '@hey-api/client-fetch', 546 + { 547 + auth: true, 548 + name: '@hey-api/sdk', 549 + }, 550 + ], 551 + }), 552 + description: 'generates SDK functions with auth (OpenID Connect)', 553 + }, 554 + { 555 + config: createConfig({ 542 556 input: 'security-oauth2.yaml', 543 557 output: 'security-false', 544 558 plugins: [
+5
packages/openapi-ts/test/__snapshots__/3.0.x/security-open-id-connect/client.gen.ts
··· 1 + // This file is auto-generated by @hey-api/openapi-ts 2 + 3 + import { createClient, createConfig } from '@hey-api/client-fetch'; 4 + 5 + export const client = createClient(createConfig());
+3
packages/openapi-ts/test/__snapshots__/3.0.x/security-open-id-connect/index.ts
··· 1 + // This file is auto-generated by @hey-api/openapi-ts 2 + export * from './types.gen'; 3 + export * from './sdk.gen';
+27
packages/openapi-ts/test/__snapshots__/3.0.x/security-open-id-connect/sdk.gen.ts
··· 1 + // This file is auto-generated by @hey-api/openapi-ts 2 + 3 + import type { Options as ClientOptions, TDataShape, Client } from '@hey-api/client-fetch'; 4 + import type { GetFooData } from './types.gen'; 5 + import { client as _heyApiClient } from './client.gen'; 6 + 7 + export type Options<TData extends TDataShape = TDataShape, ThrowOnError extends boolean = boolean> = ClientOptions<TData, ThrowOnError> & { 8 + /** 9 + * You can provide a client instance returned by `createClient()` instead of 10 + * individual options. This might be also useful if you want to implement a 11 + * custom client. 12 + */ 13 + client?: Client; 14 + }; 15 + 16 + export const getFoo = <ThrowOnError extends boolean = false>(options?: Options<GetFooData, ThrowOnError>) => { 17 + return (options?.client ?? _heyApiClient).get<unknown, unknown, ThrowOnError>({ 18 + security: [ 19 + { 20 + scheme: 'bearer', 21 + type: 'http' 22 + } 23 + ], 24 + url: '/foo', 25 + ...options 26 + }); 27 + };
+15
packages/openapi-ts/test/__snapshots__/3.0.x/security-open-id-connect/types.gen.ts
··· 1 + // This file is auto-generated by @hey-api/openapi-ts 2 + 3 + export type GetFooData = { 4 + body?: never; 5 + path?: never; 6 + query?: never; 7 + url: '/foo'; 8 + }; 9 + 10 + export type GetFooResponses = { 11 + /** 12 + * OK 13 + */ 14 + 200: unknown; 15 + };
+10
packages/openapi-ts/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/bundle/client/index.d.cts
··· 2 2 3 3 type AuthToken = string | undefined; 4 4 interface Auth { 5 + /** 6 + * Which part of the request do we use to send the auth? 7 + * 8 + * @default 'header' 9 + */ 5 10 in?: 'header' | 'query'; 11 + /** 12 + * Header or query parameter name. 13 + * 14 + * @default 'Authorization' 15 + */ 6 16 name?: string; 7 17 scheme?: 'basic' | 'bearer'; 8 18 type: 'apiKey' | 'http';
+10
packages/openapi-ts/test/__snapshots__/3.1.x/clients/@hey-api/client-axios/bundle/client/index.d.ts
··· 2 2 3 3 type AuthToken = string | undefined; 4 4 interface Auth { 5 + /** 6 + * Which part of the request do we use to send the auth? 7 + * 8 + * @default 'header' 9 + */ 5 10 in?: 'header' | 'query'; 11 + /** 12 + * Header or query parameter name. 13 + * 14 + * @default 'Authorization' 15 + */ 6 16 name?: string; 7 17 scheme?: 'basic' | 'bearer'; 8 18 type: 'apiKey' | 'http';
+10
packages/openapi-ts/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/bundle/client/index.d.cts
··· 1 1 type AuthToken = string | undefined; 2 2 interface Auth { 3 + /** 4 + * Which part of the request do we use to send the auth? 5 + * 6 + * @default 'header' 7 + */ 3 8 in?: 'header' | 'query'; 9 + /** 10 + * Header or query parameter name. 11 + * 12 + * @default 'Authorization' 13 + */ 4 14 name?: string; 5 15 scheme?: 'basic' | 'bearer'; 6 16 type: 'apiKey' | 'http';
+10
packages/openapi-ts/test/__snapshots__/3.1.x/clients/@hey-api/client-fetch/bundle/client/index.d.ts
··· 1 1 type AuthToken = string | undefined; 2 2 interface Auth { 3 + /** 4 + * Which part of the request do we use to send the auth? 5 + * 6 + * @default 'header' 7 + */ 3 8 in?: 'header' | 'query'; 9 + /** 10 + * Header or query parameter name. 11 + * 12 + * @default 'Authorization' 13 + */ 4 14 name?: string; 5 15 scheme?: 'basic' | 'bearer'; 6 16 type: 'apiKey' | 'http';
+10
packages/openapi-ts/test/__snapshots__/3.1.x/clients/@hey-api/client-next/bundle/client/index.d.cts
··· 1 1 type AuthToken = string | undefined; 2 2 interface Auth { 3 + /** 4 + * Which part of the request do we use to send the auth? 5 + * 6 + * @default 'header' 7 + */ 3 8 in?: 'header' | 'query'; 9 + /** 10 + * Header or query parameter name. 11 + * 12 + * @default 'Authorization' 13 + */ 4 14 name?: string; 5 15 scheme?: 'basic' | 'bearer'; 6 16 type: 'apiKey' | 'http';
+10
packages/openapi-ts/test/__snapshots__/3.1.x/clients/@hey-api/client-next/bundle/client/index.d.ts
··· 1 1 type AuthToken = string | undefined; 2 2 interface Auth { 3 + /** 4 + * Which part of the request do we use to send the auth? 5 + * 6 + * @default 'header' 7 + */ 3 8 in?: 'header' | 'query'; 9 + /** 10 + * Header or query parameter name. 11 + * 12 + * @default 'Authorization' 13 + */ 4 14 name?: string; 5 15 scheme?: 'basic' | 'bearer'; 6 16 type: 'apiKey' | 'http';
+10
packages/openapi-ts/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/bundle/client/index.d.cts
··· 3 3 4 4 type AuthToken = string | undefined; 5 5 interface Auth { 6 + /** 7 + * Which part of the request do we use to send the auth? 8 + * 9 + * @default 'header' 10 + */ 6 11 in?: 'header' | 'query'; 12 + /** 13 + * Header or query parameter name. 14 + * 15 + * @default 'Authorization' 16 + */ 7 17 name?: string; 8 18 scheme?: 'basic' | 'bearer'; 9 19 type: 'apiKey' | 'http';
+10
packages/openapi-ts/test/__snapshots__/3.1.x/clients/@hey-api/client-nuxt/bundle/client/index.d.ts
··· 3 3 4 4 type AuthToken = string | undefined; 5 5 interface Auth { 6 + /** 7 + * Which part of the request do we use to send the auth? 8 + * 9 + * @default 'header' 10 + */ 6 11 in?: 'header' | 'query'; 12 + /** 13 + * Header or query parameter name. 14 + * 15 + * @default 'Authorization' 16 + */ 7 17 name?: string; 8 18 scheme?: 'basic' | 'bearer'; 9 19 type: 'apiKey' | 'http';
+5
packages/openapi-ts/test/__snapshots__/3.1.x/security-open-id-connect/client.gen.ts
··· 1 + // This file is auto-generated by @hey-api/openapi-ts 2 + 3 + import { createClient, createConfig } from '@hey-api/client-fetch'; 4 + 5 + export const client = createClient(createConfig());
+3
packages/openapi-ts/test/__snapshots__/3.1.x/security-open-id-connect/index.ts
··· 1 + // This file is auto-generated by @hey-api/openapi-ts 2 + export * from './types.gen'; 3 + export * from './sdk.gen';
+27
packages/openapi-ts/test/__snapshots__/3.1.x/security-open-id-connect/sdk.gen.ts
··· 1 + // This file is auto-generated by @hey-api/openapi-ts 2 + 3 + import type { Options as ClientOptions, TDataShape, Client } from '@hey-api/client-fetch'; 4 + import type { GetFooData } from './types.gen'; 5 + import { client as _heyApiClient } from './client.gen'; 6 + 7 + export type Options<TData extends TDataShape = TDataShape, ThrowOnError extends boolean = boolean> = ClientOptions<TData, ThrowOnError> & { 8 + /** 9 + * You can provide a client instance returned by `createClient()` instead of 10 + * individual options. This might be also useful if you want to implement a 11 + * custom client. 12 + */ 13 + client?: Client; 14 + }; 15 + 16 + export const getFoo = <ThrowOnError extends boolean = false>(options?: Options<GetFooData, ThrowOnError>) => { 17 + return (options?.client ?? _heyApiClient).get<unknown, unknown, ThrowOnError>({ 18 + security: [ 19 + { 20 + scheme: 'bearer', 21 + type: 'http' 22 + } 23 + ], 24 + url: '/foo', 25 + ...options 26 + }); 27 + };
+15
packages/openapi-ts/test/__snapshots__/3.1.x/security-open-id-connect/types.gen.ts
··· 1 + // This file is auto-generated by @hey-api/openapi-ts 2 + 3 + export type GetFooData = { 4 + body?: never; 5 + path?: never; 6 + query?: never; 7 + url: '/foo'; 8 + }; 9 + 10 + export type GetFooResponses = { 11 + /** 12 + * OK 13 + */ 14 + 200: unknown; 15 + };
+2 -2
packages/openapi-ts/test/openapi-ts.config.ts
··· 6 6 // exclude: '^#/components/schemas/ModelWithCircularReference$', 7 7 // include: 8 8 // '^(#/components/schemas/import|#/paths/api/v{api-version}/simple/options)$', 9 - path: './packages/openapi-ts/test/spec/3.1.x/full.json', 9 + path: './packages/openapi-ts/test/spec/3.0.x/security-open-id-connect.yaml', 10 10 // path: './test/spec/v3-transforms.json', 11 11 // path: 'https://mongodb-mms-prod-build-server.s3.amazonaws.com/openapi/2caffd88277a4e27c95dcefc7e3b6a63a3b03297-v2-2023-11-15.json', 12 12 // path: 'https://raw.githubusercontent.com/swagger-api/swagger-petstore/master/src/main/resources/openapi.yaml', ··· 38 38 { 39 39 // asClass: true, 40 40 // auth: false, 41 - client: false, 41 + // client: false, 42 42 // include... 43 43 name: '@hey-api/sdk', 44 44 // operationId: false,
-31
packages/openapi-ts/test/spec/2.0.x/security-oauth2.json
··· 1 - { 2 - "swagger": "2.0", 3 - "info": { 4 - "title": "OpenAPI 2.0 security oauth2 example", 5 - "version": "1" 6 - }, 7 - "paths": { 8 - "/foo": { 9 - "get": { 10 - "responses": { 11 - "200": { 12 - "description": "OK" 13 - } 14 - }, 15 - "security": [ 16 - { 17 - "foo": [] 18 - } 19 - ] 20 - } 21 - } 22 - }, 23 - "securityDefinitions": { 24 - "foo": { 25 - "flow": "password", 26 - "scopes": {}, 27 - "tokenUrl": "/", 28 - "type": "oauth2" 29 - } 30 - } 31 - }
+18
packages/openapi-ts/test/spec/2.0.x/security-oauth2.yaml
··· 1 + swagger: '2.0' 2 + info: 3 + title: OpenAPI 2.0 security oauth2 example 4 + version: '1' 5 + paths: 6 + /foo: 7 + get: 8 + responses: 9 + '200': 10 + description: OK 11 + security: 12 + - foo: [] 13 + securityDefinitions: 14 + foo: 15 + flow: 'password' 16 + scopes: {} 17 + tokenUrl: '/' 18 + type: 'oauth2'
-36
packages/openapi-ts/test/spec/3.0.x/security-oauth2.json
··· 1 - { 2 - "openapi": "3.0.4", 3 - "info": { 4 - "title": "OpenAPI 3.0.4 security oauth2 example", 5 - "version": "1" 6 - }, 7 - "paths": { 8 - "/foo": { 9 - "get": { 10 - "responses": { 11 - "200": { 12 - "description": "OK" 13 - } 14 - }, 15 - "security": [ 16 - { 17 - "foo": [] 18 - } 19 - ] 20 - } 21 - } 22 - }, 23 - "components": { 24 - "securitySchemes": { 25 - "foo": { 26 - "flows": { 27 - "password": { 28 - "scopes": {}, 29 - "tokenUrl": "/" 30 - } 31 - }, 32 - "type": "oauth2" 33 - } 34 - } 35 - } 36 - }
+30
packages/openapi-ts/test/spec/3.0.x/security-oauth2.yaml
··· 1 + openapi: 3.0.4 2 + info: 3 + title: OpenAPI 3.0.4 security oauth2 example 4 + version: '1' 5 + paths: 6 + /foo: 7 + get: 8 + responses: 9 + '200': 10 + description: OK 11 + security: 12 + - foo: [] 13 + components: 14 + securitySchemes: 15 + foo: 16 + flows: 17 + authorizationCode: 18 + authorizationUrl: '/' 19 + tokenUrl: '/' 20 + scopes: {} 21 + clientCredentials: 22 + tokenUrl: '/' 23 + scopes: {} 24 + implicit: 25 + authorizationUrl: '/' 26 + scopes: {} 27 + password: 28 + scopes: {} 29 + tokenUrl: '/' 30 + type: 'oauth2'
+17
packages/openapi-ts/test/spec/3.0.x/security-open-id-connect.yaml
··· 1 + openapi: 3.0.4 2 + info: 3 + title: OpenAPI 3.0.4 security OpenID Connect example 4 + version: '1' 5 + paths: 6 + /foo: 7 + get: 8 + responses: 9 + '200': 10 + description: OK 11 + security: 12 + - foo: [] 13 + components: 14 + securitySchemes: 15 + foo: 16 + openIdConnectUrl: 'https://example.com/.well-known/openid-configuration' 17 + type: 'openIdConnect'
+10
packages/openapi-ts/test/spec/3.1.x/security-oauth2.yaml
··· 14 14 securitySchemes: 15 15 foo: 16 16 flows: 17 + authorizationCode: 18 + authorizationUrl: '/' 19 + tokenUrl: '/' 20 + scopes: {} 21 + clientCredentials: 22 + tokenUrl: '/' 23 + scopes: {} 24 + implicit: 25 + authorizationUrl: '/' 26 + scopes: {} 17 27 password: 18 28 scopes: {} 19 29 tokenUrl: '/'
+17
packages/openapi-ts/test/spec/3.1.x/security-open-id-connect.yaml
··· 1 + openapi: 3.1.1 2 + info: 3 + title: OpenAPI 3.1.1 security OpenID Connect example 4 + version: '1' 5 + paths: 6 + /foo: 7 + get: 8 + responses: 9 + '200': 10 + description: OK 11 + security: 12 + - foo: [] 13 + components: 14 + securitySchemes: 15 + foo: 16 + openIdConnectUrl: 'https://example.com/.well-known/openid-configuration' 17 + type: 'openIdConnect'