@skmtc/core 0.0.790 → 0.0.792
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.
- package/esm/helpers/naming.d.ts +65 -1
- package/esm/helpers/naming.d.ts.map +1 -1
- package/esm/helpers/naming.js +65 -1
- package/esm/oas/example/Example.d.ts +81 -1
- package/esm/oas/example/Example.d.ts.map +1 -1
- package/esm/oas/example/Example.js +74 -1
- package/esm/oas/header/Header.d.ts +217 -1
- package/esm/oas/header/Header.d.ts.map +1 -1
- package/esm/oas/header/Header.js +207 -1
- package/esm/oas/info/Info.d.ts +72 -0
- package/esm/oas/info/Info.d.ts.map +1 -1
- package/esm/oas/info/Info.js +62 -0
- package/esm/oas/mediaType/MediaType.d.ts +85 -0
- package/esm/oas/mediaType/MediaType.d.ts.map +1 -1
- package/esm/oas/mediaType/MediaType.js +77 -0
- package/esm/oas/number/Number.d.ts +179 -1
- package/esm/oas/number/Number.d.ts.map +1 -1
- package/esm/oas/number/Number.js +161 -1
- package/esm/oas/pathItem/PathItem.d.ts +92 -0
- package/esm/oas/pathItem/PathItem.d.ts.map +1 -1
- package/esm/oas/pathItem/PathItem.js +85 -0
- package/esm/oas/requestBody/RequestBody.d.ts +264 -0
- package/esm/oas/requestBody/RequestBody.d.ts.map +1 -1
- package/esm/oas/requestBody/RequestBody.js +257 -0
- package/esm/oas/response/Response.d.ts +190 -0
- package/esm/oas/response/Response.d.ts.map +1 -1
- package/esm/oas/response/Response.js +183 -0
- package/esm/oas/void/Void.d.ts +130 -3
- package/esm/oas/void/Void.d.ts.map +1 -1
- package/esm/oas/void/Void.js +125 -3
- package/package.json +1 -1
- package/script/helpers/naming.d.ts +65 -1
- package/script/helpers/naming.d.ts.map +1 -1
- package/script/helpers/naming.js +65 -1
- package/script/oas/example/Example.d.ts +81 -1
- package/script/oas/example/Example.d.ts.map +1 -1
- package/script/oas/example/Example.js +74 -1
- package/script/oas/header/Header.d.ts +217 -1
- package/script/oas/header/Header.d.ts.map +1 -1
- package/script/oas/header/Header.js +207 -1
- package/script/oas/info/Info.d.ts +72 -0
- package/script/oas/info/Info.d.ts.map +1 -1
- package/script/oas/info/Info.js +62 -0
- package/script/oas/mediaType/MediaType.d.ts +85 -0
- package/script/oas/mediaType/MediaType.d.ts.map +1 -1
- package/script/oas/mediaType/MediaType.js +77 -0
- package/script/oas/number/Number.d.ts +179 -1
- package/script/oas/number/Number.d.ts.map +1 -1
- package/script/oas/number/Number.js +161 -1
- package/script/oas/pathItem/PathItem.d.ts +92 -0
- package/script/oas/pathItem/PathItem.d.ts.map +1 -1
- package/script/oas/pathItem/PathItem.js +85 -0
- package/script/oas/requestBody/RequestBody.d.ts +264 -0
- package/script/oas/requestBody/RequestBody.d.ts.map +1 -1
- package/script/oas/requestBody/RequestBody.js +257 -0
- package/script/oas/response/Response.d.ts +190 -0
- package/script/oas/response/Response.d.ts.map +1 -1
- package/script/oas/response/Response.js +183 -0
- package/script/oas/void/Void.d.ts +130 -3
- package/script/oas/void/Void.d.ts.map +1 -1
- package/script/oas/void/Void.js +125 -3
package/esm/helpers/naming.d.ts
CHANGED
|
@@ -1,9 +1,73 @@
|
|
|
1
1
|
import type { OasOperation } from '../oas/operation/Operation.js';
|
|
2
2
|
import type { Method } from '../types/Method.js';
|
|
3
|
+
/**
|
|
4
|
+
* Determines the endpoint type based on HTTP method.
|
|
5
|
+
*
|
|
6
|
+
* @param operation - The OpenAPI operation to analyze
|
|
7
|
+
* @returns 'query' for GET operations, 'mutation' for all others
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* const getOp = new OasOperation({ method: 'get', path: '/users' });
|
|
12
|
+
* console.log(toEndpointType(getOp)); // 'query'
|
|
13
|
+
*
|
|
14
|
+
* const postOp = new OasOperation({ method: 'post', path: '/users' });
|
|
15
|
+
* console.log(toEndpointType(postOp)); // 'mutation'
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
3
18
|
export declare const toEndpointType: (operation: OasOperation) => "query" | "mutation";
|
|
4
|
-
/**
|
|
19
|
+
/**
|
|
20
|
+
* Generates endpoint name in the `camelCase{method}Api{path}` format.
|
|
21
|
+
*
|
|
22
|
+
* @param operation - The OpenAPI operation
|
|
23
|
+
* @returns Camel-cased endpoint name
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```typescript
|
|
27
|
+
* const op = new OasOperation({ method: 'post', path: '/users/{id}/profile' });
|
|
28
|
+
* console.log(toEndpointName(op)); // 'createApiUsersIdProfile'
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
5
31
|
export declare const toEndpointName: (operation: OasOperation) => string;
|
|
32
|
+
/**
|
|
33
|
+
* Generates response type name for an operation.
|
|
34
|
+
*
|
|
35
|
+
* @param operation - The OpenAPI operation
|
|
36
|
+
* @returns Response type name with 'Response' suffix
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```typescript
|
|
40
|
+
* const op = new OasOperation({ method: 'get', path: '/users' });
|
|
41
|
+
* console.log(toResponseName(op)); // 'getApiUsersResponse'
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
6
44
|
export declare const toResponseName: (operation: OasOperation) => string;
|
|
45
|
+
/**
|
|
46
|
+
* Generates arguments type name for an operation.
|
|
47
|
+
*
|
|
48
|
+
* @param operation - The OpenAPI operation
|
|
49
|
+
* @returns Arguments type name with 'Args' suffix
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```typescript
|
|
53
|
+
* const op = new OasOperation({ method: 'put', path: '/users/{id}' });
|
|
54
|
+
* console.log(toArgsName(op)); // 'updateApiUsersIdArgs'
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
7
57
|
export declare const toArgsName: (operation: OasOperation) => string;
|
|
58
|
+
/**
|
|
59
|
+
* Converts HTTP method to a descriptive verb.
|
|
60
|
+
*
|
|
61
|
+
* @param method - HTTP method
|
|
62
|
+
* @returns Descriptive verb for the method
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```typescript
|
|
66
|
+
* console.log(toMethodVerb('post')); // 'Create'
|
|
67
|
+
* console.log(toMethodVerb('put')); // 'Update'
|
|
68
|
+
* console.log(toMethodVerb('get')); // 'get'
|
|
69
|
+
* console.log(toMethodVerb('delete')); // 'delete'
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
8
72
|
export declare const toMethodVerb: (method: Method) => string;
|
|
9
73
|
//# sourceMappingURL=naming.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"naming.d.ts","sourceRoot":"","sources":["../../src/helpers/naming.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAA;AACjE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAGhD,eAAO,MAAM,cAAc,GAAI,WAAW,YAAY,KAAG,OAAO,GAAG,UAElE,CAAA;AAED
|
|
1
|
+
{"version":3,"file":"naming.d.ts","sourceRoot":"","sources":["../../src/helpers/naming.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAA;AACjE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAGhD;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,cAAc,GAAI,WAAW,YAAY,KAAG,OAAO,GAAG,UAElE,CAAA;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,cAAc,GAAI,WAAW,YAAY,KAAG,MAMxD,CAAA;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,cAAc,GAAI,WAAW,YAAY,KAAG,MAIxD,CAAA;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,UAAU,GAAI,WAAW,YAAY,KAAG,MAIpD,CAAA;AAED;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,YAAY,GAAI,QAAQ,MAAM,KAAG,MAK7C,CAAA"}
|
package/esm/helpers/naming.js
CHANGED
|
@@ -1,22 +1,86 @@
|
|
|
1
1
|
import { camelCase } from 'lodash-es';
|
|
2
2
|
import { match } from 'ts-pattern';
|
|
3
|
+
/**
|
|
4
|
+
* Determines the endpoint type based on HTTP method.
|
|
5
|
+
*
|
|
6
|
+
* @param operation - The OpenAPI operation to analyze
|
|
7
|
+
* @returns 'query' for GET operations, 'mutation' for all others
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* const getOp = new OasOperation({ method: 'get', path: '/users' });
|
|
12
|
+
* console.log(toEndpointType(getOp)); // 'query'
|
|
13
|
+
*
|
|
14
|
+
* const postOp = new OasOperation({ method: 'post', path: '/users' });
|
|
15
|
+
* console.log(toEndpointType(postOp)); // 'mutation'
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
3
18
|
export const toEndpointType = (operation) => {
|
|
4
19
|
return operation.method === 'get' ? 'query' : 'mutation';
|
|
5
20
|
};
|
|
6
|
-
/**
|
|
21
|
+
/**
|
|
22
|
+
* Generates endpoint name in the `camelCase{method}Api{path}` format.
|
|
23
|
+
*
|
|
24
|
+
* @param operation - The OpenAPI operation
|
|
25
|
+
* @returns Camel-cased endpoint name
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* const op = new OasOperation({ method: 'post', path: '/users/{id}/profile' });
|
|
30
|
+
* console.log(toEndpointName(op)); // 'createApiUsersIdProfile'
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
7
33
|
export const toEndpointName = (operation) => {
|
|
8
34
|
const { path, method } = operation;
|
|
9
35
|
const verb = toMethodVerb(method);
|
|
10
36
|
return camelCase(`${verb}Api${path}`);
|
|
11
37
|
};
|
|
38
|
+
/**
|
|
39
|
+
* Generates response type name for an operation.
|
|
40
|
+
*
|
|
41
|
+
* @param operation - The OpenAPI operation
|
|
42
|
+
* @returns Response type name with 'Response' suffix
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* const op = new OasOperation({ method: 'get', path: '/users' });
|
|
47
|
+
* console.log(toResponseName(op)); // 'getApiUsersResponse'
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
12
50
|
export const toResponseName = (operation) => {
|
|
13
51
|
const operationName = toEndpointName(operation);
|
|
14
52
|
return `${operationName}Response`;
|
|
15
53
|
};
|
|
54
|
+
/**
|
|
55
|
+
* Generates arguments type name for an operation.
|
|
56
|
+
*
|
|
57
|
+
* @param operation - The OpenAPI operation
|
|
58
|
+
* @returns Arguments type name with 'Args' suffix
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```typescript
|
|
62
|
+
* const op = new OasOperation({ method: 'put', path: '/users/{id}' });
|
|
63
|
+
* console.log(toArgsName(op)); // 'updateApiUsersIdArgs'
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
16
66
|
export const toArgsName = (operation) => {
|
|
17
67
|
const operationName = toEndpointName(operation);
|
|
18
68
|
return `${operationName}Args`;
|
|
19
69
|
};
|
|
70
|
+
/**
|
|
71
|
+
* Converts HTTP method to a descriptive verb.
|
|
72
|
+
*
|
|
73
|
+
* @param method - HTTP method
|
|
74
|
+
* @returns Descriptive verb for the method
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```typescript
|
|
78
|
+
* console.log(toMethodVerb('post')); // 'Create'
|
|
79
|
+
* console.log(toMethodVerb('put')); // 'Update'
|
|
80
|
+
* console.log(toMethodVerb('get')); // 'get'
|
|
81
|
+
* console.log(toMethodVerb('delete')); // 'delete'
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
20
84
|
export const toMethodVerb = (method) => {
|
|
21
85
|
return match(method)
|
|
22
86
|
.with('post', () => 'Create')
|
|
@@ -1,13 +1,93 @@
|
|
|
1
1
|
import type { OasRef } from '../ref/Ref.js';
|
|
2
2
|
import type { ToJsonSchemaOptions } from '../schema/Schema.js';
|
|
3
3
|
import type { OpenAPIV3 } from 'openapi-types';
|
|
4
|
+
/**
|
|
5
|
+
* Constructor fields for {@link OasExample}.
|
|
6
|
+
*/
|
|
4
7
|
export type ExampleFields = {
|
|
8
|
+
/** Short summary of the example */
|
|
5
9
|
summary: string | undefined;
|
|
10
|
+
/** Longer description of the example */
|
|
6
11
|
description: string | undefined;
|
|
12
|
+
/** The example value */
|
|
7
13
|
value: unknown;
|
|
14
|
+
/** Custom extension fields (x-* properties) */
|
|
8
15
|
extensionFields?: Record<string, unknown>;
|
|
9
16
|
};
|
|
10
|
-
/**
|
|
17
|
+
/**
|
|
18
|
+
* Represents an Example Object in the OpenAPI Specification.
|
|
19
|
+
*
|
|
20
|
+
* The `OasExample` class provides sample data for parameters, request bodies,
|
|
21
|
+
* responses, and other components in an OpenAPI document. Examples are crucial
|
|
22
|
+
* for API documentation, testing, and helping developers understand expected
|
|
23
|
+
* data formats and structures.
|
|
24
|
+
*
|
|
25
|
+
* This class supports rich example definitions with metadata, making API
|
|
26
|
+
* documentation more informative and interactive for developers.
|
|
27
|
+
*
|
|
28
|
+
* ## Key Features
|
|
29
|
+
*
|
|
30
|
+
* - **Sample Data**: Concrete examples of API inputs and outputs
|
|
31
|
+
* - **Documentation**: Summary and description for context
|
|
32
|
+
* - **Type Flexibility**: Supports any data type as example values
|
|
33
|
+
* - **Reference Support**: Can be referenced from multiple locations
|
|
34
|
+
* - **Markdown Support**: Rich text descriptions with CommonMark
|
|
35
|
+
*
|
|
36
|
+
* @example Simple string example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* import { OasExample } from '@skmtc/core';
|
|
39
|
+
*
|
|
40
|
+
* const nameExample = new OasExample({
|
|
41
|
+
* summary: 'Typical user name',
|
|
42
|
+
* description: 'A common first and last name combination',
|
|
43
|
+
* value: 'John Doe'
|
|
44
|
+
* });
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* @example JSON object example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* const userExample = new OasExample({
|
|
50
|
+
* summary: 'Complete user profile',
|
|
51
|
+
* description: 'Example user with all profile fields populated',
|
|
52
|
+
* value: {
|
|
53
|
+
* id: 12345,
|
|
54
|
+
* name: 'Jane Smith',
|
|
55
|
+
* email: 'jane.smith@example.com',
|
|
56
|
+
* active: true,
|
|
57
|
+
* createdAt: '2023-01-15T10:30:00Z'
|
|
58
|
+
* }
|
|
59
|
+
* });
|
|
60
|
+
* ```
|
|
61
|
+
*
|
|
62
|
+
* @example Array example with multiple items
|
|
63
|
+
* ```typescript
|
|
64
|
+
* const productsExample = new OasExample({
|
|
65
|
+
* summary: 'Product list sample',
|
|
66
|
+
* description: 'Typical response for product catalog endpoint',
|
|
67
|
+
* value: [
|
|
68
|
+
* { id: 1, name: 'Laptop', price: 999.99, category: 'Electronics' },
|
|
69
|
+
* { id: 2, name: 'Book', price: 19.99, category: 'Education' },
|
|
70
|
+
* { id: 3, name: 'Coffee Mug', price: 12.50, category: 'Home' }
|
|
71
|
+
* ]
|
|
72
|
+
* });
|
|
73
|
+
* ```
|
|
74
|
+
*
|
|
75
|
+
* @example Error response example
|
|
76
|
+
* ```typescript
|
|
77
|
+
* const errorExample = new OasExample({
|
|
78
|
+
* summary: 'Validation error',
|
|
79
|
+
* description: 'Response when request validation fails',
|
|
80
|
+
* value: {
|
|
81
|
+
* error: 'Validation failed',
|
|
82
|
+
* code: 'INVALID_INPUT',
|
|
83
|
+
* details: [
|
|
84
|
+
* { field: 'email', message: 'Invalid email format' },
|
|
85
|
+
* { field: 'age', message: 'Must be between 18 and 120' }
|
|
86
|
+
* ]
|
|
87
|
+
* }
|
|
88
|
+
* });
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
11
91
|
export declare class OasExample {
|
|
12
92
|
#private;
|
|
13
93
|
/** Static identifier property for OasExample */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Example.d.ts","sourceRoot":"","sources":["../../../src/oas/example/Example.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,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M,GAAG,SAAS,CAEpC;IAED,6BAA6B;IAC7B,IAAI,KAAK,IAAI,OAAO,CAEnB;IAED,qCAAqC;IACrC,IAAI,eAAe,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAEzD;IAED,4CAA4C;IAC5C,KAAK,IAAI,IAAI,IAAI,MAAM,CAAC,SAAS,CAAC;IAIlC,qBAAqB;IACrB,OAAO,IAAI,UAAU;IAIrB,WAAW,IAAI,UAAU;IAIzB,YAAY,CAAC,QAAQ,EAAE,mBAAmB,GAAG,SAAS,CAAC,aAAa;CAOrE"}
|
|
@@ -10,7 +10,80 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
12
|
var _OasExample_fields;
|
|
13
|
-
/**
|
|
13
|
+
/**
|
|
14
|
+
* Represents an Example Object in the OpenAPI Specification.
|
|
15
|
+
*
|
|
16
|
+
* The `OasExample` class provides sample data for parameters, request bodies,
|
|
17
|
+
* responses, and other components in an OpenAPI document. Examples are crucial
|
|
18
|
+
* for API documentation, testing, and helping developers understand expected
|
|
19
|
+
* data formats and structures.
|
|
20
|
+
*
|
|
21
|
+
* This class supports rich example definitions with metadata, making API
|
|
22
|
+
* documentation more informative and interactive for developers.
|
|
23
|
+
*
|
|
24
|
+
* ## Key Features
|
|
25
|
+
*
|
|
26
|
+
* - **Sample Data**: Concrete examples of API inputs and outputs
|
|
27
|
+
* - **Documentation**: Summary and description for context
|
|
28
|
+
* - **Type Flexibility**: Supports any data type as example values
|
|
29
|
+
* - **Reference Support**: Can be referenced from multiple locations
|
|
30
|
+
* - **Markdown Support**: Rich text descriptions with CommonMark
|
|
31
|
+
*
|
|
32
|
+
* @example Simple string example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* import { OasExample } from '@skmtc/core';
|
|
35
|
+
*
|
|
36
|
+
* const nameExample = new OasExample({
|
|
37
|
+
* summary: 'Typical user name',
|
|
38
|
+
* description: 'A common first and last name combination',
|
|
39
|
+
* value: 'John Doe'
|
|
40
|
+
* });
|
|
41
|
+
* ```
|
|
42
|
+
*
|
|
43
|
+
* @example JSON object example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* const userExample = new OasExample({
|
|
46
|
+
* summary: 'Complete user profile',
|
|
47
|
+
* description: 'Example user with all profile fields populated',
|
|
48
|
+
* value: {
|
|
49
|
+
* id: 12345,
|
|
50
|
+
* name: 'Jane Smith',
|
|
51
|
+
* email: 'jane.smith@example.com',
|
|
52
|
+
* active: true,
|
|
53
|
+
* createdAt: '2023-01-15T10:30:00Z'
|
|
54
|
+
* }
|
|
55
|
+
* });
|
|
56
|
+
* ```
|
|
57
|
+
*
|
|
58
|
+
* @example Array example with multiple items
|
|
59
|
+
* ```typescript
|
|
60
|
+
* const productsExample = new OasExample({
|
|
61
|
+
* summary: 'Product list sample',
|
|
62
|
+
* description: 'Typical response for product catalog endpoint',
|
|
63
|
+
* value: [
|
|
64
|
+
* { id: 1, name: 'Laptop', price: 999.99, category: 'Electronics' },
|
|
65
|
+
* { id: 2, name: 'Book', price: 19.99, category: 'Education' },
|
|
66
|
+
* { id: 3, name: 'Coffee Mug', price: 12.50, category: 'Home' }
|
|
67
|
+
* ]
|
|
68
|
+
* });
|
|
69
|
+
* ```
|
|
70
|
+
*
|
|
71
|
+
* @example Error response example
|
|
72
|
+
* ```typescript
|
|
73
|
+
* const errorExample = new OasExample({
|
|
74
|
+
* summary: 'Validation error',
|
|
75
|
+
* description: 'Response when request validation fails',
|
|
76
|
+
* value: {
|
|
77
|
+
* error: 'Validation failed',
|
|
78
|
+
* code: 'INVALID_INPUT',
|
|
79
|
+
* details: [
|
|
80
|
+
* { field: 'email', message: 'Invalid email format' },
|
|
81
|
+
* { field: 'age', message: 'Must be between 18 and 120' }
|
|
82
|
+
* ]
|
|
83
|
+
* }
|
|
84
|
+
* });
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
14
87
|
export class OasExample {
|
|
15
88
|
constructor(fields) {
|
|
16
89
|
/** Static identifier property for OasExample */
|
|
@@ -4,16 +4,232 @@ import type { OasExample } from '../example/Example.js';
|
|
|
4
4
|
import type { OasSchema } from '../schema/Schema.js';
|
|
5
5
|
import type { ToJsonSchemaOptions } from '../schema/Schema.js';
|
|
6
6
|
import type { OpenAPIV3 } from 'openapi-types';
|
|
7
|
+
/**
|
|
8
|
+
* Constructor fields for {@link OasHeader}.
|
|
9
|
+
*/
|
|
7
10
|
export type HeaderFields = {
|
|
11
|
+
/** A brief description of the header */
|
|
8
12
|
description: string | undefined;
|
|
13
|
+
/** Whether the header is required */
|
|
9
14
|
required: boolean | undefined;
|
|
15
|
+
/** Whether the header is deprecated */
|
|
10
16
|
deprecated: boolean | undefined;
|
|
17
|
+
/** Schema defining the header's data type */
|
|
11
18
|
schema: OasSchema | OasRef<'schema'> | undefined;
|
|
19
|
+
/** Example values for the header */
|
|
12
20
|
examples: Record<string, OasExample | OasRef<'example'>> | undefined;
|
|
21
|
+
/** Content definitions for complex header values */
|
|
13
22
|
content: Record<string, OasMediaType> | undefined;
|
|
23
|
+
/** Custom extension fields (x-* properties) */
|
|
14
24
|
extensionFields?: Record<string, unknown>;
|
|
15
25
|
};
|
|
16
|
-
/**
|
|
26
|
+
/**
|
|
27
|
+
* Represents a Header Object in the OpenAPI Specification.
|
|
28
|
+
*
|
|
29
|
+
* The `OasHeader` class encapsulates the definition of a single HTTP header that
|
|
30
|
+
* can be sent with responses or expected in requests. Headers provide additional
|
|
31
|
+
* metadata about the HTTP message and can include authentication tokens, content
|
|
32
|
+
* information, pagination data, rate limiting details, and more.
|
|
33
|
+
*
|
|
34
|
+
* This class provides comprehensive support for header definitions with typed
|
|
35
|
+
* values, validation schemas, examples, and documentation.
|
|
36
|
+
*
|
|
37
|
+
* ## Key Features
|
|
38
|
+
*
|
|
39
|
+
* - **Schema Validation**: Typed header values through schema definitions
|
|
40
|
+
* - **Examples**: Multiple example values for documentation and testing
|
|
41
|
+
* - **Content Types**: Support for complex header values with media types
|
|
42
|
+
* - **Deprecation Support**: Mark headers as deprecated with proper warnings
|
|
43
|
+
* - **Required/Optional**: Control whether headers are mandatory
|
|
44
|
+
* - **Documentation**: Rich description support for API documentation
|
|
45
|
+
*
|
|
46
|
+
* @example Basic authentication header
|
|
47
|
+
* ```typescript
|
|
48
|
+
* import { OasHeader, OasString } from '@skmtc/core';
|
|
49
|
+
*
|
|
50
|
+
* const authHeader = new OasHeader({
|
|
51
|
+
* description: 'Bearer token for API authentication',
|
|
52
|
+
* required: true,
|
|
53
|
+
* schema: new OasString({
|
|
54
|
+
* pattern: '^Bearer [A-Za-z0-9+/=]+$',
|
|
55
|
+
* description: 'JWT bearer token'
|
|
56
|
+
* }),
|
|
57
|
+
* examples: {
|
|
58
|
+
* valid: new OasExample({
|
|
59
|
+
* summary: 'Valid bearer token',
|
|
60
|
+
* value: 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...'
|
|
61
|
+
* })
|
|
62
|
+
* }
|
|
63
|
+
* });
|
|
64
|
+
* ```
|
|
65
|
+
*
|
|
66
|
+
* @example Pagination headers
|
|
67
|
+
* ```typescript
|
|
68
|
+
* const totalCountHeader = new OasHeader({
|
|
69
|
+
* description: 'Total number of items available',
|
|
70
|
+
* required: false,
|
|
71
|
+
* schema: new OasInteger({
|
|
72
|
+
* minimum: 0,
|
|
73
|
+
* description: 'Non-negative integer count'
|
|
74
|
+
* }),
|
|
75
|
+
* examples: {
|
|
76
|
+
* empty: new OasExample({ value: 0, description: 'No items' }),
|
|
77
|
+
* normal: new OasExample({ value: 150, description: 'Normal case' }),
|
|
78
|
+
* large: new OasExample({ value: 10000, description: 'Large dataset' })
|
|
79
|
+
* }
|
|
80
|
+
* });
|
|
81
|
+
*
|
|
82
|
+
* const linkHeader = new OasHeader({
|
|
83
|
+
* description: 'Pagination links (RFC 5988)',
|
|
84
|
+
* required: false,
|
|
85
|
+
* schema: new OasString({
|
|
86
|
+
* description: 'Comma-separated list of link relations'
|
|
87
|
+
* }),
|
|
88
|
+
* examples: {
|
|
89
|
+
* withNext: new OasExample({
|
|
90
|
+
* value: '</api/users?page=2>; rel="next", </api/users?page=10>; rel="last"'
|
|
91
|
+
* }),
|
|
92
|
+
* lastPage: new OasExample({
|
|
93
|
+
* value: '</api/users?page=9>; rel="prev", </api/users?page=1>; rel="first"'
|
|
94
|
+
* })
|
|
95
|
+
* }
|
|
96
|
+
* });
|
|
97
|
+
* ```
|
|
98
|
+
*
|
|
99
|
+
* @example Content type and encoding headers
|
|
100
|
+
* ```typescript
|
|
101
|
+
* const contentTypeHeader = new OasHeader({
|
|
102
|
+
* description: 'MIME type of the response content',
|
|
103
|
+
* required: true,
|
|
104
|
+
* schema: new OasString({
|
|
105
|
+
* enum: [
|
|
106
|
+
* 'application/json',
|
|
107
|
+
* 'application/xml',
|
|
108
|
+
* 'text/csv',
|
|
109
|
+
* 'application/pdf',
|
|
110
|
+
* 'application/octet-stream'
|
|
111
|
+
* ]
|
|
112
|
+
* }),
|
|
113
|
+
* examples: {
|
|
114
|
+
* json: new OasExample({ value: 'application/json' }),
|
|
115
|
+
* xml: new OasExample({ value: 'application/xml' }),
|
|
116
|
+
* csv: new OasExample({ value: 'text/csv' })
|
|
117
|
+
* }
|
|
118
|
+
* });
|
|
119
|
+
*
|
|
120
|
+
* const contentLengthHeader = new OasHeader({
|
|
121
|
+
* description: 'Size of the response body in bytes',
|
|
122
|
+
* required: false,
|
|
123
|
+
* schema: new OasInteger({
|
|
124
|
+
* minimum: 0,
|
|
125
|
+
* description: 'Content size in bytes'
|
|
126
|
+
* })
|
|
127
|
+
* });
|
|
128
|
+
* ```
|
|
129
|
+
*
|
|
130
|
+
* @example Rate limiting headers
|
|
131
|
+
* ```typescript
|
|
132
|
+
* const rateLimitHeader = new OasHeader({
|
|
133
|
+
* description: 'Number of requests remaining in the current window',
|
|
134
|
+
* required: false,
|
|
135
|
+
* schema: new OasInteger({
|
|
136
|
+
* minimum: 0,
|
|
137
|
+
* description: 'Remaining request count'
|
|
138
|
+
* }),
|
|
139
|
+
* examples: {
|
|
140
|
+
* available: new OasExample({ value: 95, description: '95 requests remaining' }),
|
|
141
|
+
* depleted: new OasExample({ value: 0, description: 'Rate limit reached' })
|
|
142
|
+
* }
|
|
143
|
+
* });
|
|
144
|
+
*
|
|
145
|
+
* const rateLimitResetHeader = new OasHeader({
|
|
146
|
+
* description: 'Unix timestamp when the rate limit window resets',
|
|
147
|
+
* required: false,
|
|
148
|
+
* schema: new OasInteger({
|
|
149
|
+
* minimum: 0,
|
|
150
|
+
* description: 'Unix timestamp in seconds'
|
|
151
|
+
* }),
|
|
152
|
+
* examples: {
|
|
153
|
+
* reset: new OasExample({
|
|
154
|
+
* value: 1634567890,
|
|
155
|
+
* description: 'Reset at 2021-10-18 12:31:30 UTC'
|
|
156
|
+
* })
|
|
157
|
+
* }
|
|
158
|
+
* });
|
|
159
|
+
* ```
|
|
160
|
+
*
|
|
161
|
+
* @example Custom application headers
|
|
162
|
+
* ```typescript
|
|
163
|
+
* const requestIdHeader = new OasHeader({
|
|
164
|
+
* description: 'Unique identifier for request tracing',
|
|
165
|
+
* required: false,
|
|
166
|
+
* schema: new OasString({
|
|
167
|
+
* format: 'uuid',
|
|
168
|
+
* description: 'UUID v4 request identifier'
|
|
169
|
+
* }),
|
|
170
|
+
* examples: {
|
|
171
|
+
* uuid: new OasExample({
|
|
172
|
+
* value: '123e4567-e89b-12d3-a456-426614174000',
|
|
173
|
+
* description: 'Request tracking ID'
|
|
174
|
+
* })
|
|
175
|
+
* }
|
|
176
|
+
* });
|
|
177
|
+
*
|
|
178
|
+
* const serverTimingHeader = new OasHeader({
|
|
179
|
+
* description: 'Server-side performance metrics',
|
|
180
|
+
* required: false,
|
|
181
|
+
* schema: new OasString({
|
|
182
|
+
* description: 'Server-Timing header format (RFC 8760)'
|
|
183
|
+
* }),
|
|
184
|
+
* examples: {
|
|
185
|
+
* timing: new OasExample({
|
|
186
|
+
* value: 'db;dur=53, app;dur=47.2',
|
|
187
|
+
* description: 'Database took 53ms, app logic 47.2ms'
|
|
188
|
+
* })
|
|
189
|
+
* }
|
|
190
|
+
* });
|
|
191
|
+
* ```
|
|
192
|
+
*
|
|
193
|
+
* @example Deprecated header
|
|
194
|
+
* ```typescript
|
|
195
|
+
* const deprecatedHeader = new OasHeader({
|
|
196
|
+
* description: 'Legacy API version header (deprecated)',
|
|
197
|
+
* required: false,
|
|
198
|
+
* deprecated: true,
|
|
199
|
+
* schema: new OasString({
|
|
200
|
+
* enum: ['v1', 'v2'],
|
|
201
|
+
* description: 'Use Accept or Content-Type header instead'
|
|
202
|
+
* }),
|
|
203
|
+
* examples: {
|
|
204
|
+
* legacy: new OasExample({
|
|
205
|
+
* value: 'v1',
|
|
206
|
+
* description: 'Legacy version (use Accept header instead)'
|
|
207
|
+
* })
|
|
208
|
+
* }
|
|
209
|
+
* });
|
|
210
|
+
* ```
|
|
211
|
+
*
|
|
212
|
+
* @example Using in response definitions
|
|
213
|
+
* ```typescript
|
|
214
|
+
* const successResponse = new OasResponse({
|
|
215
|
+
* description: 'Paginated user list',
|
|
216
|
+
* headers: {
|
|
217
|
+
* 'X-Total-Count': totalCountHeader,
|
|
218
|
+
* 'Link': linkHeader,
|
|
219
|
+
* 'X-Rate-Limit-Remaining': rateLimitHeader,
|
|
220
|
+
* 'X-Rate-Limit-Reset': rateLimitResetHeader,
|
|
221
|
+
* 'X-Request-ID': requestIdHeader
|
|
222
|
+
* },
|
|
223
|
+
* content: {
|
|
224
|
+
* 'application/json': new OasMediaType({
|
|
225
|
+
* schema: new OasArray({
|
|
226
|
+
* items: new OasRef({ $ref: '#/components/schemas/User' })
|
|
227
|
+
* })
|
|
228
|
+
* })
|
|
229
|
+
* }
|
|
230
|
+
* });
|
|
231
|
+
* ```
|
|
232
|
+
*/
|
|
17
233
|
export declare class OasHeader {
|
|
18
234
|
#private;
|
|
19
235
|
oasType: 'header';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Header.d.ts","sourceRoot":"","sources":["../../../src/oas/header/Header.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAC7D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AACvD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AACpD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAA;AAC9D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAE9C,MAAM,MAAM,YAAY,GAAG;IACzB,WAAW,EAAE,MAAM,GAAG,SAAS,CAAA;IAC/B,QAAQ,EAAE,OAAO,GAAG,SAAS,CAAA;IAC7B,UAAU,EAAE,OAAO,GAAG,SAAS,CAAA;IAC/B,MAAM,EAAE,SAAS,GAAG,MAAM,CAAC,QAAQ,CAAC,GAAG,SAAS,CAAA;IAChD,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC,GAAG,SAAS,CAAA;IACpE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,GAAG,SAAS,CAAA;IACjD,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAC1C,CAAA;AAED
|
|
1
|
+
{"version":3,"file":"Header.d.ts","sourceRoot":"","sources":["../../../src/oas/header/Header.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAC7D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AACvD,OAAO,KAAK,EAAE,SAAS,EA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