@skmtc/core 0.0.807 → 0.0.809
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/oas/array/array-types.d.ts +238 -25
- package/esm/oas/array/array-types.d.ts.map +1 -1
- package/esm/oas/array/array-types.js +97 -5
- package/esm/oas/boolean/boolean-types.d.ts +81 -9
- package/esm/oas/boolean/boolean-types.d.ts.map +1 -1
- package/esm/oas/boolean/boolean-types.js +32 -2
- package/esm/oas/contact/contact-types.d.ts +176 -0
- package/esm/oas/contact/contact-types.d.ts.map +1 -1
- package/esm/oas/contact/contact-types.js +102 -0
- package/esm/oas/mediaType/toMediaTypeItemV3.d.ts +288 -0
- package/esm/oas/mediaType/toMediaTypeItemV3.d.ts.map +1 -1
- package/esm/oas/mediaType/toMediaTypeItemV3.js +272 -0
- package/esm/oas/operation/operation-types.d.ts +251 -0
- package/esm/oas/operation/operation-types.d.ts.map +1 -1
- package/esm/oas/operation/operation-types.js +98 -0
- package/esm/oas/string/string-types.d.ts +192 -18
- package/esm/oas/string/string-types.d.ts.map +1 -1
- package/esm/oas/string/string-types.js +76 -4
- package/esm/types/ModuleExport.d.ts +130 -0
- package/esm/types/ModuleExport.d.ts.map +1 -1
- package/esm/types/ModuleExport.js +36 -0
- package/esm/types/PrettierConfig.d.ts +74 -0
- package/esm/types/PrettierConfig.d.ts.map +1 -1
- package/esm/types/PrettierConfig.js +74 -0
- package/esm/types/Results.d.ts +97 -0
- package/esm/types/Results.d.ts.map +1 -1
- package/esm/types/Results.js +97 -0
- package/package.json +1 -1
- package/script/oas/array/array-types.d.ts +238 -25
- package/script/oas/array/array-types.d.ts.map +1 -1
- package/script/oas/array/array-types.js +97 -5
- package/script/oas/boolean/boolean-types.d.ts +81 -9
- package/script/oas/boolean/boolean-types.d.ts.map +1 -1
- package/script/oas/boolean/boolean-types.js +32 -2
- package/script/oas/contact/contact-types.d.ts +176 -0
- package/script/oas/contact/contact-types.d.ts.map +1 -1
- package/script/oas/contact/contact-types.js +102 -0
- package/script/oas/mediaType/toMediaTypeItemV3.d.ts +288 -0
- package/script/oas/mediaType/toMediaTypeItemV3.d.ts.map +1 -1
- package/script/oas/mediaType/toMediaTypeItemV3.js +272 -0
- package/script/oas/operation/operation-types.d.ts +251 -0
- package/script/oas/operation/operation-types.d.ts.map +1 -1
- package/script/oas/operation/operation-types.js +98 -0
- package/script/oas/string/string-types.d.ts +192 -18
- package/script/oas/string/string-types.d.ts.map +1 -1
- package/script/oas/string/string-types.js +76 -4
- package/script/types/ModuleExport.d.ts +130 -0
- package/script/types/ModuleExport.d.ts.map +1 -1
- package/script/types/ModuleExport.js +36 -0
- package/script/types/PrettierConfig.d.ts +74 -0
- package/script/types/PrettierConfig.d.ts.map +1 -1
- package/script/types/PrettierConfig.js +74 -0
- package/script/types/Results.d.ts +97 -0
- package/script/types/Results.d.ts.map +1 -1
- package/script/types/Results.js +97 -0
|
@@ -40,9 +40,64 @@ const ref_types_js_1 = require("../ref/ref-types.js");
|
|
|
40
40
|
/**
|
|
41
41
|
* Valibot schema for validating OpenAPI array data objects.
|
|
42
42
|
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
* to handle recursive schema references
|
|
43
|
+
* This comprehensive schema validates OpenAPI array schemas according to the OpenAPI v3
|
|
44
|
+
* specification, including item type definitions, length constraints, uniqueness requirements,
|
|
45
|
+
* and enumeration values. It uses lazy evaluation to handle recursive schema references,
|
|
46
|
+
* allowing for complex nested array structures and self-referential schemas.
|
|
47
|
+
*
|
|
48
|
+
* The schema supports both direct schema definitions and reference objects for the items
|
|
49
|
+
* property, enabling flexible array type definitions that can reference other schemas
|
|
50
|
+
* in the document or define inline item types.
|
|
51
|
+
*
|
|
52
|
+
* @example Validating a simple array schema
|
|
53
|
+
* ```typescript
|
|
54
|
+
* import { oasArrayData } from '@skmtc/core/oas/array';
|
|
55
|
+
* import * as v from 'valibot';
|
|
56
|
+
*
|
|
57
|
+
* const schema = {
|
|
58
|
+
* type: 'array',
|
|
59
|
+
* items: {
|
|
60
|
+
* type: 'string'
|
|
61
|
+
* },
|
|
62
|
+
* description: 'List of user names',
|
|
63
|
+
* minItems: 1,
|
|
64
|
+
* maxItems: 100
|
|
65
|
+
* };
|
|
66
|
+
*
|
|
67
|
+
* const validated = v.parse(oasArrayData, schema);
|
|
68
|
+
* console.log(validated.minItems); // 1
|
|
69
|
+
* ```
|
|
70
|
+
*
|
|
71
|
+
* @example Validating array with reference items
|
|
72
|
+
* ```typescript
|
|
73
|
+
* const refArraySchema = {
|
|
74
|
+
* type: 'array',
|
|
75
|
+
* items: {
|
|
76
|
+
* $ref: '#/components/schemas/User'
|
|
77
|
+
* },
|
|
78
|
+
* title: 'User List',
|
|
79
|
+
* uniqueItems: true,
|
|
80
|
+
* default: []
|
|
81
|
+
* };
|
|
82
|
+
*
|
|
83
|
+
* const result = v.parse(oasArrayData, refArraySchema);
|
|
84
|
+
* console.log(result.uniqueItems); // true
|
|
85
|
+
* ```
|
|
86
|
+
*
|
|
87
|
+
* @example Validating constrained arrays
|
|
88
|
+
* ```typescript
|
|
89
|
+
* const constrainedArray = {
|
|
90
|
+
* type: 'array',
|
|
91
|
+
* items: { type: 'number' },
|
|
92
|
+
* minItems: 2,
|
|
93
|
+
* maxItems: 10,
|
|
94
|
+
* uniqueItems: true,
|
|
95
|
+
* enums: [[1, 2, 3], [4, 5, 6]]
|
|
96
|
+
* };
|
|
97
|
+
*
|
|
98
|
+
* const validated = v.parse(oasArrayData, constrainedArray);
|
|
99
|
+
* console.log(validated.maxItems); // 10
|
|
100
|
+
* ```
|
|
46
101
|
*/
|
|
47
102
|
exports.oasArrayData = v.object({
|
|
48
103
|
type: v.literal('array'),
|
|
@@ -58,8 +113,45 @@ exports.oasArrayData = v.object({
|
|
|
58
113
|
/**
|
|
59
114
|
* Valibot schema for array data without the items property.
|
|
60
115
|
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
116
|
+
* This specialized schema validates array schemas when the items property is processed
|
|
117
|
+
* separately from the main array constraints. It's commonly used during schema parsing
|
|
118
|
+
* and transformation processes where items need special handling, such as when resolving
|
|
119
|
+
* references or applying schema merging operations.
|
|
120
|
+
*
|
|
121
|
+
* This pattern is useful in multi-phase parsing where array constraints (like min/max
|
|
122
|
+
* items, uniqueness) are validated independently from the item type definitions,
|
|
123
|
+
* allowing for more flexible processing pipelines.
|
|
124
|
+
*
|
|
125
|
+
* @example Validating array constraints without items
|
|
126
|
+
* ```typescript
|
|
127
|
+
* import { oasArrayDataWithoutItems } from '@skmtc/core/oas/array';
|
|
128
|
+
* import * as v from 'valibot';
|
|
129
|
+
*
|
|
130
|
+
* const constraintsOnly = {
|
|
131
|
+
* type: 'array',
|
|
132
|
+
* title: 'Validation Rules',
|
|
133
|
+
* minItems: 1,
|
|
134
|
+
* maxItems: 50,
|
|
135
|
+
* uniqueItems: true,
|
|
136
|
+
* default: []
|
|
137
|
+
* };
|
|
138
|
+
*
|
|
139
|
+
* const validated = v.parse(oasArrayDataWithoutItems, constraintsOnly);
|
|
140
|
+
* console.log(validated.uniqueItems); // true
|
|
141
|
+
* ```
|
|
142
|
+
*
|
|
143
|
+
* @example Usage in two-phase parsing
|
|
144
|
+
* ```typescript
|
|
145
|
+
* function parseArraySchema(schema: unknown) {
|
|
146
|
+
* // Phase 1: Validate basic array structure
|
|
147
|
+
* const arrayConstraints = v.parse(oasArrayDataWithoutItems, schema);
|
|
148
|
+
*
|
|
149
|
+
* // Phase 2: Process items separately (not shown)
|
|
150
|
+
* const items = processItemsSchema((schema as any).items);
|
|
151
|
+
*
|
|
152
|
+
* return { ...arrayConstraints, items };
|
|
153
|
+
* }
|
|
154
|
+
* ```
|
|
63
155
|
*/
|
|
64
156
|
exports.oasArrayDataWithoutItems = v.object({
|
|
65
157
|
type: v.literal('array'),
|
|
@@ -2,27 +2,99 @@ import * as v from 'valibot';
|
|
|
2
2
|
/**
|
|
3
3
|
* Valibot schema for validating OpenAPI boolean data objects.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
5
|
+
* This schema validates OpenAPI boolean schemas according to the OpenAPI v3 specification,
|
|
6
|
+
* including optional properties like default values, enumeration constraints, title,
|
|
7
|
+
* and description metadata. Boolean enums are commonly used to restrict values to
|
|
8
|
+
* specific boolean constants (e.g., [true] for always-true flags).
|
|
9
|
+
*
|
|
10
|
+
* @example Validating a basic boolean schema
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import { oasBooleanData } from '@skmtc/core/oas/boolean';
|
|
13
|
+
* import * as v from 'valibot';
|
|
14
|
+
*
|
|
15
|
+
* const schema = {
|
|
16
|
+
* type: 'boolean',
|
|
17
|
+
* description: 'Whether the feature is enabled',
|
|
18
|
+
* default: false
|
|
19
|
+
* };
|
|
20
|
+
*
|
|
21
|
+
* const validated = v.parse(oasBooleanData, schema);
|
|
22
|
+
* console.log(validated.default); // false
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @example Validating boolean with enumeration
|
|
26
|
+
* ```typescript
|
|
27
|
+
* const constrainedBoolean = {
|
|
28
|
+
* type: 'boolean',
|
|
29
|
+
* title: 'Admin Flag',
|
|
30
|
+
* description: 'User admin status',
|
|
31
|
+
* enum: [true] // Only true values allowed
|
|
32
|
+
* };
|
|
33
|
+
*
|
|
34
|
+
* const result = v.parse(oasBooleanData, constrainedBoolean);
|
|
35
|
+
* console.log(result.enum); // [true]
|
|
36
|
+
* ```
|
|
7
37
|
*/
|
|
8
38
|
export declare const oasBooleanData: v.GenericSchema<OasBooleanData>;
|
|
9
39
|
/**
|
|
10
40
|
* Data type for OpenAPI boolean schema objects.
|
|
11
41
|
*
|
|
12
|
-
* Represents boolean schemas
|
|
13
|
-
*
|
|
14
|
-
*
|
|
42
|
+
* Represents the structure of OpenAPI boolean schemas as processed by the SKMTC pipeline.
|
|
43
|
+
* This type includes all standard OpenAPI boolean schema properties including metadata,
|
|
44
|
+
* default values, and enumeration constraints. It's used throughout the boolean
|
|
45
|
+
* processing pipeline for type-safe handling of boolean schema definitions.
|
|
46
|
+
*
|
|
47
|
+
* ## Usage in SKMTC Pipeline
|
|
48
|
+
*
|
|
49
|
+
* This type is used by:
|
|
50
|
+
* - Schema parsers to validate incoming boolean schema data
|
|
51
|
+
* - Boolean processors to transform OpenAPI schemas into OAS objects
|
|
52
|
+
* - Code generators to access boolean schema metadata and constraints
|
|
53
|
+
* - Validation systems to ensure schema compliance
|
|
54
|
+
*
|
|
55
|
+
* @example Basic boolean schema
|
|
56
|
+
* ```typescript
|
|
57
|
+
* import type { OasBooleanData } from '@skmtc/core/oas/boolean';
|
|
58
|
+
*
|
|
59
|
+
* const isActiveSchema: OasBooleanData = {
|
|
60
|
+
* type: 'boolean',
|
|
61
|
+
* title: 'Active Status',
|
|
62
|
+
* description: 'Whether the record is active',
|
|
63
|
+
* default: true
|
|
64
|
+
* };
|
|
65
|
+
* ```
|
|
66
|
+
*
|
|
67
|
+
* @example Boolean with enumeration constraints
|
|
68
|
+
* ```typescript
|
|
69
|
+
* const adminFlagSchema: OasBooleanData = {
|
|
70
|
+
* type: 'boolean',
|
|
71
|
+
* description: 'Administrative privileges flag',
|
|
72
|
+
* enum: [false, true], // Allow both values
|
|
73
|
+
* default: false
|
|
74
|
+
* };
|
|
75
|
+
* ```
|
|
76
|
+
*
|
|
77
|
+
* @example Read-only boolean flag
|
|
78
|
+
* ```typescript
|
|
79
|
+
* const systemFlagSchema: OasBooleanData = {
|
|
80
|
+
* type: 'boolean',
|
|
81
|
+
* title: 'System Generated',
|
|
82
|
+
* description: 'Indicates if the record was system-generated',
|
|
83
|
+
* enum: [true], // Always true
|
|
84
|
+
* default: true
|
|
85
|
+
* };
|
|
86
|
+
* ```
|
|
15
87
|
*/
|
|
16
88
|
export type OasBooleanData = {
|
|
17
89
|
/** Type identifier (always 'boolean') */
|
|
18
90
|
type: 'boolean';
|
|
19
|
-
/** Human-readable title for the boolean */
|
|
91
|
+
/** Human-readable title for the boolean schema */
|
|
20
92
|
title?: string;
|
|
21
|
-
/** Detailed description
|
|
93
|
+
/** Detailed description explaining the boolean's purpose and usage */
|
|
22
94
|
description?: string;
|
|
23
|
-
/** Default value
|
|
95
|
+
/** Default value used when no explicit value is provided */
|
|
24
96
|
default?: boolean;
|
|
25
|
-
/** Array of valid boolean values
|
|
97
|
+
/** Array of valid boolean values for enumeration constraints */
|
|
26
98
|
enum?: boolean[];
|
|
27
99
|
};
|
|
28
100
|
//# sourceMappingURL=boolean-types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"boolean-types.d.ts","sourceRoot":"","sources":["../../../src/oas/boolean/boolean-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAA;AAE5B
|
|
1
|
+
{"version":3,"file":"boolean-types.d.ts","sourceRoot":"","sources":["../../../src/oas/boolean/boolean-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAA;AAE5B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,eAAO,MAAM,cAAc,EAAE,CAAC,CAAC,aAAa,CAAC,cAAc,CAMzD,CAAA;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B,yCAAyC;IACzC,IAAI,EAAE,SAAS,CAAA;IACf,kDAAkD;IAClD,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,sEAAsE;IACtE,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,4DAA4D;IAC5D,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,gEAAgE;IAChE,IAAI,CAAC,EAAE,OAAO,EAAE,CAAA;CACjB,CAAA"}
|
|
@@ -38,8 +38,38 @@ const v = __importStar(require("valibot"));
|
|
|
38
38
|
/**
|
|
39
39
|
* Valibot schema for validating OpenAPI boolean data objects.
|
|
40
40
|
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
41
|
+
* This schema validates OpenAPI boolean schemas according to the OpenAPI v3 specification,
|
|
42
|
+
* including optional properties like default values, enumeration constraints, title,
|
|
43
|
+
* and description metadata. Boolean enums are commonly used to restrict values to
|
|
44
|
+
* specific boolean constants (e.g., [true] for always-true flags).
|
|
45
|
+
*
|
|
46
|
+
* @example Validating a basic boolean schema
|
|
47
|
+
* ```typescript
|
|
48
|
+
* import { oasBooleanData } from '@skmtc/core/oas/boolean';
|
|
49
|
+
* import * as v from 'valibot';
|
|
50
|
+
*
|
|
51
|
+
* const schema = {
|
|
52
|
+
* type: 'boolean',
|
|
53
|
+
* description: 'Whether the feature is enabled',
|
|
54
|
+
* default: false
|
|
55
|
+
* };
|
|
56
|
+
*
|
|
57
|
+
* const validated = v.parse(oasBooleanData, schema);
|
|
58
|
+
* console.log(validated.default); // false
|
|
59
|
+
* ```
|
|
60
|
+
*
|
|
61
|
+
* @example Validating boolean with enumeration
|
|
62
|
+
* ```typescript
|
|
63
|
+
* const constrainedBoolean = {
|
|
64
|
+
* type: 'boolean',
|
|
65
|
+
* title: 'Admin Flag',
|
|
66
|
+
* description: 'User admin status',
|
|
67
|
+
* enum: [true] // Only true values allowed
|
|
68
|
+
* };
|
|
69
|
+
*
|
|
70
|
+
* const result = v.parse(oasBooleanData, constrainedBoolean);
|
|
71
|
+
* console.log(result.enum); // [true]
|
|
72
|
+
* ```
|
|
43
73
|
*/
|
|
44
74
|
exports.oasBooleanData = v.object({
|
|
45
75
|
type: v.literal('boolean'),
|
|
@@ -1,9 +1,185 @@
|
|
|
1
1
|
import * as v from 'valibot';
|
|
2
|
+
/**
|
|
3
|
+
* Data type for OpenAPI contact information objects.
|
|
4
|
+
*
|
|
5
|
+
* This type represents contact information as specified in the OpenAPI v3 specification's
|
|
6
|
+
* Info Object. Contact information provides details about the person or organization
|
|
7
|
+
* responsible for the API, including optional name, website URL, and email address.
|
|
8
|
+
*
|
|
9
|
+
* The contact information is typically displayed in API documentation and used by
|
|
10
|
+
* developers to reach out for support, questions, or feedback about the API.
|
|
11
|
+
*
|
|
12
|
+
* ## Usage in SKMTC Pipeline
|
|
13
|
+
*
|
|
14
|
+
* This type is used by:
|
|
15
|
+
* - Info processors to validate and structure contact information
|
|
16
|
+
* - Documentation generators to display API maintainer information
|
|
17
|
+
* - Client generators to embed support contact details in generated code
|
|
18
|
+
* - Validation systems to ensure contact information completeness
|
|
19
|
+
*
|
|
20
|
+
* @example Basic contact information
|
|
21
|
+
* ```typescript
|
|
22
|
+
* import type { OasContactData } from '@skmtc/core/oas/contact';
|
|
23
|
+
*
|
|
24
|
+
* const apiContact: OasContactData = {
|
|
25
|
+
* oasType: 'contact',
|
|
26
|
+
* name: 'API Support Team',
|
|
27
|
+
* url: 'https://company.com/support',
|
|
28
|
+
* email: 'api-support@company.com'
|
|
29
|
+
* };
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @example Minimal contact with only email
|
|
33
|
+
* ```typescript
|
|
34
|
+
* const minimalContact: OasContactData = {
|
|
35
|
+
* oasType: 'contact',
|
|
36
|
+
* email: 'support@api-company.com'
|
|
37
|
+
* };
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* @example Contact with name and URL
|
|
41
|
+
* ```typescript
|
|
42
|
+
* const teamContact: OasContactData = {
|
|
43
|
+
* oasType: 'contact',
|
|
44
|
+
* name: 'Development Team',
|
|
45
|
+
* url: 'https://github.com/company/api-repo'
|
|
46
|
+
* };
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* @example Integration in OpenAPI Info object
|
|
50
|
+
* ```typescript
|
|
51
|
+
* const apiInfo = {
|
|
52
|
+
* title: 'My API',
|
|
53
|
+
* version: '1.0.0',
|
|
54
|
+
* description: 'A comprehensive API for managing resources',
|
|
55
|
+
* contact: {
|
|
56
|
+
* oasType: 'contact',
|
|
57
|
+
* name: 'Jane Doe',
|
|
58
|
+
* url: 'https://janedoe.dev',
|
|
59
|
+
* email: 'jane@company.com'
|
|
60
|
+
* }
|
|
61
|
+
* };
|
|
62
|
+
* ```
|
|
63
|
+
*
|
|
64
|
+
* @example Empty contact (valid but not recommended)
|
|
65
|
+
* ```typescript
|
|
66
|
+
* const emptyContact: OasContactData = {
|
|
67
|
+
* oasType: 'contact'
|
|
68
|
+
* // All fields are optional, but at least one should be provided
|
|
69
|
+
* };
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
2
72
|
export type OasContactData = {
|
|
73
|
+
/** Type identifier for SKMTC internal processing */
|
|
3
74
|
oasType: 'contact';
|
|
75
|
+
/** The identifying name of the contact person or organization */
|
|
4
76
|
name?: string;
|
|
77
|
+
/** The URL pointing to the contact information (website, GitHub, etc.) */
|
|
5
78
|
url?: string;
|
|
79
|
+
/** The email address of the contact person or organization */
|
|
6
80
|
email?: string;
|
|
7
81
|
};
|
|
82
|
+
/**
|
|
83
|
+
* Valibot schema for validating OpenAPI contact data objects.
|
|
84
|
+
*
|
|
85
|
+
* This schema validates OpenAPI contact information according to the OpenAPI v3
|
|
86
|
+
* specification. All contact fields are optional, allowing for flexible contact
|
|
87
|
+
* information configurations. The schema ensures proper string formatting for
|
|
88
|
+
* name, URL, and email fields while maintaining the required `oasType` identifier.
|
|
89
|
+
*
|
|
90
|
+
* Note that while all fields are optional according to the OpenAPI specification,
|
|
91
|
+
* it's recommended to provide at least one contact method for practical API usage.
|
|
92
|
+
*
|
|
93
|
+
* @example Validating complete contact information
|
|
94
|
+
* ```typescript
|
|
95
|
+
* import { oasContactData } from '@skmtc/core/oas/contact';
|
|
96
|
+
* import * as v from 'valibot';
|
|
97
|
+
*
|
|
98
|
+
* const contact = {
|
|
99
|
+
* oasType: 'contact',
|
|
100
|
+
* name: 'API Support',
|
|
101
|
+
* url: 'https://api.company.com/support',
|
|
102
|
+
* email: 'support@company.com'
|
|
103
|
+
* };
|
|
104
|
+
*
|
|
105
|
+
* const validated = v.parse(oasContactData, contact);
|
|
106
|
+
* console.log(validated.name); // 'API Support'
|
|
107
|
+
* console.log(validated.email); // 'support@company.com'
|
|
108
|
+
* ```
|
|
109
|
+
*
|
|
110
|
+
* @example Validating partial contact information
|
|
111
|
+
* ```typescript
|
|
112
|
+
* const partialContact = {
|
|
113
|
+
* oasType: 'contact',
|
|
114
|
+
* email: 'help@api.com'
|
|
115
|
+
* // name and url are optional and omitted
|
|
116
|
+
* };
|
|
117
|
+
*
|
|
118
|
+
* const result = v.parse(oasContactData, partialContact);
|
|
119
|
+
* console.log(result.email); // 'help@api.com'
|
|
120
|
+
* console.log(result.name); // undefined
|
|
121
|
+
* console.log(result.url); // undefined
|
|
122
|
+
* ```
|
|
123
|
+
*
|
|
124
|
+
* @example Validation error handling
|
|
125
|
+
* ```typescript
|
|
126
|
+
* const invalidContact = {
|
|
127
|
+
* oasType: 'contact',
|
|
128
|
+
* name: 123, // Invalid: should be string
|
|
129
|
+
* email: 'valid@email.com'
|
|
130
|
+
* };
|
|
131
|
+
*
|
|
132
|
+
* try {
|
|
133
|
+
* v.parse(oasContactData, invalidContact);
|
|
134
|
+
* } catch (error) {
|
|
135
|
+
* console.error('Contact validation failed:', error.message);
|
|
136
|
+
* // Handle validation errors appropriately
|
|
137
|
+
* }
|
|
138
|
+
* ```
|
|
139
|
+
*
|
|
140
|
+
* @example Usage in OpenAPI document processing
|
|
141
|
+
* ```typescript
|
|
142
|
+
* function processApiInfo(infoObject: unknown) {
|
|
143
|
+
* // Validate the info object structure
|
|
144
|
+
* const info = parseInfoObject(infoObject);
|
|
145
|
+
*
|
|
146
|
+
* // If contact information exists, validate it
|
|
147
|
+
* if (info.contact) {
|
|
148
|
+
* const validatedContact = v.parse(oasContactData, {
|
|
149
|
+
* oasType: 'contact',
|
|
150
|
+
* ...info.contact
|
|
151
|
+
* });
|
|
152
|
+
*
|
|
153
|
+
* console.log(`API maintained by: ${validatedContact.name || 'Unknown'}`);
|
|
154
|
+
* console.log(`Support: ${validatedContact.email || 'No email provided'}`);
|
|
155
|
+
* }
|
|
156
|
+
* }
|
|
157
|
+
* ```
|
|
158
|
+
*
|
|
159
|
+
* @example Integration with documentation generators
|
|
160
|
+
* ```typescript
|
|
161
|
+
* class DocumentationGenerator {
|
|
162
|
+
* generateContactSection(contactData: OasContactData): string {
|
|
163
|
+
* const validated = v.parse(oasContactData, contactData);
|
|
164
|
+
*
|
|
165
|
+
* let contactSection = '## Contact Information\n\n';
|
|
166
|
+
*
|
|
167
|
+
* if (validated.name) {
|
|
168
|
+
* contactSection += `**Maintainer:** ${validated.name}\n\n`;
|
|
169
|
+
* }
|
|
170
|
+
*
|
|
171
|
+
* if (validated.email) {
|
|
172
|
+
* contactSection += `**Email:** [${validated.email}](mailto:${validated.email})\n\n`;
|
|
173
|
+
* }
|
|
174
|
+
*
|
|
175
|
+
* if (validated.url) {
|
|
176
|
+
* contactSection += `**Website:** [${validated.url}](${validated.url})\n\n`;
|
|
177
|
+
* }
|
|
178
|
+
*
|
|
179
|
+
* return contactSection;
|
|
180
|
+
* }
|
|
181
|
+
* }
|
|
182
|
+
* ```
|
|
183
|
+
*/
|
|
8
184
|
export declare const oasContactData: v.GenericSchema<OasContactData>;
|
|
9
185
|
//# sourceMappingURL=contact-types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contact-types.d.ts","sourceRoot":"","sources":["../../../src/oas/contact/contact-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAA;AAE5B,MAAM,MAAM,cAAc,GAAG;IAC3B,OAAO,EAAE,SAAS,CAAA;IAClB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,CAAA;AAED,eAAO,MAAM,cAAc,EAAE,CAAC,CAAC,aAAa,CAAC,cAAc,CAKzD,CAAA"}
|
|
1
|
+
{"version":3,"file":"contact-types.d.ts","sourceRoot":"","sources":["../../../src/oas/contact/contact-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAA;AAE5B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqEG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B,oDAAoD;IACpD,OAAO,EAAE,SAAS,CAAA;IAClB,iEAAiE;IACjE,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,0EAA0E;IAC1E,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,8DAA8D;IAC9D,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqGG;AACH,eAAO,MAAM,cAAc,EAAE,CAAC,CAAC,aAAa,CAAC,cAAc,CAKzD,CAAA"}
|
|
@@ -35,6 +35,108 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.oasContactData = void 0;
|
|
37
37
|
const v = __importStar(require("valibot"));
|
|
38
|
+
/**
|
|
39
|
+
* Valibot schema for validating OpenAPI contact data objects.
|
|
40
|
+
*
|
|
41
|
+
* This schema validates OpenAPI contact information according to the OpenAPI v3
|
|
42
|
+
* specification. All contact fields are optional, allowing for flexible contact
|
|
43
|
+
* information configurations. The schema ensures proper string formatting for
|
|
44
|
+
* name, URL, and email fields while maintaining the required `oasType` identifier.
|
|
45
|
+
*
|
|
46
|
+
* Note that while all fields are optional according to the OpenAPI specification,
|
|
47
|
+
* it's recommended to provide at least one contact method for practical API usage.
|
|
48
|
+
*
|
|
49
|
+
* @example Validating complete contact information
|
|
50
|
+
* ```typescript
|
|
51
|
+
* import { oasContactData } from '@skmtc/core/oas/contact';
|
|
52
|
+
* import * as v from 'valibot';
|
|
53
|
+
*
|
|
54
|
+
* const contact = {
|
|
55
|
+
* oasType: 'contact',
|
|
56
|
+
* name: 'API Support',
|
|
57
|
+
* url: 'https://api.company.com/support',
|
|
58
|
+
* email: 'support@company.com'
|
|
59
|
+
* };
|
|
60
|
+
*
|
|
61
|
+
* const validated = v.parse(oasContactData, contact);
|
|
62
|
+
* console.log(validated.name); // 'API Support'
|
|
63
|
+
* console.log(validated.email); // 'support@company.com'
|
|
64
|
+
* ```
|
|
65
|
+
*
|
|
66
|
+
* @example Validating partial contact information
|
|
67
|
+
* ```typescript
|
|
68
|
+
* const partialContact = {
|
|
69
|
+
* oasType: 'contact',
|
|
70
|
+
* email: 'help@api.com'
|
|
71
|
+
* // name and url are optional and omitted
|
|
72
|
+
* };
|
|
73
|
+
*
|
|
74
|
+
* const result = v.parse(oasContactData, partialContact);
|
|
75
|
+
* console.log(result.email); // 'help@api.com'
|
|
76
|
+
* console.log(result.name); // undefined
|
|
77
|
+
* console.log(result.url); // undefined
|
|
78
|
+
* ```
|
|
79
|
+
*
|
|
80
|
+
* @example Validation error handling
|
|
81
|
+
* ```typescript
|
|
82
|
+
* const invalidContact = {
|
|
83
|
+
* oasType: 'contact',
|
|
84
|
+
* name: 123, // Invalid: should be string
|
|
85
|
+
* email: 'valid@email.com'
|
|
86
|
+
* };
|
|
87
|
+
*
|
|
88
|
+
* try {
|
|
89
|
+
* v.parse(oasContactData, invalidContact);
|
|
90
|
+
* } catch (error) {
|
|
91
|
+
* console.error('Contact validation failed:', error.message);
|
|
92
|
+
* // Handle validation errors appropriately
|
|
93
|
+
* }
|
|
94
|
+
* ```
|
|
95
|
+
*
|
|
96
|
+
* @example Usage in OpenAPI document processing
|
|
97
|
+
* ```typescript
|
|
98
|
+
* function processApiInfo(infoObject: unknown) {
|
|
99
|
+
* // Validate the info object structure
|
|
100
|
+
* const info = parseInfoObject(infoObject);
|
|
101
|
+
*
|
|
102
|
+
* // If contact information exists, validate it
|
|
103
|
+
* if (info.contact) {
|
|
104
|
+
* const validatedContact = v.parse(oasContactData, {
|
|
105
|
+
* oasType: 'contact',
|
|
106
|
+
* ...info.contact
|
|
107
|
+
* });
|
|
108
|
+
*
|
|
109
|
+
* console.log(`API maintained by: ${validatedContact.name || 'Unknown'}`);
|
|
110
|
+
* console.log(`Support: ${validatedContact.email || 'No email provided'}`);
|
|
111
|
+
* }
|
|
112
|
+
* }
|
|
113
|
+
* ```
|
|
114
|
+
*
|
|
115
|
+
* @example Integration with documentation generators
|
|
116
|
+
* ```typescript
|
|
117
|
+
* class DocumentationGenerator {
|
|
118
|
+
* generateContactSection(contactData: OasContactData): string {
|
|
119
|
+
* const validated = v.parse(oasContactData, contactData);
|
|
120
|
+
*
|
|
121
|
+
* let contactSection = '## Contact Information\n\n';
|
|
122
|
+
*
|
|
123
|
+
* if (validated.name) {
|
|
124
|
+
* contactSection += `**Maintainer:** ${validated.name}\n\n`;
|
|
125
|
+
* }
|
|
126
|
+
*
|
|
127
|
+
* if (validated.email) {
|
|
128
|
+
* contactSection += `**Email:** [${validated.email}](mailto:${validated.email})\n\n`;
|
|
129
|
+
* }
|
|
130
|
+
*
|
|
131
|
+
* if (validated.url) {
|
|
132
|
+
* contactSection += `**Website:** [${validated.url}](${validated.url})\n\n`;
|
|
133
|
+
* }
|
|
134
|
+
*
|
|
135
|
+
* return contactSection;
|
|
136
|
+
* }
|
|
137
|
+
* }
|
|
138
|
+
* ```
|
|
139
|
+
*/
|
|
38
140
|
exports.oasContactData = v.object({
|
|
39
141
|
oasType: v.literal('contact'),
|
|
40
142
|
name: v.optional(v.string()),
|