@skmtc/core 0.0.789 → 0.0.790
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/context/RenderContext.d.ts +190 -0
- package/esm/context/RenderContext.d.ts.map +1 -1
- package/esm/context/RenderContext.js +179 -0
- package/esm/oas/boolean/Boolean.d.ts +142 -1
- package/esm/oas/boolean/Boolean.d.ts.map +1 -1
- package/esm/oas/boolean/Boolean.js +130 -1
- package/esm/oas/parameter/Parameter.d.ts +160 -0
- package/esm/oas/parameter/Parameter.d.ts.map +1 -1
- package/esm/oas/parameter/Parameter.js +144 -0
- package/package.json +1 -1
- package/script/context/RenderContext.d.ts +190 -0
- package/script/context/RenderContext.d.ts.map +1 -1
- package/script/context/RenderContext.js +179 -0
- package/script/oas/boolean/Boolean.d.ts +142 -1
- package/script/oas/boolean/Boolean.d.ts.map +1 -1
- package/script/oas/boolean/Boolean.js +130 -1
- package/script/oas/parameter/Parameter.d.ts +160 -0
- package/script/oas/parameter/Parameter.d.ts.map +1 -1
- package/script/oas/parameter/Parameter.js +144 -0
|
@@ -1,6 +1,135 @@
|
|
|
1
1
|
import "../../_dnt.polyfills.js";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Represents a boolean schema in the OpenAPI Specification.
|
|
4
|
+
*
|
|
5
|
+
* The `OasBoolean` class handles boolean data types in OpenAPI schemas, supporting
|
|
6
|
+
* both simple true/false values and more complex boolean schemas with constraints,
|
|
7
|
+
* enumerations, and nullable types. This class provides type-safe boolean handling
|
|
8
|
+
* with optional null value support through generic typing.
|
|
9
|
+
*
|
|
10
|
+
* ## Key Features
|
|
11
|
+
*
|
|
12
|
+
* - **Type Safety**: Generic nullable type support with proper TypeScript inference
|
|
13
|
+
* - **Enum Support**: Constrain boolean values to specific true/false combinations
|
|
14
|
+
* - **Null Handling**: Optional null value support for nullable boolean types
|
|
15
|
+
* - **Validation**: Default values and example validation
|
|
16
|
+
* - **JSON Schema**: Converts to standard JSON Schema format for validation
|
|
17
|
+
* - **Documentation**: Rich metadata support for API documentation
|
|
18
|
+
*
|
|
19
|
+
* @template Nullable - Whether the boolean value itself can be null
|
|
20
|
+
*
|
|
21
|
+
* @example Basic boolean schema
|
|
22
|
+
* ```typescript
|
|
23
|
+
* import { OasBoolean } from '@skmtc/core';
|
|
24
|
+
*
|
|
25
|
+
* const isActiveSchema = new OasBoolean({
|
|
26
|
+
* title: 'Active Status',
|
|
27
|
+
* description: 'Whether the user account is active',
|
|
28
|
+
* default: true,
|
|
29
|
+
* example: true
|
|
30
|
+
* });
|
|
31
|
+
*
|
|
32
|
+
* // This represents: boolean with default true
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* @example Nullable boolean schema
|
|
36
|
+
* ```typescript
|
|
37
|
+
* const nullableFlag = new OasBoolean<true>({
|
|
38
|
+
* title: 'Optional Flag',
|
|
39
|
+
* description: 'An optional boolean flag that can be null',
|
|
40
|
+
* nullable: true,
|
|
41
|
+
* default: null,
|
|
42
|
+
* example: true
|
|
43
|
+
* });
|
|
44
|
+
*
|
|
45
|
+
* // This represents: boolean | null
|
|
46
|
+
* ```
|
|
47
|
+
*
|
|
48
|
+
* @example Boolean with enum constraints
|
|
49
|
+
* ```typescript
|
|
50
|
+
* const strictBoolean = new OasBoolean({
|
|
51
|
+
* title: 'Confirmation',
|
|
52
|
+
* description: 'Must explicitly be true to confirm action',
|
|
53
|
+
* enums: [true], // Only true is allowed
|
|
54
|
+
* example: true
|
|
55
|
+
* });
|
|
56
|
+
*
|
|
57
|
+
* // This only accepts true, effectively making it required
|
|
58
|
+
* ```
|
|
59
|
+
*
|
|
60
|
+
* @example Boolean with null in enum
|
|
61
|
+
* ```typescript
|
|
62
|
+
* const triStateBoolean = new OasBoolean<true>({
|
|
63
|
+
* title: 'Approval Status',
|
|
64
|
+
* description: 'Approval can be true (approved), false (denied), or null (pending)',
|
|
65
|
+
* nullable: true,
|
|
66
|
+
* enums: [true, false, null],
|
|
67
|
+
* default: null,
|
|
68
|
+
* example: null
|
|
69
|
+
* });
|
|
70
|
+
*
|
|
71
|
+
* // This represents: true | false | null (tri-state logic)
|
|
72
|
+
* ```
|
|
73
|
+
*
|
|
74
|
+
* @example Feature flag schema
|
|
75
|
+
* ```typescript
|
|
76
|
+
* const featureFlag = new OasBoolean({
|
|
77
|
+
* title: 'Feature Enabled',
|
|
78
|
+
* description: 'Whether the new feature is enabled for this user',
|
|
79
|
+
* default: false,
|
|
80
|
+
* example: false
|
|
81
|
+
* });
|
|
82
|
+
*
|
|
83
|
+
* // Used in configuration objects
|
|
84
|
+
* const userConfig = new OasObject({
|
|
85
|
+
* properties: {
|
|
86
|
+
* darkMode: featureFlag,
|
|
87
|
+
* notifications: featureFlag,
|
|
88
|
+
* betaFeatures: featureFlag
|
|
89
|
+
* }
|
|
90
|
+
* });
|
|
91
|
+
* ```
|
|
92
|
+
*
|
|
93
|
+
* @example Consent and agreement booleans
|
|
94
|
+
* ```typescript
|
|
95
|
+
* const consentSchema = new OasBoolean({
|
|
96
|
+
* title: 'Terms Accepted',
|
|
97
|
+
* description: 'User has accepted the terms and conditions',
|
|
98
|
+
* enums: [true], // Must be true to be valid
|
|
99
|
+
* example: true
|
|
100
|
+
* });
|
|
101
|
+
*
|
|
102
|
+
* const privacyConsent = new OasBoolean({
|
|
103
|
+
* title: 'Privacy Policy Accepted',
|
|
104
|
+
* description: 'User has accepted the privacy policy',
|
|
105
|
+
* default: false,
|
|
106
|
+
* example: true
|
|
107
|
+
* });
|
|
108
|
+
*
|
|
109
|
+
* // Used in registration forms where consent is required
|
|
110
|
+
* ```
|
|
111
|
+
*
|
|
112
|
+
* @example Optional settings with nullable booleans
|
|
113
|
+
* ```typescript
|
|
114
|
+
* const userPreferences = new OasObject({
|
|
115
|
+
* properties: {
|
|
116
|
+
* emailNotifications: new OasBoolean<true>({
|
|
117
|
+
* title: 'Email Notifications',
|
|
118
|
+
* description: 'Enable email notifications (null means use default)',
|
|
119
|
+
* nullable: true,
|
|
120
|
+
* default: null
|
|
121
|
+
* }),
|
|
122
|
+
* smsNotifications: new OasBoolean<true>({
|
|
123
|
+
* title: 'SMS Notifications',
|
|
124
|
+
* description: 'Enable SMS notifications (null means not set)',
|
|
125
|
+
* nullable: true,
|
|
126
|
+
* default: null
|
|
127
|
+
* })
|
|
128
|
+
* }
|
|
129
|
+
* });
|
|
130
|
+
*
|
|
131
|
+
* // Allows: { emailNotifications: true, smsNotifications: null }
|
|
132
|
+
* ```
|
|
4
133
|
*/
|
|
5
134
|
export class OasBoolean {
|
|
6
135
|
constructor(fields = {}) {
|
|
@@ -6,21 +6,181 @@ import type { OasExample } from '../example/Example.js';
|
|
|
6
6
|
import type { OasSchema } from '../schema/Schema.js';
|
|
7
7
|
import type { ToJsonSchemaOptions } from '../schema/Schema.js';
|
|
8
8
|
import type { OpenAPIV3 } from 'openapi-types';
|
|
9
|
+
/**
|
|
10
|
+
* Constructor fields for {@link OasParameter}.
|
|
11
|
+
*/
|
|
9
12
|
export type ParameterFields = {
|
|
13
|
+
/** The name of the parameter */
|
|
10
14
|
name: string;
|
|
15
|
+
/** The location of the parameter (path, query, header, cookie) */
|
|
11
16
|
location: OasParameterLocation;
|
|
17
|
+
/** A brief description of the parameter */
|
|
12
18
|
description?: string | undefined;
|
|
19
|
+
/** Determines whether this parameter is mandatory */
|
|
13
20
|
required?: boolean | undefined;
|
|
21
|
+
/** Specifies that the parameter is deprecated */
|
|
14
22
|
deprecated?: boolean | undefined;
|
|
23
|
+
/** Whether to allow empty values for the parameter */
|
|
15
24
|
allowEmptyValue?: boolean | undefined;
|
|
25
|
+
/** Whether reserved characters are allowed in the parameter value */
|
|
16
26
|
allowReserved?: boolean | undefined;
|
|
27
|
+
/** The schema defining the parameter's data type */
|
|
17
28
|
schema?: OasSchema | OasRef<'schema'> | undefined;
|
|
29
|
+
/** Example values for the parameter */
|
|
18
30
|
examples?: Record<string, OasExample | OasRef<'example'>> | undefined;
|
|
31
|
+
/** Media type definitions for the parameter content */
|
|
19
32
|
content?: Record<string, OasMediaType> | undefined;
|
|
33
|
+
/** The serialization style for the parameter */
|
|
20
34
|
style: OasParameterStyle;
|
|
35
|
+
/** Whether to explode parameter values */
|
|
21
36
|
explode: boolean;
|
|
37
|
+
/** Custom extension fields (x-* properties) */
|
|
22
38
|
extensionFields?: Record<string, unknown>;
|
|
23
39
|
};
|
|
40
|
+
/**
|
|
41
|
+
* Represents a Parameter Object in the OpenAPI Specification.
|
|
42
|
+
*
|
|
43
|
+
* The `OasParameter` class encapsulates the definition of a single operation parameter,
|
|
44
|
+
* including its location, data type, validation rules, and serialization behavior.
|
|
45
|
+
* Parameters can be located in the path, query string, headers, or cookies.
|
|
46
|
+
*
|
|
47
|
+
* This class provides comprehensive support for parameter validation, serialization
|
|
48
|
+
* styles, and complex data types through schema definitions or content specifications.
|
|
49
|
+
*
|
|
50
|
+
* ## Key Features
|
|
51
|
+
*
|
|
52
|
+
* - **Location Support**: Path, query, header, and cookie parameters
|
|
53
|
+
* - **Schema Validation**: Comprehensive data type validation through schemas
|
|
54
|
+
* - **Serialization Styles**: Various parameter serialization formats
|
|
55
|
+
* - **Content Types**: Support for complex parameter content with media types
|
|
56
|
+
* - **Examples & Documentation**: Parameter examples and descriptive documentation
|
|
57
|
+
* - **Advanced Options**: Empty values, reserved characters, and explode behavior
|
|
58
|
+
*
|
|
59
|
+
* @example Basic path parameter
|
|
60
|
+
* ```typescript
|
|
61
|
+
* import { OasParameter, OasString } from '@skmtc/core';
|
|
62
|
+
*
|
|
63
|
+
* const userIdParam = new OasParameter({
|
|
64
|
+
* name: 'userId',
|
|
65
|
+
* location: 'path',
|
|
66
|
+
* description: 'Unique identifier for the user',
|
|
67
|
+
* required: true,
|
|
68
|
+
* schema: new OasString({
|
|
69
|
+
* pattern: '^[0-9a-f]{24}$',
|
|
70
|
+
* example: '507f1f77bcf86cd799439011'
|
|
71
|
+
* }),
|
|
72
|
+
* style: 'simple',
|
|
73
|
+
* explode: false
|
|
74
|
+
* });
|
|
75
|
+
*
|
|
76
|
+
* // Used in path: /users/{userId}
|
|
77
|
+
* ```
|
|
78
|
+
*
|
|
79
|
+
* @example Query parameter with validation
|
|
80
|
+
* ```typescript
|
|
81
|
+
* const pageSizeParam = new OasParameter({
|
|
82
|
+
* name: 'pageSize',
|
|
83
|
+
* location: 'query',
|
|
84
|
+
* description: 'Number of items to return per page',
|
|
85
|
+
* required: false,
|
|
86
|
+
* schema: new OasInteger({
|
|
87
|
+
* minimum: 1,
|
|
88
|
+
* maximum: 100,
|
|
89
|
+
* default: 20
|
|
90
|
+
* }),
|
|
91
|
+
* style: 'form',
|
|
92
|
+
* explode: true,
|
|
93
|
+
* examples: {
|
|
94
|
+
* small: new OasExample({ value: 10 }),
|
|
95
|
+
* medium: new OasExample({ value: 25 }),
|
|
96
|
+
* large: new OasExample({ value: 50 })
|
|
97
|
+
* }
|
|
98
|
+
* });
|
|
99
|
+
*
|
|
100
|
+
* // Used in query: ?pageSize=20
|
|
101
|
+
* ```
|
|
102
|
+
*
|
|
103
|
+
* @example Header parameter
|
|
104
|
+
* ```typescript
|
|
105
|
+
* const authHeaderParam = new OasParameter({
|
|
106
|
+
* name: 'Authorization',
|
|
107
|
+
* location: 'header',
|
|
108
|
+
* description: 'Bearer token for authentication',
|
|
109
|
+
* required: true,
|
|
110
|
+
* schema: new OasString({
|
|
111
|
+
* pattern: '^Bearer [A-Za-z0-9+/=]+$',
|
|
112
|
+
* example: 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...'
|
|
113
|
+
* }),
|
|
114
|
+
* style: 'simple',
|
|
115
|
+
* explode: false
|
|
116
|
+
* });
|
|
117
|
+
* ```
|
|
118
|
+
*
|
|
119
|
+
* @example Complex parameter with content
|
|
120
|
+
* ```typescript
|
|
121
|
+
* const filterParam = new OasParameter({
|
|
122
|
+
* name: 'filter',
|
|
123
|
+
* location: 'query',
|
|
124
|
+
* description: 'Complex filter object',
|
|
125
|
+
* required: false,
|
|
126
|
+
* content: {
|
|
127
|
+
* 'application/json': new OasMediaType({
|
|
128
|
+
* schema: new OasObject({
|
|
129
|
+
* properties: {
|
|
130
|
+
* category: new OasString(),
|
|
131
|
+
* priceRange: new OasObject({
|
|
132
|
+
* properties: {
|
|
133
|
+
* min: new OasNumber(),
|
|
134
|
+
* max: new OasNumber()
|
|
135
|
+
* }
|
|
136
|
+
* })
|
|
137
|
+
* }
|
|
138
|
+
* })
|
|
139
|
+
* })
|
|
140
|
+
* },
|
|
141
|
+
* style: 'deepObject',
|
|
142
|
+
* explode: true
|
|
143
|
+
* });
|
|
144
|
+
*
|
|
145
|
+
* // Used as: ?filter[category]=electronics&filter[priceRange][min]=100
|
|
146
|
+
* ```
|
|
147
|
+
*
|
|
148
|
+
* @example Array parameter with explode
|
|
149
|
+
* ```typescript
|
|
150
|
+
* const tagsParam = new OasParameter({
|
|
151
|
+
* name: 'tags',
|
|
152
|
+
* location: 'query',
|
|
153
|
+
* description: 'Filter by multiple tags',
|
|
154
|
+
* required: false,
|
|
155
|
+
* schema: new OasArray({
|
|
156
|
+
* items: new OasString(),
|
|
157
|
+
* minItems: 1,
|
|
158
|
+
* maxItems: 10
|
|
159
|
+
* }),
|
|
160
|
+
* style: 'form',
|
|
161
|
+
* explode: true // Results in: ?tags=tech&tags=api&tags=rest
|
|
162
|
+
* });
|
|
163
|
+
*
|
|
164
|
+
* // Without explode: ?tags=tech,api,rest
|
|
165
|
+
* // With explode: ?tags=tech&tags=api&tags=rest
|
|
166
|
+
* ```
|
|
167
|
+
*
|
|
168
|
+
* @example Cookie parameter
|
|
169
|
+
* ```typescript
|
|
170
|
+
* const sessionParam = new OasParameter({
|
|
171
|
+
* name: 'sessionId',
|
|
172
|
+
* location: 'cookie',
|
|
173
|
+
* description: 'Session identifier cookie',
|
|
174
|
+
* required: false,
|
|
175
|
+
* schema: new OasString({
|
|
176
|
+
* minLength: 32,
|
|
177
|
+
* maxLength: 128
|
|
178
|
+
* }),
|
|
179
|
+
* style: 'form',
|
|
180
|
+
* explode: false
|
|
181
|
+
* });
|
|
182
|
+
* ```
|
|
183
|
+
*/
|
|
24
184
|
export declare class OasParameter {
|
|
25
185
|
oasType: 'parameter';
|
|
26
186
|
name: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Parameter.d.ts","sourceRoot":"","sources":["../../../src/oas/parameter/Parameter.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AACnF,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;AAK9C,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,oBAAoB,CAAA;IAC9B,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAChC,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;IAC9B,UAAU,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;IAChC,eAAe,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;IACrC,aAAa,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;IACnC,MAAM,CAAC,EAAE,SAAS,GAAG,MAAM,CAAC,QAAQ,CAAC,GAAG,SAAS,CAAA;IACjD,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC,GAAG,SAAS,CAAA;IACr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MAAM,EAAE,eAAe;IAkBnC,KAAK,IAAI,IAAI,IAAI,MAAM,CAAC,WAAW,CAAC;IAIpC,OAAO,IAAI,YAAY;IAIvB,WAAW,IAAI,YAAY;IAI3B,QAAQ,CAAC,SAAS,GAAE,MAA2B,GAAG,SAAS,GAAG,MAAM,CAAC,QAAQ,CAAC;IAc9E,YAAY,CAAC,OAAO,EAAE,mBAAmB,GAAG,SAAS,CAAC,eAAe;CAuBtE"}
|
|
@@ -1,4 +1,148 @@
|
|
|
1
1
|
import "../../_dnt.polyfills.js";
|
|
2
|
+
/**
|
|
3
|
+
* Represents a Parameter Object in the OpenAPI Specification.
|
|
4
|
+
*
|
|
5
|
+
* The `OasParameter` class encapsulates the definition of a single operation parameter,
|
|
6
|
+
* including its location, data type, validation rules, and serialization behavior.
|
|
7
|
+
* Parameters can be located in the path, query string, headers, or cookies.
|
|
8
|
+
*
|
|
9
|
+
* This class provides comprehensive support for parameter validation, serialization
|
|
10
|
+
* styles, and complex data types through schema definitions or content specifications.
|
|
11
|
+
*
|
|
12
|
+
* ## Key Features
|
|
13
|
+
*
|
|
14
|
+
* - **Location Support**: Path, query, header, and cookie parameters
|
|
15
|
+
* - **Schema Validation**: Comprehensive data type validation through schemas
|
|
16
|
+
* - **Serialization Styles**: Various parameter serialization formats
|
|
17
|
+
* - **Content Types**: Support for complex parameter content with media types
|
|
18
|
+
* - **Examples & Documentation**: Parameter examples and descriptive documentation
|
|
19
|
+
* - **Advanced Options**: Empty values, reserved characters, and explode behavior
|
|
20
|
+
*
|
|
21
|
+
* @example Basic path parameter
|
|
22
|
+
* ```typescript
|
|
23
|
+
* import { OasParameter, OasString } from '@skmtc/core';
|
|
24
|
+
*
|
|
25
|
+
* const userIdParam = new OasParameter({
|
|
26
|
+
* name: 'userId',
|
|
27
|
+
* location: 'path',
|
|
28
|
+
* description: 'Unique identifier for the user',
|
|
29
|
+
* required: true,
|
|
30
|
+
* schema: new OasString({
|
|
31
|
+
* pattern: '^[0-9a-f]{24}$',
|
|
32
|
+
* example: '507f1f77bcf86cd799439011'
|
|
33
|
+
* }),
|
|
34
|
+
* style: 'simple',
|
|
35
|
+
* explode: false
|
|
36
|
+
* });
|
|
37
|
+
*
|
|
38
|
+
* // Used in path: /users/{userId}
|
|
39
|
+
* ```
|
|
40
|
+
*
|
|
41
|
+
* @example Query parameter with validation
|
|
42
|
+
* ```typescript
|
|
43
|
+
* const pageSizeParam = new OasParameter({
|
|
44
|
+
* name: 'pageSize',
|
|
45
|
+
* location: 'query',
|
|
46
|
+
* description: 'Number of items to return per page',
|
|
47
|
+
* required: false,
|
|
48
|
+
* schema: new OasInteger({
|
|
49
|
+
* minimum: 1,
|
|
50
|
+
* maximum: 100,
|
|
51
|
+
* default: 20
|
|
52
|
+
* }),
|
|
53
|
+
* style: 'form',
|
|
54
|
+
* explode: true,
|
|
55
|
+
* examples: {
|
|
56
|
+
* small: new OasExample({ value: 10 }),
|
|
57
|
+
* medium: new OasExample({ value: 25 }),
|
|
58
|
+
* large: new OasExample({ value: 50 })
|
|
59
|
+
* }
|
|
60
|
+
* });
|
|
61
|
+
*
|
|
62
|
+
* // Used in query: ?pageSize=20
|
|
63
|
+
* ```
|
|
64
|
+
*
|
|
65
|
+
* @example Header parameter
|
|
66
|
+
* ```typescript
|
|
67
|
+
* const authHeaderParam = new OasParameter({
|
|
68
|
+
* name: 'Authorization',
|
|
69
|
+
* location: 'header',
|
|
70
|
+
* description: 'Bearer token for authentication',
|
|
71
|
+
* required: true,
|
|
72
|
+
* schema: new OasString({
|
|
73
|
+
* pattern: '^Bearer [A-Za-z0-9+/=]+$',
|
|
74
|
+
* example: 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...'
|
|
75
|
+
* }),
|
|
76
|
+
* style: 'simple',
|
|
77
|
+
* explode: false
|
|
78
|
+
* });
|
|
79
|
+
* ```
|
|
80
|
+
*
|
|
81
|
+
* @example Complex parameter with content
|
|
82
|
+
* ```typescript
|
|
83
|
+
* const filterParam = new OasParameter({
|
|
84
|
+
* name: 'filter',
|
|
85
|
+
* location: 'query',
|
|
86
|
+
* description: 'Complex filter object',
|
|
87
|
+
* required: false,
|
|
88
|
+
* content: {
|
|
89
|
+
* 'application/json': new OasMediaType({
|
|
90
|
+
* schema: new OasObject({
|
|
91
|
+
* properties: {
|
|
92
|
+
* category: new OasString(),
|
|
93
|
+
* priceRange: new OasObject({
|
|
94
|
+
* properties: {
|
|
95
|
+
* min: new OasNumber(),
|
|
96
|
+
* max: new OasNumber()
|
|
97
|
+
* }
|
|
98
|
+
* })
|
|
99
|
+
* }
|
|
100
|
+
* })
|
|
101
|
+
* })
|
|
102
|
+
* },
|
|
103
|
+
* style: 'deepObject',
|
|
104
|
+
* explode: true
|
|
105
|
+
* });
|
|
106
|
+
*
|
|
107
|
+
* // Used as: ?filter[category]=electronics&filter[priceRange][min]=100
|
|
108
|
+
* ```
|
|
109
|
+
*
|
|
110
|
+
* @example Array parameter with explode
|
|
111
|
+
* ```typescript
|
|
112
|
+
* const tagsParam = new OasParameter({
|
|
113
|
+
* name: 'tags',
|
|
114
|
+
* location: 'query',
|
|
115
|
+
* description: 'Filter by multiple tags',
|
|
116
|
+
* required: false,
|
|
117
|
+
* schema: new OasArray({
|
|
118
|
+
* items: new OasString(),
|
|
119
|
+
* minItems: 1,
|
|
120
|
+
* maxItems: 10
|
|
121
|
+
* }),
|
|
122
|
+
* style: 'form',
|
|
123
|
+
* explode: true // Results in: ?tags=tech&tags=api&tags=rest
|
|
124
|
+
* });
|
|
125
|
+
*
|
|
126
|
+
* // Without explode: ?tags=tech,api,rest
|
|
127
|
+
* // With explode: ?tags=tech&tags=api&tags=rest
|
|
128
|
+
* ```
|
|
129
|
+
*
|
|
130
|
+
* @example Cookie parameter
|
|
131
|
+
* ```typescript
|
|
132
|
+
* const sessionParam = new OasParameter({
|
|
133
|
+
* name: 'sessionId',
|
|
134
|
+
* location: 'cookie',
|
|
135
|
+
* description: 'Session identifier cookie',
|
|
136
|
+
* required: false,
|
|
137
|
+
* schema: new OasString({
|
|
138
|
+
* minLength: 32,
|
|
139
|
+
* maxLength: 128
|
|
140
|
+
* }),
|
|
141
|
+
* style: 'form',
|
|
142
|
+
* explode: false
|
|
143
|
+
* });
|
|
144
|
+
* ```
|
|
145
|
+
*/
|
|
2
146
|
export class OasParameter {
|
|
3
147
|
constructor(fields) {
|
|
4
148
|
Object.defineProperty(this, "oasType", {
|
package/package.json
CHANGED
|
@@ -8,16 +8,206 @@ import type * as log from '../deps/jsr.io/@std/log/0.224.14/mod.js';
|
|
|
8
8
|
import { File } from '../dsl/File.js';
|
|
9
9
|
import type { Preview, Mapping } from '../types/Preview.js';
|
|
10
10
|
import type { JsonFile } from '../dsl/JsonFile.js';
|
|
11
|
+
/**
|
|
12
|
+
* Constructor arguments for {@link RenderContext}.
|
|
13
|
+
*/
|
|
11
14
|
type ConstructorArgs = {
|
|
15
|
+
/** Map of generated files to render */
|
|
12
16
|
files: Map<string, File | JsonFile>;
|
|
17
|
+
/** Preview data for generated content */
|
|
13
18
|
previews: Record<string, Record<string, Preview>>;
|
|
19
|
+
/** Mapping data for file relationships */
|
|
14
20
|
mappings: Record<string, Record<string, Mapping>>;
|
|
21
|
+
/** Optional Prettier configuration for code formatting */
|
|
15
22
|
prettierConfig?: PrettierConfigType;
|
|
23
|
+
/** Base path for resolving file paths */
|
|
16
24
|
basePath: string | undefined;
|
|
25
|
+
/** Stack trail for distributed tracing */
|
|
17
26
|
stackTrail: StackTrail;
|
|
27
|
+
/** Logger instance for debug information */
|
|
18
28
|
logger: log.Logger;
|
|
29
|
+
/** Function to capture result status */
|
|
19
30
|
captureCurrentResult: (result: ResultType) => void;
|
|
20
31
|
};
|
|
32
|
+
/**
|
|
33
|
+
* The rendering context for the final phase of the SKMTC transformation pipeline.
|
|
34
|
+
*
|
|
35
|
+
* `RenderContext` is responsible for taking the generated artifacts from the generation
|
|
36
|
+
* phase and rendering them into their final form with proper formatting, path resolution,
|
|
37
|
+
* and file preparation. It handles code formatting via Prettier, path normalization,
|
|
38
|
+
* and produces the final artifacts ready for writing to the filesystem.
|
|
39
|
+
*
|
|
40
|
+
* This context represents the culmination of the three-phase SKMTC pipeline, transforming
|
|
41
|
+
* generator outputs into production-ready code files with proper formatting and structure.
|
|
42
|
+
*
|
|
43
|
+
* ## Key Features
|
|
44
|
+
*
|
|
45
|
+
* - **Code Formatting**: Automatic Prettier formatting for generated TypeScript/JavaScript code
|
|
46
|
+
* - **Path Resolution**: Intelligent path resolution with base path support
|
|
47
|
+
* - **Content Collation**: Combines all generated content into organized file structures
|
|
48
|
+
* - **Metadata Generation**: Tracks file statistics (lines, characters) and relationships
|
|
49
|
+
* - **Error Tracking**: Comprehensive error handling with Sentry integration
|
|
50
|
+
* - **Performance Monitoring**: Built-in tracing and performance measurement
|
|
51
|
+
*
|
|
52
|
+
* @example Basic rendering usage
|
|
53
|
+
* ```typescript
|
|
54
|
+
* import { RenderContext } from '@skmtc/core';
|
|
55
|
+
*
|
|
56
|
+
* const renderContext = new RenderContext({
|
|
57
|
+
* files: generatedFiles,
|
|
58
|
+
* previews: previewData,
|
|
59
|
+
* mappings: mappingData,
|
|
60
|
+
* prettierConfig: {
|
|
61
|
+
* semi: false,
|
|
62
|
+
* singleQuote: true,
|
|
63
|
+
* trailingComma: 'all'
|
|
64
|
+
* },
|
|
65
|
+
* basePath: './src/generated',
|
|
66
|
+
* stackTrail: traceStack,
|
|
67
|
+
* logger: myLogger,
|
|
68
|
+
* captureCurrentResult: (result) => console.log(result)
|
|
69
|
+
* });
|
|
70
|
+
*
|
|
71
|
+
* const rendered = await renderContext.render();
|
|
72
|
+
*
|
|
73
|
+
* // Access rendered files
|
|
74
|
+
* Object.entries(rendered.artifacts).forEach(([path, content]) => {
|
|
75
|
+
* console.log(`Rendered ${path}: ${rendered.files[path].lines} lines`);
|
|
76
|
+
* // Write to filesystem
|
|
77
|
+
* await Deno.writeTextFile(path, content);
|
|
78
|
+
* });
|
|
79
|
+
* ```
|
|
80
|
+
*
|
|
81
|
+
* @example With custom Prettier configuration
|
|
82
|
+
* ```typescript
|
|
83
|
+
* const renderContext = new RenderContext({
|
|
84
|
+
* files: generatedFiles,
|
|
85
|
+
* previews: {},
|
|
86
|
+
* mappings: {},
|
|
87
|
+
* prettierConfig: {
|
|
88
|
+
* parser: 'typescript',
|
|
89
|
+
* printWidth: 120,
|
|
90
|
+
* tabWidth: 2,
|
|
91
|
+
* semi: true,
|
|
92
|
+
* singleQuote: true,
|
|
93
|
+
* trailingComma: 'es5',
|
|
94
|
+
* bracketSpacing: true,
|
|
95
|
+
* arrowParens: 'avoid'
|
|
96
|
+
* },
|
|
97
|
+
* basePath: './packages/api-client/src',
|
|
98
|
+
* stackTrail: stack,
|
|
99
|
+
* logger: logger,
|
|
100
|
+
* captureCurrentResult: resultHandler
|
|
101
|
+
* });
|
|
102
|
+
*
|
|
103
|
+
* const result = await renderContext.render();
|
|
104
|
+
*
|
|
105
|
+
* // All TypeScript files are automatically formatted
|
|
106
|
+
* console.log('Formatted files:', Object.keys(result.artifacts).length);
|
|
107
|
+
* ```
|
|
108
|
+
*
|
|
109
|
+
* @example Processing render results
|
|
110
|
+
* ```typescript
|
|
111
|
+
* const rendered = await renderContext.render();
|
|
112
|
+
*
|
|
113
|
+
* // Analyze file statistics
|
|
114
|
+
* const totalLines = Object.values(rendered.files)
|
|
115
|
+
* .reduce((sum, file) => sum + file.lines, 0);
|
|
116
|
+
* const totalChars = Object.values(rendered.files)
|
|
117
|
+
* .reduce((sum, file) => sum + file.characters, 0);
|
|
118
|
+
*
|
|
119
|
+
* console.log(`Generated ${Object.keys(rendered.artifacts).length} files`);
|
|
120
|
+
* console.log(`Total lines: ${totalLines}`);
|
|
121
|
+
* console.log(`Total characters: ${totalChars}`);
|
|
122
|
+
*
|
|
123
|
+
* // Check for large files
|
|
124
|
+
* const largeFiles = Object.entries(rendered.files)
|
|
125
|
+
* .filter(([_, metadata]) => metadata.lines > 1000)
|
|
126
|
+
* .map(([path, metadata]) => ({ path, lines: metadata.lines }));
|
|
127
|
+
*
|
|
128
|
+
* if (largeFiles.length > 0) {
|
|
129
|
+
* console.log('Large files detected:', largeFiles);
|
|
130
|
+
* }
|
|
131
|
+
*
|
|
132
|
+
* // Access preview and mapping data
|
|
133
|
+
* console.log('Previews available:', Object.keys(rendered.previews));
|
|
134
|
+
* console.log('Mappings available:', Object.keys(rendered.mappings));
|
|
135
|
+
* ```
|
|
136
|
+
*
|
|
137
|
+
* @example Integration with CoreContext
|
|
138
|
+
* ```typescript
|
|
139
|
+
* // Typically used within CoreContext.toArtifacts()
|
|
140
|
+
* class CustomCoreContext extends CoreContext {
|
|
141
|
+
* async renderWithPostProcessing(
|
|
142
|
+
* files: Map<string, File | JsonFile>,
|
|
143
|
+
* previews: Record<string, Record<string, Preview>>,
|
|
144
|
+
* mappings: Record<string, Record<string, Mapping>>
|
|
145
|
+
* ) {
|
|
146
|
+
* const renderContext = new RenderContext({
|
|
147
|
+
* files,
|
|
148
|
+
* previews,
|
|
149
|
+
* mappings,
|
|
150
|
+
* prettierConfig: this.prettierConfig,
|
|
151
|
+
* basePath: this.settings?.basePath,
|
|
152
|
+
* stackTrail: this.stackTrail,
|
|
153
|
+
* logger: this.logger,
|
|
154
|
+
* captureCurrentResult: this.captureCurrentResult.bind(this)
|
|
155
|
+
* });
|
|
156
|
+
*
|
|
157
|
+
* const rendered = await renderContext.render();
|
|
158
|
+
*
|
|
159
|
+
* // Post-process rendered files
|
|
160
|
+
* const processedArtifacts: Record<string, string> = {};
|
|
161
|
+
*
|
|
162
|
+
* for (const [path, content] of Object.entries(rendered.artifacts)) {
|
|
163
|
+
* // Add file headers, license notices, etc.
|
|
164
|
+
* const processedContent = this.addFileHeader(content, path);
|
|
165
|
+
* processedArtifacts[path] = processedContent;
|
|
166
|
+
* }
|
|
167
|
+
*
|
|
168
|
+
* return {
|
|
169
|
+
* ...rendered,
|
|
170
|
+
* artifacts: processedArtifacts
|
|
171
|
+
* };
|
|
172
|
+
* }
|
|
173
|
+
* }
|
|
174
|
+
* ```
|
|
175
|
+
*
|
|
176
|
+
* @example Error handling during rendering
|
|
177
|
+
* ```typescript
|
|
178
|
+
* try {
|
|
179
|
+
* const renderContext = new RenderContext({
|
|
180
|
+
* files: generatedFiles,
|
|
181
|
+
* previews: {},
|
|
182
|
+
* mappings: {},
|
|
183
|
+
* prettierConfig: prettierConfig,
|
|
184
|
+
* basePath: './invalid-path', // This might cause issues
|
|
185
|
+
* stackTrail: stack,
|
|
186
|
+
* logger: logger,
|
|
187
|
+
* captureCurrentResult: (result) => {
|
|
188
|
+
* if (result === 'error') {
|
|
189
|
+
* console.error('Render error detected');
|
|
190
|
+
* }
|
|
191
|
+
* }
|
|
192
|
+
* });
|
|
193
|
+
*
|
|
194
|
+
* const result = await renderContext.render();
|
|
195
|
+
*
|
|
196
|
+
* // Check if any files failed to render
|
|
197
|
+
* const failedFiles = Object.entries(result.files)
|
|
198
|
+
* .filter(([path, metadata]) => metadata.lines === 0)
|
|
199
|
+
* .map(([path]) => path);
|
|
200
|
+
*
|
|
201
|
+
* if (failedFiles.length > 0) {
|
|
202
|
+
* console.warn('Files with no content:', failedFiles);
|
|
203
|
+
* }
|
|
204
|
+
*
|
|
205
|
+
* } catch (error) {
|
|
206
|
+
* console.error('Render operation failed:', error);
|
|
207
|
+
* // Sentry automatically captures the error
|
|
208
|
+
* }
|
|
209
|
+
* ```
|
|
210
|
+
*/
|
|
21
211
|
export declare class RenderContext {
|
|
22
212
|
#private;
|
|
23
213
|
files: Map<string, File | JsonFile>;
|