| @@ -12,6 +12,10 @@ import { HttpMethod, ServerInfo, type ExtractionResult } from "./types"; · 11 unmodified lines |
| 12 | | 12 | |
| 13 | /** Scopes declared by a flow: `{ scopeName: description }` */ | 13 | /** Scopes declared by a flow: `{ scopeName: description }` */ |
| 14 | const OAuth2Scopes = Schema.Record(Schema.String, Schema.String); | 14 | const OAuth2Scopes = Schema.Record(Schema.String, Schema.String); |
| | 15 | const SecuritySchemeType = Schema.Literals(["http", "apiKey", "oauth2", "openIdConnect"]); |
| | 16 | type SecuritySchemeType = typeof SecuritySchemeType.Type; |
| | 17 | |
| | 18 | const decodeSecuritySchemeType = Schema.decodeUnknownOption(SecuritySchemeType); |
| 15 | | 19 | |
| 16 | export class OAuth2AuthorizationCodeFlow extends Schema.Class<OAuth2AuthorizationCodeFlow>( | 20 | export class OAuth2AuthorizationCodeFlow extends Schema.Class<OAuth2AuthorizationCodeFlow>( |
| 17 | "OAuth2AuthorizationCodeFlow", | 21 | "OAuth2AuthorizationCodeFlow", |
| @@ -43,7 +47,7 @@ export class SecurityScheme extends Schema.Class<SecurityScheme>("SecurityScheme · 25 unmodified lines |
| 43 | /** Key name in components.securitySchemes (e.g. "api_token") */ | 47 | /** Key name in components.securitySchemes (e.g. "api_token") */ |
| 44 | name: Schema.String, | 48 | name: Schema.String, |
| 45 | /** OpenAPI security scheme type */ | 49 | /** OpenAPI security scheme type */ |
| 46 | type: Schema.Literals(["http", "apiKey", "oauth2", "openIdConnect"]), | 50 | type: SecuritySchemeType, |
| 47 | /** For type: "http" — e.g. "bearer", "basic" */ | 51 | /** For type: "http" — e.g. "bearer", "basic" */ |
| 48 | scheme: Schema.OptionFromOptional(Schema.String), | 52 | scheme: Schema.OptionFromOptional(Schema.String), |
| 49 | /** For type: "http" with scheme "bearer" — e.g. "JWT" */ | 53 | /** For type: "http" with scheme "bearer" — e.g. "JWT" */ |
| @@ -215,19 +219,20 @@ const extractSecuritySchemes = ( · 165 unmodified lines |
| 215 | if (!resolved || typeof resolved !== "object") return []; | 219 | if (!resolved || typeof resolved !== "object") return []; |
| 216 | const scheme = resolved; | 220 | const scheme = resolved; |
| 217 | | 221 | |
| 218 | const type = scheme.type as string; | 222 | const type = decodeSecuritySchemeType(scheme.type); |
| 219 | if (!["http", "apiKey", "oauth2", "openIdConnect"].includes(type)) return []; | 223 | if (Option.isNone(type)) return []; |
| | 224 | const schemeType = type.value; |
| 220 | | 225 | |
| 221 | return [ | 226 | return [ |
| 222 | new SecurityScheme({ | 227 | new SecurityScheme({ |
| 223 | name, | 228 | name, |
| 224 | type: type as "http" | "apiKey" | "oauth2" | "openIdConnect", | 229 | type: schemeType, |
| 225 | scheme: Option.fromNullishOr(scheme.scheme as string | undefined), | 230 | scheme: Option.fromNullishOr(scheme.scheme as string | undefined), |
| 226 | bearerFormat: Option.fromNullishOr(scheme.bearerFormat as string | undefined), | 231 | bearerFormat: Option.fromNullishOr(scheme.bearerFormat as string | undefined), |
| 227 | in: Option.fromNullishOr(scheme.in as "header" | "query" | "cookie" | undefined), | 232 | in: Option.fromNullishOr(scheme.in as "header" | "query" | "cookie" | undefined), |
| 228 | headerName: Option.fromNullishOr(scheme.name as string | undefined), | 233 | headerName: Option.fromNullishOr(scheme.name as string | undefined), |
| 229 | description: Option.fromNullishOr(scheme.description as string | undefined), | 234 | description: Option.fromNullishOr(scheme.description as string | undefined), |
| 230 | flows: type === "oauth2" ? extractFlows(scheme.flows) : Option.none(), | 235 | flows: schemeType === "oauth2" ? extractFlows(scheme.flows) : Option.none(), |
| 231 | openIdConnectUrl: Option.fromNullishOr( | 236 | openIdConnectUrl: Option.fromNullishOr( |
| 232 | scheme.openIdConnectUrl as string | undefined, | 237 | scheme.openIdConnectUrl as string | undefined, |
| 233 | ), | 238 | ), |