@skmtc/core 0.0.785 → 0.0.786

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.
Files changed (47) hide show
  1. package/esm/dsl/Identifier.d.ts +152 -0
  2. package/esm/dsl/Identifier.d.ts.map +1 -1
  3. package/esm/dsl/Identifier.js +152 -0
  4. package/esm/dsl/Import.d.ts +221 -0
  5. package/esm/dsl/Import.d.ts.map +1 -1
  6. package/esm/dsl/Import.js +202 -0
  7. package/esm/dsl/operation/OperationBase.d.ts +181 -1
  8. package/esm/dsl/operation/OperationBase.d.ts.map +1 -1
  9. package/esm/dsl/operation/OperationBase.js +181 -1
  10. package/esm/oas/document/Document.d.ts +155 -1
  11. package/esm/oas/document/Document.d.ts.map +1 -1
  12. package/esm/oas/document/Document.js +141 -2
  13. package/esm/oas/object/Object.d.ts +255 -10
  14. package/esm/oas/object/Object.d.ts.map +1 -1
  15. package/esm/oas/object/Object.js +229 -10
  16. package/esm/types/GeneratorKeys.d.ts +336 -0
  17. package/esm/types/GeneratorKeys.d.ts.map +1 -1
  18. package/esm/types/GeneratorKeys.js +243 -0
  19. package/esm/types/GeneratorType.d.ts +119 -0
  20. package/esm/types/GeneratorType.d.ts.map +1 -1
  21. package/esm/types/Method.d.ts +109 -0
  22. package/esm/types/Method.d.ts.map +1 -1
  23. package/esm/types/Method.js +84 -0
  24. package/package.json +1 -1
  25. package/script/dsl/Identifier.d.ts +152 -0
  26. package/script/dsl/Identifier.d.ts.map +1 -1
  27. package/script/dsl/Identifier.js +152 -0
  28. package/script/dsl/Import.d.ts +221 -0
  29. package/script/dsl/Import.d.ts.map +1 -1
  30. package/script/dsl/Import.js +202 -0
  31. package/script/dsl/operation/OperationBase.d.ts +181 -1
  32. package/script/dsl/operation/OperationBase.d.ts.map +1 -1
  33. package/script/dsl/operation/OperationBase.js +181 -1
  34. package/script/oas/document/Document.d.ts +155 -1
  35. package/script/oas/document/Document.d.ts.map +1 -1
  36. package/script/oas/document/Document.js +141 -2
  37. package/script/oas/object/Object.d.ts +255 -10
  38. package/script/oas/object/Object.d.ts.map +1 -1
  39. package/script/oas/object/Object.js +229 -10
  40. package/script/types/GeneratorKeys.d.ts +336 -0
  41. package/script/types/GeneratorKeys.d.ts.map +1 -1
  42. package/script/types/GeneratorKeys.js +243 -0
  43. package/script/types/GeneratorType.d.ts +119 -0
  44. package/script/types/GeneratorType.d.ts.map +1 -1
  45. package/script/types/Method.d.ts +109 -0
  46. package/script/types/Method.d.ts.map +1 -1
  47. package/script/types/Method.js +84 -0
@@ -8,23 +8,156 @@ import type { OasSecurityRequirement } from '../securityRequirement/SecurityRequ
8
8
  import type { StackTrail } from '../../context/StackTrail.js';
9
9
  import type { OasSchema } from '../schema/Schema.js';
10
10
  import type { OasRef } from '../ref/Ref.js';
