genoc 0.4.3 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,14 +1,81 @@
1
1
  import type { ErrorResponse, StreamResponse } from './responses.js';
2
+ /**
3
+ * OAuth 2.0 flow configuration, spec-agnostic structural twin of the OpenAPI
4
+ * OAuth Flow Object. Which URLs are meaningful depends on the flow kind.
5
+ */
6
+ export type OAuthFlow = {
7
+ authorizationUrl?: string;
8
+ tokenUrl?: string;
9
+ refreshUrl?: string;
10
+ scopes: Record<string, string>;
11
+ };
12
+ /**
13
+ * OAuth 2.0 flows, spec-agnostic structural twin of the OpenAPI OAuth Flows
14
+ * Object.
15
+ */
16
+ export type OAuthFlows = {
17
+ implicit?: OAuthFlow;
18
+ password?: OAuthFlow;
19
+ clientCredentials?: OAuthFlow;
20
+ authorizationCode?: OAuthFlow;
21
+ };
22
+ /**
23
+ * Spec-agnostic structural twin of an OpenAPI security scheme object,
24
+ * discriminated on `type` so implementations can narrow.
25
+ */
26
+ export type SecurityScheme = {
27
+ type: 'apiKey';
28
+ name: string;
29
+ in: string;
30
+ description?: string;
31
+ } | {
32
+ type: 'http';
33
+ scheme: string;
34
+ bearerFormat?: string;
35
+ description?: string;
36
+ } | {
37
+ type: 'oauth2';
38
+ flows: OAuthFlows;
39
+ description?: string;
40
+ } | {
41
+ type: 'openIdConnect';
42
+ openIdConnectUrl: string;
43
+ description?: string;
44
+ } | {
45
+ type: 'mutualTLS';
46
+ description?: string;
47
+ };
48
+ /**
49
+ * One scheme invocation inside a security requirement: the scheme name as
50
+ * declared in the spec, the scopes requested for it, and the resolved scheme
51
+ * object.
52
+ */
53
+ export type SecurityCall = {
54
+ schemeName: string;
55
+ scopes: readonly string[];
56
+ scheme: SecurityScheme;
57
+ };
58
+ /**
59
+ * One security alternative. Several `SecurityCall`s inside one requirement are
60
+ * conjunctive — all must be satisfied.
61
+ */
62
+ export type SecurityRequirement = readonly SecurityCall[];
2
63
  /**
3
64
  * Performs an HTTP request and returns the response.
4
65
  *
5
66
  * When `expectStream` is true, the implementation should return
6
67
  * a `StreamResponse` containing the stream data, filename (from
7
68
  * Content-Disposition header), and response headers.
69
+ *
70
+ * When `security` is present, it carries the operation's security requirements
71
+ * as an OR-list of AND-alternatives (spec `security` semantics): satisfying any
72
+ * one requirement authorizes the request. Each call carries the fully resolved
73
+ * scheme object. Absent `security` means the operation is public.
8
74
  */
9
75
  export type Requester = <TResponse>(method: string, path: string, options: {
10
76
  query?: Record<string, unknown>;
11
77
  body?: unknown;
12
78
  headers?: Record<string, string>;
13
79
  expectStream?: true;
80
+ security?: readonly SecurityRequirement[];
14
81
  }) => Promise<TResponse | StreamResponse | ErrorResponse>;
@@ -72,7 +72,7 @@ export type OperationObject = {
72
72
  requestBody?: RequestBodyObject | ReferenceObject;
73
73
  responses: ResponsesObject;
74
74
  deprecated?: boolean;
75
- security?: unknown[];
75
+ security?: SecurityRequirementObject[];
76
76
  servers?: unknown[];
77
77
  };
78
78
  export type PathItemObject = {
@@ -140,8 +140,9 @@ export type OAuth2FlowsObject = {
140
140
  clientCredentials?: OAuth2FlowClientCredentials;
141
141
  authorizationCode?: OAuth2FlowAuthorizationCode;
142
142
  };
143
+ export type SecurityRequirementObject = Record<string, string[]>;
143
144
  export type SecuritySchemeObject = {
144
- type: 'apiKey' | 'http' | 'oauth2' | 'openIdConnect';
145
+ type: 'apiKey' | 'http' | 'oauth2' | 'openIdConnect' | 'mutualTLS';
145
146
  description?: string;
146
147
  name?: string;
147
148
  in?: 'query' | 'header' | 'cookie';
@@ -156,7 +157,7 @@ export type ComponentsObject = {
156
157
  parameters?: Record<string, ParameterObject | ReferenceObject>;
157
158
  requestBodies?: Record<string, RequestBodyObject | ReferenceObject>;
158
159
  headers?: Record<string, unknown>;
159
- securitySchemes?: Record<string, SecuritySchemeObject>;
160
+ securitySchemes?: Record<string, SecuritySchemeObject | ReferenceObject>;
160
161
  links?: Record<string, unknown>;
161
162
  callbacks?: Record<string, unknown>;
162
163
  examples?: Record<string, unknown>;
@@ -167,7 +168,7 @@ export type OpenAPIDocument = {
167
168
  servers?: ServerObject[];
168
169
  paths?: PathsObject;
169
170
  components?: ComponentsObject;
170
- security?: unknown[];
171
+ security?: SecurityRequirementObject[];
171
172
  tags?: unknown[];
172
173
  externalDocs?: {
173
174
  description?: string;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * The eight OpenAPI Operation Object HTTP methods, in canonical generation
3
+ * order (the order methods appear in generated clients).
4
+ *
5
+ * Single source shared by the analyzer (path-item iteration) and the
6
+ * validators (per-operation checks) — do not inline local copies.
7
+ */
8
+ export declare const HTTP_METHODS: readonly ["get", "post", "put", "patch", "delete", "options", "head", "trace"];
@@ -0,0 +1,17 @@
1
+ /**
2
+ * The eight OpenAPI Operation Object HTTP methods, in canonical generation
3
+ * order (the order methods appear in generated clients).
4
+ *
5
+ * Single source shared by the analyzer (path-item iteration) and the
6
+ * validators (per-operation checks) — do not inline local copies.
7
+ */
8
+ export const HTTP_METHODS = [
9
+ 'get',
10
+ 'post',
11
+ 'put',
12
+ 'patch',
13
+ 'delete',
14
+ 'options',
15
+ 'head',
16
+ 'trace',
17
+ ];
@@ -44,6 +44,7 @@ export const RESERVED_TYPE_NAMES = new Set([
44
44
  ...RUNTIME_CLASS_NAMES,
45
45
  ...CLIENT_SURFACE_NAMES,
46
46
  'FileInput',
47
+ 'SecuritySchemeName',
47
48
  ]);
48
49
  /**
49
50
  * Build a PascalCase type-name prefix from an operation's method + path.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "genoc",
3
- "version": "0.4.3",
3
+ "version": "0.5.0",
4
4
  "description": "Generate typed HTTP clients from OpenAPI 3.0 / 3.1 specifications",
5
5
  "keywords": [
6
6
  "client",