11
+ /**
12
+ * Fields that define the structure of an OpenAPI v3 document.
13
+ *
14
+ * This type represents the normalized structure of an OpenAPI document after
15
+ * parsing, with operations flattened from the nested paths structure into
16
+ * a simple array for easier processing.
17
+ */
11
18
  export type DocumentFields = {
19
+ /** OpenAPI specification version (e.g., '3.0.0', '3.1.0') */
12
20
  openapi: string;
21
+ /** API metadata including title, version, description */
13
22
  info: OasInfo;
23
+ /** Array of server objects providing connectivity information */
14
24
  servers?: OasServer[] | undefined;
25
+ /** Flattened array of all operations from all paths */
15
26
  operations: OasOperation[];
27
+ /** Container for reusable components (schemas, responses, etc.) */
16
28
  components?: OasComponents | undefined;
29
+ /** List of tags used by operations with additional metadata */
17
30
  tags?: OasTag[] | undefined;
31
+ /** Default security requirements that apply to all operations */
18
32
  security?: OasSecurityRequirement[] | undefined;
33
+ /** Custom extension fields (x-* properties) */
19
34
  extensionFields?: Record<string, unknown>;
20
35
  };
21
- /** Top level document object describing the API */
36
+ /**
37
+ * Represents a complete OpenAPI v3 document in the SKMTC OAS processing system.
38
+ *
39
+ * The `OasDocument` class is the root object in the OAS hierarchy, containing all
40
+ * the information needed to describe a complete REST API. It provides normalized
41
+ * access to document properties with built-in validation and error handling.
42
+ *
43
+ * ## Key Features
44
+ *
45
+ * - **Normalized Structure**: Operations are flattened from nested paths for easier processing
46
+ * - **Lazy Initialization**: Fields are set after construction during parsing
47
+ * - **Type Safety**: All properties are typed and validated on access
48
+ * - **Extensibility**: Supports OpenAPI extension fields (x-* properties)
49
+ * - **JSON Serialization**: Can be converted back to standard OpenAPI JSON format
50
+ *
51
+ * @example Basic document access
52
+ * ```typescript
53
+ * import { OasDocument } from '@skmtc/core';
54
+ *
55
+ * // Document is typically created during parsing
56
+ * const document = new OasDocument();
57
+ * document.fields = {
58
+ * openapi: '3.0.0',
59
+ * info: { title: 'My API', version: '1.0.0' },
60
+ * operations: [
61
+ * // ... parsed operations
62
+ * ],
63
+ * components: {
64
+ * schemas: {
65
+ * User: { type: 'object', properties: { id: { type: 'string' } } }
66
+ * }
67
+ * }
68
+ * };
69
+ *
70
+ * console.log(document.info.title); // 'My API'
71
+ * console.log(document.operations.length); // Number of operations
72
+ * ```
73
+ *
74
+ * @example Iterating over operations
75
+ * ```typescript
76
+ * // Process all operations in the document
77
+ * for (const operation of document.operations) {
78
+ * console.log(`${operation.method.toUpperCase()} ${operation.path}`);
79
+ *
80
+ * if (operation.operationId) {
81
+ * console.log(`Operation ID: ${operation.operationId}`);
82
+ * }
83
+ * }
84
+ * ```
85
+ *
86
+ * @example Working with components
87
+ * ```typescript
88
+ * if (document.components?.schemas) {
89
+ * const userSchema = document.components.schemas.get('User');
90
+ * if (userSchema) {
91
+ * console.log('User schema found:', userSchema);
92
+ * }
93
+ * }
94
+ * ```
95
+ */
22
96
  export declare class OasDocument {
23
97
  #private;
24
98
  /** Static identifier property for OasDocument */
25
99
  oasType: 'openapi';
100
+ /**
101
+ * Creates a new OasDocument instance.
102
+ *
103
+ * The document is typically created with undefined fields and populated
104
+ * later during the parsing process. This allows for lazy initialization
105
+ * and proper error handling during document processing.
106
+ *
107
+ * @param fields - Optional document fields (usually set later during parsing)
108
+ *
109
+ * @example
110
+ * ```typescript
111
+ * // Usually created without fields during parsing
112
+ * const document = new OasDocument();
113
+ *
114
+ * // Fields are set later by the parser
115
+ * document.fields = parsedDocumentFields;
116
+ * ```
117
+ */
26
118
  constructor(fields?: DocumentFields);
119
+ /**
120
+ * Removes an item from the document based on a stack trail path.
121
+ *
122
+ * This method is used internally during document processing to remove
123
+ * specific operations or schema components. The stack trail indicates
124
+ * the path to the item within the document structure.
125
+ *
126
+ * @param stackTrail - Path to the item to remove
127
+ * @returns The removed item, or undefined if not found
128
+ *
129
+ * @internal This method is primarily used by the processing pipeline
130
+ *
131
+ * @example
132
+ * ```typescript
133
+ * // Remove an operation at /users POST
134
+ * const removed = document.removeItem(new StackTrail(['paths', '/users', 'post']));
135
+ *
136
+ * // Remove a schema component
137
+ * const removedSchema = document.removeItem(new StackTrail(['components', 'schemas', 'User']));
138
+ * ```
139
+ */
27
140
  removeItem(stackTrail: StackTrail): OasOperation | OasSchema | OasRef<'schema'> | undefined;
141
+ /**
142
+ * Sets the document fields after parsing.
143
+ *
144
+ * This setter is called by the parsing pipeline to populate the document
145
+ * with parsed OpenAPI data. It enables lazy initialization and proper
146
+ * error handling during document processing.
147
+ *
148
+ * @param fields - The parsed document fields
149
+ *
150
+ * @example
151
+ * ```typescript
152
+ * const document = new OasDocument();
153
+ * document.fields = {
154
+ * openapi: '3.0.0',
155
+ * info: { title: 'API', version: '1.0' },
156
+ * operations: [],
157
+ * // ... other fields
158
+ * };
159
+ * ```
160
+ */
28
161
  set fields(fields: DocumentFields);
29
162
  /** OpenAPI specification version */
30
163
  get openapi(): string;
@@ -41,6 +174,27 @@ export declare class OasDocument {
41
174
  get security(): OasSecurityRequirement[] | undefined;
42
175
  /** Specification Extension fields */
43
176
  get extensionFields(): Record<string, unknown> | undefined;
177
+ /**
178
+ * Converts the document back to a JSON-serializable OpenAPI object.
179
+ *
180
+ * This method serializes the document to a standard OpenAPI v3 format,
181
+ * which can be used for output, validation, or further processing. The
182
+ * resulting object follows the OpenAPI specification structure.
183
+ *
184
+ * @returns A JSON-serializable object representing the OpenAPI document
185
+ *
186
+ * @example
187
+ * ```typescript
188
+ * // Convert document back to standard OpenAPI format
189
+ * const openApiJson = document.toJSON();
190
+ *
191
+ * // Can be stringified for output
192
+ * const yamlString = JSON.stringify(openApiJson, null, 2);
193
+ *
194
+ * // Or used with OpenAPI tools
195
+ * await validateOpenApiDocument(openApiJson);
196
+ * ```
197
+ */
44
198
  toJSON(): object;
45
199
  }
46
200
  //# sourceMappingURL=Document.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Document.d.ts","sourceRoot":"","sources":["../../../src/oas/document/Document.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAA;AAChE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAC7D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AAC9C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AACpD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,+CAA+C,CAAA;AAC3F,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAA;AAG7D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AACpD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AAE3C,MAAM,MAAM,cAAc,GAAG;IAC3B,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,EAAE,OAAO,CAAA;IACb,OAAO,CAAC,EAAE,SAAS,EAAE,GAAG,SAAS,CAAA;IACjC,UAAU,EAAE,YAAY,EAAE,CAAA;IAC1B,UAAU,CAAC,EAAE,aAAa,GAAG,SAAS,CAAA;IACtC,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,SAAS,CAAA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AAS;IA6B3F;;;;;;;;;;;;;;;;;;;OAmBG;IACH,IAAI,MAAM,CAAC,MAAM,EAAE,cAAc,EAEhC;IAED,oCAAoC;IACpC,IAAI,OAAO,IAAI,MAAM,CAMpB;IAED,mBAAmB;IACnB,IAAI,IAAI,IAAI,OAAO,CAMlB;IAED,IAAI,OAAO,IAAI,SAAS,EAAE,GAAG,SAAS,CAMrC;IAED,yCAAyC;IACzC,IAAI,UAAU,IAAI,YAAY,EAAE,CAM/B;IAED,iEAAiE;IACjE,IAAI,UAAU,IAAI,aAAa,GAAG,SAAS,CAM1C;IAED,wDAAwD;IACxD,IAAI,IAAI,IAAI,MAAM,EAAE,GAAG,SAAS,CAM/B;IAED,gDAAgD;IAChD,IAAI,QAAQ,IAAI,sBAAsB,EAAE,GAAG,SAAS,CAMnD;IAED,qCAAqC;IACrC,IAAI,eAAe,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAMzD;IAED;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,MAAM,IAAI,MAAM;CAYjB"}
@@ -12,8 +12,85 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
12
12
  var _OasDocument_fields;
13
13
  import "../../_dnt.polyfills.js";
14
14
  import { match } from 'ts-pattern';
15
- /** Top level document object describing the API */
15
+ /**
16
+ * Represents a complete OpenAPI v3 document in the SKMTC OAS processing system.
17
+ *
18
+ * The `OasDocument` class is the root object in the OAS hierarchy, containing all
19
+ * the information needed to describe a complete REST API. It provides normalized
20
+ * access to document properties with built-in validation and error handling.
21
+ *
22
+ * ## Key Features
23
+ *
24
+ * - **Normalized Structure**: Operations are flattened from nested paths for easier processing
25
+ * - **Lazy Initialization**: Fields are set after construction during parsing
26
+ * - **Type Safety**: All properties are typed and validated on access
27
+ * - **Extensibility**: Supports OpenAPI extension fields (x-* properties)
28
+ * - **JSON Serialization**: Can be converted back to standard OpenAPI JSON format
29
+ *
30
+ * @example Basic document access
31
+ * ```typescript
32
+ * import { OasDocument } from '@skmtc/core';
33
+ *
34
+ * // Document is typically created during parsing
35
+ * const document = new OasDocument();
36
+ * document.fields = {
37
+ * openapi: '3.0.0',
38
+ * info: { title: 'My API', version: '1.0.0' },
39
+ * operations: [
40
+ * // ... parsed operations
41
+ * ],
42
+ * components: {
43
+ * schemas: {
44
+ * User: { type: 'object', properties: { id: { type: 'string' } } }
45
+ * }
46
+ * }
47
+ * };
48
+ *
49
+ * console.log(document.info.title); // 'My API'
50
+ * console.log(document.operations.length); // Number of operations
51
+ * ```
52
+ *
53
+ * @example Iterating over operations
54
+ * ```typescript
55
+ * // Process all operations in the document
56
+ * for (const operation of document.operations) {
57
+ * console.log(`${operation.method.toUpperCase()} ${operation.path}`);
58
+ *
59
+ * if (operation.operationId) {
60
+ * console.log(`Operation ID: ${operation.operationId}`);
61
+ * }
62
+ * }
63
+ * ```
64
+ *
65
+ * @example Working with components
66
+ * ```typescript
67
+ * if (document.components?.schemas) {
68
+ * const userSchema = document.components.schemas.get('User');
69
+ * if (userSchema) {
70
+ * console.log('User schema found:', userSchema);
71
+ * }
72
+ * }
73
+ * ```
74
+ */
16
75
  export class OasDocument {
76
+ /**
77
+ * Creates a new OasDocument instance.
78
+ *
79
+ * The document is typically created with undefined fields and populated
80
+ * later during the parsing process. This allows for lazy initialization
81
+ * and proper error handling during document processing.
82
+ *
83
+ * @param fields - Optional document fields (usually set later during parsing)
84
+ *
85
+ * @example
86
+ * ```typescript
87
+ * // Usually created without fields during parsing
88
+ * const document = new OasDocument();
89
+ *
90
+ * // Fields are set later by the parser
91
+ * document.fields = parsedDocumentFields;
92
+ * ```
93
+ */
17
94
  constructor(fields) {
18
95
  /** Static identifier property for OasDocument */
19
96
  Object.defineProperty(this, "oasType", {
@@ -22,10 +99,31 @@ export class OasDocument {
22
99
  writable: true,
23
100
  value: 'openapi'
24
101
  });
25
- /** @internal */
102
+ /** @internal Private fields storage */
26
103
  _OasDocument_fields.set(this, void 0);
27
104
  __classPrivateFieldSet(this, _OasDocument_fields, fields, "f");
28
105
  }
106
+ /**
107
+ * Removes an item from the document based on a stack trail path.
108
+ *
109
+ * This method is used internally during document processing to remove
110
+ * specific operations or schema components. The stack trail indicates
111
+ * the path to the item within the document structure.
112
+ *
113
+ * @param stackTrail - Path to the item to remove
114
+ * @returns The removed item, or undefined if not found
115
+ *
116
+ * @internal This method is primarily used by the processing pipeline
117
+ *
118
+ * @example
119
+ * ```typescript
120
+ * // Remove an operation at /users POST
121
+ * const removed = document.removeItem(new StackTrail(['paths', '/users', 'post']));
122
+ *
123
+ * // Remove a schema component
124
+ * const removedSchema = document.removeItem(new StackTrail(['components', 'schemas', 'User']));
125
+ * ```
126
+ */
29
127
  removeItem(stackTrail) {
30
128
  const [first, second, third] = stackTrail.stackTrail;
31
129
  return match(first)
@@ -47,6 +145,26 @@ export class OasDocument {
47
145
  throw new Error(`Unexpected stack trail: ${stackTrail}`);
48
146
  });
49
147
  }
148
+ /**
149
+ * Sets the document fields after parsing.
150
+ *
151
+ * This setter is called by the parsing pipeline to populate the document
152
+ * with parsed OpenAPI data. It enables lazy initialization and proper
153
+ * error handling during document processing.
154
+ *
155
+ * @param fields - The parsed document fields
156
+ *
157
+ * @example
158
+ * ```typescript
159
+ * const document = new OasDocument();
160
+ * document.fields = {
161
+ * openapi: '3.0.0',
162
+ * info: { title: 'API', version: '1.0' },
163
+ * operations: [],
164
+ * // ... other fields
165
+ * };
166
+ * ```
167
+ */
50
168
  set fields(fields) {
51
169
  __classPrivateFieldSet(this, _OasDocument_fields, fields, "f");
52
170
  }
@@ -105,6 +223,27 @@ export class OasDocument {
105
223
  }
106
224
  return __classPrivateFieldGet(this, _OasDocument_fields, "f").extensionFields;
107
225
  }
226
+ /**
227
+ * Converts the document back to a JSON-serializable OpenAPI object.
228
+ *
229
+ * This method serializes the document to a standard OpenAPI v3 format,
230
+ * which can be used for output, validation, or further processing. The
231
+ * resulting object follows the OpenAPI specification structure.
232
+ *
233
+ * @returns A JSON-serializable object representing the OpenAPI document
234
+ *
235
+ * @example
236
+ * ```typescript
237
+ * // Convert document back to standard OpenAPI format
238
+ * const openApiJson = document.toJSON();
239
+ *
240
+ * // Can be stringified for output
241
+ * const yamlString = JSON.stringify(openApiJson, null, 2);
242
+ *
243
+ * // Or used with OpenAPI tools
244
+ * await validateOpenApiDocument(openApiJson);
245
+ * ```
246
+ */
108
247
  toJSON() {
109
248
  return {
110
249
  openapi: this.openapi,
@@ -3,32 +3,138 @@ import type { OasRef } from '../ref/Ref.js';
3
3
  import type { OasSchema, ToJsonSchemaOptions } from '../schema/Schema.js';
4
4
  import type { CustomValue } from '../../types/CustomValue.js';
5
5
  import type { OpenAPIV3 } from 'openapi-types';
6
+ /**
7
+ * Constructor fields for {@link OasObject}.
8
+ *
9
+ * @template Nullable - Whether the object can be null (affects type unions)
10
+ */
6
11
  export type OasObjectFields<Nullable extends boolean | undefined> = {
12
+ /** A short summary of the object */
7
13
  title?: string;
14
+ /** A description of the object */
8
15
  description?: string;
16
+ /** Record mapping property names to their schemas */
9
17
  properties?: Record<string, OasSchema | OasRef<'schema'> | CustomValue> | undefined;
18
+ /** Array of required property names */
10
19
  required?: string[] | undefined;
20
+ /** Default value for the object (null allowed if Nullable is true) */
11
21
  default?: Nullable extends true ? Record<string, unknown> | null | undefined : Record<string, unknown> | undefined;
22
+ /** Whether additional properties are allowed (true/false/schema) */
12
23
  additionalProperties?: boolean | OasSchema | OasRef<'schema'> | undefined;
24
+ /** Whether the object value can be null */
13
25
  nullable?: Nullable;
26
+ /** Maximum number of properties allowed */
14
27
  maxProperties?: number;
28
+ /** Minimum number of properties required */
15
29
  minProperties?: number;
30
+ /** Array of valid enum values for the object */
16
31
  enums?: Nullable extends true ? (Record<string, unknown> | null)[] | undefined : Record<string, unknown>[] | undefined;
32
+ /** Custom extension fields (x-* properties) */
17
33
  extensionFields?: Record<string, unknown>;
34
+ /** Example value for the object (null allowed if Nullable is true) */
18
35
  example?: Nullable extends true ? Record<string, unknown> | null | undefined : Record<string, unknown> | undefined;
36
+ /** Whether the object is read-only */
19
37
  readOnly?: boolean;
38
+ /** Whether the object is write-only */
20
39
  writeOnly?: boolean;
40
+ /** Whether the object is deprecated */
21
41
  deprecated?: boolean;
22
42
  };
43
+ /**
44
+ * Arguments for the {@link OasObject.addProperty} method.
45
+ */
23
46
  export type AddPropertyArgs = {
47
+ /** The name of the property to add */
24
48
  name: string;
49
+ /** The schema definition for the property */
25
50
  schema: OasSchema | OasRef<'schema'> | CustomValue | undefined;
51
+ /** Whether the property should be required */
26
52
  required?: boolean;
27
53
  };
28
54
  /**
29
- * Object representing an object and/or a record in the OpenAPI Specification.
55
+ * Represents an object schema in the OpenAPI Specification.
56
+ *
57
+ * `OasObject` handles both:
58
+ * - **Objects**: Types with fixed, named properties (like TypeScript interfaces)
59
+ * - **Records**: Types with dynamic keys and consistent value types (like TypeScript Record<string, T>)
60
+ *
61
+ * This class provides comprehensive support for object validation constraints,
62
+ * property management, and JSON Schema conversion. It supports nullable types
63
+ * through generic type parameters and handles complex property relationships.
64
+ *
65
+ * ## Key Features
66
+ *
67
+ * - **Property Management**: Add/remove properties with automatic required field handling
68
+ * - **Type Safety**: Generic nullable type support with proper TypeScript inference
69
+ * - **Validation**: Min/max properties, additional properties, and enum constraints
70
+ * - **JSON Schema**: Convert to standard JSON Schema format for validation
71
+ * - **Immutability**: All mutations return new instances (functional style)
72
+ *
73
+ * @template Nullable - Whether the object value itself can be null
74
+ *
75
+ * @example Basic object schema
76
+ * ```typescript
77
+ * import { OasObject } from '@skmtc/core';
78
+ *
79
+ * const userObject = new OasObject({
80
+ * title: 'User',
81
+ * description: 'A user in the system',
82
+ * properties: {
83
+ * id: new OasString({ title: 'User ID' }),
84
+ * name: new OasString({ title: 'Full Name' }),
85
+ * email: new OasString({ format: 'email' })
86
+ * },
87
+ * required: ['id', 'name'],
88
+ * additionalProperties: false
89
+ * });
90
+ * ```
30
91
  *
31
- * Objects have fixed, named fields. Records have any number of fields that do not have predefined names.
92
+ * @example Dynamic property management
93
+ * ```typescript
94
+ * // Start with empty object
95
+ * let schema = OasObject.empty();
96
+ *
97
+ * // Add properties dynamically
98
+ * schema = schema.addProperty({
99
+ * name: 'id',
100
+ * schema: new OasString(),
101
+ * required: true
102
+ * });
103
+ *
104
+ * schema = schema.addProperty({
105
+ * name: 'metadata',
106
+ * schema: new OasObject({ additionalProperties: true }),
107
+ * required: false
108
+ * });
109
+ *
110
+ * // Remove a property
111
+ * schema = schema.removeProperty('metadata');
112
+ * ```
113
+ *
114
+ * @example Record-style object (additional properties)
115
+ * ```typescript
116
+ * const recordObject = new OasObject({
117
+ * title: 'StringMap',
118
+ * description: 'A map of string keys to string values',
119
+ * additionalProperties: new OasString(), // Any string key -> string value
120
+ * minProperties: 1 // At least one property required
121
+ * });
122
+ *
123
+ * // This allows: { [key: string]: string }
124
+ * ```
125
+ *
126
+ * @example Nullable object support
127
+ * ```typescript
128
+ * const nullableUser = new OasObject<true>({
129
+ * nullable: true,
130
+ * properties: {
131
+ * name: new OasString()
132
+ * },
133
+ * default: null // Can have null default when nullable
134
+ * });
135
+ *
136
+ * // This represents: { name: string } | null
137
+ * ```
32
138
  */
33
139
  export declare class OasObject<Nullable extends boolean | undefined = boolean | undefined> {
34
140
  /**
@@ -82,29 +188,168 @@ export declare class OasObject<Nullable extends boolean | undefined = boolean |
82
188
  writeOnly?: boolean;
83
189
  deprecated?: boolean;
84
190
  enums?: Nullable extends true ? (Record<string, unknown> | null)[] | undefined : Record<string, unknown>[] | undefined;
191
+ /**
192
+ * Creates a new OasObject instance.
193
+ *
194
+ * @param fields - Object configuration fields
195
+ *
196
+ * @example
197
+ * ```typescript
198
+ * const userSchema = new OasObject({
199
+ * title: 'User',
200
+ * properties: {
201
+ * id: new OasString({ title: 'ID' }),
202
+ * name: new OasString({ title: 'Name' })
203
+ * },
204
+ * required: ['id'],
205
+ * additionalProperties: false
206
+ * });
207
+ * ```
208
+ */
85
209
  constructor(fields?: OasObjectFields<Nullable>);
86
- /** Creates new empty OasObject */
210
+ /**
211
+ * Creates a new empty OasObject with no properties.
212
+ *
213
+ * This factory method creates a non-nullable object with empty properties
214
+ * and required arrays, useful as a starting point for dynamic object building.
215
+ *
216
+ * @returns A new empty OasObject instance
217
+ *
218
+ * @example
219
+ * ```typescript
220
+ * // Start with empty object and build up
221
+ * let schema = OasObject.empty();
222
+ *
223
+ * schema = schema.addProperty({
224
+ * name: 'id',
225
+ * schema: new OasString(),
226
+ * required: true
227
+ * });
228
+ *
229
+ * schema = schema.addProperty({
230
+ * name: 'name',
231
+ * schema: new OasString(),
232
+ * required: true
233
+ * });
234
+ * ```
235
+ */
87
236
  static empty(): OasObject<false>;
88
237
  /**
89
238
  * Adds a new property to the object.
90
239
  *
91
- * @param {AddPropertyArgs} args - The arguments for adding a property.
92
- * @param {string} args.name - The name of the property to add.
93
- * @param {OasSchema | OasRef<'schema'> | CustomValue | undefined} args.schema - The schema of the property to add.
94
- * @param {boolean} args.required - Whether the property is required.
95
- * @returns {OasObject} A new OasObject with the added property.
240
+ * This method returns a new OasObject instance with the added property,
241
+ * following an immutable pattern. If the property is marked as required,
242
+ * it will be added to the required array.
243
+ *
244
+ * @param args - Property addition arguments
245
+ * @param args.name - The name of the property to add
246
+ * @param args.schema - The schema definition for the property
247
+ * @param args.required - Whether the property should be required (default: false)
248
+ * @returns A new OasObject with the added property
249
+ *
250
+ * @example Adding a simple property
251
+ * ```typescript
252
+ * const original = OasObject.empty();
253
+ * const withName = original.addProperty({
254
+ * name: 'username',
255
+ * schema: new OasString({ minLength: 3 }),
256
+ * required: true
257
+ * });
258
+ *
259
+ * console.log(withName.required); // ['username']
260
+ * ```
261
+ *
262
+ * @example Chaining property additions
263
+ * ```typescript
264
+ * const userSchema = OasObject.empty()
265
+ * .addProperty({
266
+ * name: 'id',
267
+ * schema: new OasInteger(),
268
+ * required: true
269
+ * })
270
+ * .addProperty({
271
+ * name: 'email',
272
+ * schema: new OasString({ format: 'email' }),
273
+ * required: true
274
+ * })
275
+ * .addProperty({
276
+ * name: 'age',
277
+ * schema: new OasInteger({ minimum: 0 }),
278
+ * required: false
279
+ * });
280
+ * ```
96
281
  */
97
282
  addProperty({ name, schema, required }: AddPropertyArgs): OasObject;
98
283
  /**
99
284
  * Removes a property from the object.
100
285
  *
101
- * @param {string} name - The name of the property to remove.
102
- * @returns {OasObject} A new OasObject with the removed property.
286
+ * This method returns a new OasObject instance with the specified property
287
+ * removed. If the property was required, it will also be removed from the
288
+ * required array. If the property doesn't exist, returns the same instance.
289
+ *
290
+ * @param name - The name of the property to remove
291
+ * @returns A new OasObject with the property removed, or the same instance if property doesn't exist
292
+ *
293
+ * @example
294
+ * ```typescript
295
+ * const userSchema = new OasObject({
296
+ * properties: {
297
+ * id: new OasString(),
298
+ * name: new OasString(),
299
+ * email: new OasString(),
300
+ * temporaryField: new OasString()
301
+ * },
302
+ * required: ['id', 'name', 'temporaryField']
303
+ * });
304
+ *
305
+ * // Remove temporary field
306
+ * const cleanedSchema = userSchema.removeProperty('temporaryField');
307
+ *
308
+ * console.log(cleanedSchema.required); // ['id', 'name']
309
+ * console.log('temporaryField' in cleanedSchema.properties); // false
310
+ * ```
103
311
  */
104
312
  removeProperty(name: string): OasObject;
105
313
  isRef(): this is OasRef<'schema'>;
106
314
  resolve(): OasObject;
107
315
  resolveOnce(): OasObject;
316
+ /**
317
+ * Converts the OasObject to a standard JSON Schema object.
318
+ *
319
+ * This method serializes the object to the JSON Schema format used in
320
+ * OpenAPI specifications. It handles property conversion, additional
321
+ * properties rules, and validation constraints.
322
+ *
323
+ * @param options - Conversion options for handling references and context
324
+ * @returns A JSON Schema representation of the object
325
+ *
326
+ * @example
327
+ * ```typescript
328
+ * const userObject = new OasObject({
329
+ * title: 'User',
330
+ * properties: {
331
+ * id: new OasString(),
332
+ * name: new OasString()
333
+ * },
334
+ * required: ['id'],
335
+ * additionalProperties: false
336
+ * });
337
+ *
338
+ * const jsonSchema = userObject.toJsonSchema({ refContext: new Map() });
339
+ *
340
+ * console.log(jsonSchema);
341
+ * // {
342
+ * // type: 'object',
343
+ * // title: 'User',
344
+ * // properties: {
345
+ * // id: { type: 'string' },
346
+ * // name: { type: 'string' }
347
+ * // },
348
+ * // required: ['id'],
349
+ * // additionalProperties: false
350
+ * // }
351
+ * ```
352
+ */
108
353
  toJsonSchema(options: ToJsonSchemaOptions): OpenAPIV3.NonArraySchemaObject;
109
354
  }
110
355
  //# sourceMappingURL=Object.d.ts.map