@skmtc/core 0.0.785 → 0.0.787

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 (93) hide show
  1. package/esm/dsl/ContentSettings.d.ts +164 -0
  2. package/esm/dsl/ContentSettings.d.ts.map +1 -1
  3. package/esm/dsl/ContentSettings.js +151 -0
  4. package/esm/dsl/Definition.d.ts +199 -0
  5. package/esm/dsl/Definition.d.ts.map +1 -1
  6. package/esm/dsl/Definition.js +189 -0
  7. package/esm/dsl/EntityType.d.ts +83 -0
  8. package/esm/dsl/EntityType.d.ts.map +1 -1
  9. package/esm/dsl/EntityType.js +83 -0
  10. package/esm/dsl/Identifier.d.ts +152 -0
  11. package/esm/dsl/Identifier.d.ts.map +1 -1
  12. package/esm/dsl/Identifier.js +152 -0
  13. package/esm/dsl/Import.d.ts +221 -0
  14. package/esm/dsl/Import.d.ts.map +1 -1
  15. package/esm/dsl/Import.js +202 -0
  16. package/esm/dsl/operation/OperationBase.d.ts +181 -1
  17. package/esm/dsl/operation/OperationBase.d.ts.map +1 -1
  18. package/esm/dsl/operation/OperationBase.js +181 -1
  19. package/esm/oas/array/Array.d.ts +109 -1
  20. package/esm/oas/array/Array.d.ts.map +1 -1
  21. package/esm/oas/array/Array.js +93 -1
  22. package/esm/oas/document/Document.d.ts +155 -1
  23. package/esm/oas/document/Document.d.ts.map +1 -1
  24. package/esm/oas/document/Document.js +141 -2
  25. package/esm/oas/integer/Integer.d.ts +98 -0
  26. package/esm/oas/integer/Integer.d.ts.map +1 -1
  27. package/esm/oas/integer/Integer.js +80 -0
  28. package/esm/oas/object/Object.d.ts +255 -10
  29. package/esm/oas/object/Object.d.ts.map +1 -1
  30. package/esm/oas/object/Object.js +229 -10
  31. package/esm/oas/string/String.d.ts +103 -1
  32. package/esm/oas/string/String.d.ts.map +1 -1
  33. package/esm/oas/string/String.js +87 -1
  34. package/esm/types/Brand.d.ts +74 -0
  35. package/esm/types/Brand.d.ts.map +1 -1
  36. package/esm/types/Brand.js +9 -0
  37. package/esm/types/GeneratorKeys.d.ts +336 -0
  38. package/esm/types/GeneratorKeys.d.ts.map +1 -1
  39. package/esm/types/GeneratorKeys.js +243 -0
  40. package/esm/types/GeneratorType.d.ts +119 -0
  41. package/esm/types/GeneratorType.d.ts.map +1 -1
  42. package/esm/types/Method.d.ts +109 -0
  43. package/esm/types/Method.d.ts.map +1 -1
  44. package/esm/types/Method.js +84 -0
  45. package/esm/types/RefName.d.ts +61 -0
  46. package/esm/types/RefName.d.ts.map +1 -1
  47. package/package.json +1 -1
  48. package/script/dsl/ContentSettings.d.ts +164 -0
  49. package/script/dsl/ContentSettings.d.ts.map +1 -1
  50. package/script/dsl/ContentSettings.js +151 -0
  51. package/script/dsl/Definition.d.ts +199 -0
  52. package/script/dsl/Definition.d.ts.map +1 -1
  53. package/script/dsl/Definition.js +189 -0
  54. package/script/dsl/EntityType.d.ts +83 -0
  55. package/script/dsl/EntityType.d.ts.map +1 -1
  56. package/script/dsl/EntityType.js +83 -0
  57. package/script/dsl/Identifier.d.ts +152 -0
  58. package/script/dsl/Identifier.d.ts.map +1 -1
  59. package/script/dsl/Identifier.js +152 -0
  60. package/script/dsl/Import.d.ts +221 -0
  61. package/script/dsl/Import.d.ts.map +1 -1
  62. package/script/dsl/Import.js +202 -0
  63. package/script/dsl/operation/OperationBase.d.ts +181 -1
  64. package/script/dsl/operation/OperationBase.d.ts.map +1 -1
  65. package/script/dsl/operation/OperationBase.js +181 -1
  66. package/script/oas/array/Array.d.ts +109 -1
  67. package/script/oas/array/Array.d.ts.map +1 -1
  68. package/script/oas/array/Array.js +93 -1
  69. package/script/oas/document/Document.d.ts +155 -1
  70. package/script/oas/document/Document.d.ts.map +1 -1
  71. package/script/oas/document/Document.js +141 -2
  72. package/script/oas/integer/Integer.d.ts +98 -0
  73. package/script/oas/integer/Integer.d.ts.map +1 -1
  74. package/script/oas/integer/Integer.js +80 -0
  75. package/script/oas/object/Object.d.ts +255 -10
  76. package/script/oas/object/Object.d.ts.map +1 -1
  77. package/script/oas/object/Object.js +229 -10
  78. package/script/oas/string/String.d.ts +103 -1
  79. package/script/oas/string/String.d.ts.map +1 -1
  80. package/script/oas/string/String.js +87 -1
  81. package/script/types/Brand.d.ts +74 -0
  82. package/script/types/Brand.d.ts.map +1 -1
  83. package/script/types/Brand.js +9 -0
  84. package/script/types/GeneratorKeys.d.ts +336 -0
  85. package/script/types/GeneratorKeys.d.ts.map +1 -1
  86. package/script/types/GeneratorKeys.js +243 -0
  87. package/script/types/GeneratorType.d.ts +119 -0
  88. package/script/types/GeneratorType.d.ts.map +1 -1
  89. package/script/types/Method.d.ts +109 -0
  90. package/script/types/Method.d.ts.map +1 -1
  91. package/script/types/Method.js +84 -0
  92. package/script/types/RefName.d.ts +61 -0
  93. package/script/types/RefName.d.ts.map +1 -1
@@ -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
@@ -1 +1 @@
1
- {"version":3,"file":"Object.d.ts","sourceRoot":"","sources":["../../../src/oas/object/Object.ts"],"names":[],"mappings":"AAAA,OAAO,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAO,KAAK,EAAE,SAAS,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAA;AACzE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAA;AAC7D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAG9C,MAAM,MAAM,eAAe,CAAC,QAAQ,SAAS,OAAO,GAAG,SAAS,IAAI;IAClE,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,GAAG,MAAM,CAAC,QAAQ,CAAC,GAAG,WAAW,CAAC,GAAG,SAAS,CAAA;IACnF,QAAQ,CAAC,EAAE,MAAM,EAAE,GAAG,SAAS,CAAA;IAC/B,OAAO,CAAC,EAAE,QAA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IAAI,IAAI,MAAM,CAAC,QAAQ,CAAC;IAIjC,OAAO,IAAI,SAAS;IAIpB,WAAW,IAAI,SAAS;IAIxB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAoCG;IACH,YAAY,CAAC,OAAO,EAAE,mBAAmB,GAAG,SAAS,CAAC,oBAAoB;CA8B3E"}
@@ -1,11 +1,109 @@
1
1
  import "../../_dnt.polyfills.js";
2
2
  import { match, P } from 'ts-pattern';
3
3
  /**
4
- * Object representing an object and/or a record in the OpenAPI Specification.
4
+ * Represents an object schema in the OpenAPI Specification.
5
5
  *
6
- * Objects have fixed, named fields. Records have any number of fields that do not have predefined names.
6
+ * `OasObject` handles both:
7
+ * - **Objects**: Types with fixed, named properties (like TypeScript interfaces)
8
+ * - **Records**: Types with dynamic keys and consistent value types (like TypeScript Record<string, T>)
9
+ *
10
+ * This class provides comprehensive support for object validation constraints,
11
+ * property management, and JSON Schema conversion. It supports nullable types
12
+ * through generic type parameters and handles complex property relationships.
13
+ *
14
+ * ## Key Features
15
+ *
16
+ * - **Property Management**: Add/remove properties with automatic required field handling
17
+ * - **Type Safety**: Generic nullable type support with proper TypeScript inference
18
+ * - **Validation**: Min/max properties, additional properties, and enum constraints
19
+ * - **JSON Schema**: Convert to standard JSON Schema format for validation
20
+ * - **Immutability**: All mutations return new instances (functional style)
21
+ *
22
+ * @template Nullable - Whether the object value itself can be null
23
+ *
24
+ * @example Basic object schema
25
+ * ```typescript
26
+ * import { OasObject } from '@skmtc/core';
27
+ *
28
+ * const userObject = new OasObject({
29
+ * title: 'User',
30
+ * description: 'A user in the system',
31
+ * properties: {
32
+ * id: new OasString({ title: 'User ID' }),
33
+ * name: new OasString({ title: 'Full Name' }),
34
+ * email: new OasString({ format: 'email' })
35
+ * },
36
+ * required: ['id', 'name'],
37
+ * additionalProperties: false
38
+ * });
39
+ * ```
40
+ *
41
+ * @example Dynamic property management
42
+ * ```typescript
43
+ * // Start with empty object
44
+ * let schema = OasObject.empty();
45
+ *
46
+ * // Add properties dynamically
47
+ * schema = schema.addProperty({
48
+ * name: 'id',
49
+ * schema: new OasString(),
50
+ * required: true
51
+ * });
52
+ *
53
+ * schema = schema.addProperty({
54
+ * name: 'metadata',
55
+ * schema: new OasObject({ additionalProperties: true }),
56
+ * required: false
57
+ * });
58
+ *
59
+ * // Remove a property
60
+ * schema = schema.removeProperty('metadata');
61
+ * ```
62
+ *
63
+ * @example Record-style object (additional properties)
64
+ * ```typescript
65
+ * const recordObject = new OasObject({
66
+ * title: 'StringMap',
67
+ * description: 'A map of string keys to string values',
68
+ * additionalProperties: new OasString(), // Any string key -> string value
69
+ * minProperties: 1 // At least one property required
70
+ * });
71
+ *
72
+ * // This allows: { [key: string]: string }
73
+ * ```
74
+ *
75
+ * @example Nullable object support
76
+ * ```typescript
77
+ * const nullableUser = new OasObject<true>({
78
+ * nullable: true,
79
+ * properties: {
80
+ * name: new OasString()
81
+ * },
82
+ * default: null // Can have null default when nullable
83
+ * });
84
+ *
85
+ * // This represents: { name: string } | null
86
+ * ```
7
87
  */
8
88
  export class OasObject {
89
+ /**
90
+ * Creates a new OasObject instance.
91
+ *
92
+ * @param fields - Object configuration fields
93
+ *
94
+ * @example
95
+ * ```typescript
96
+ * const userSchema = new OasObject({
97
+ * title: 'User',
98
+ * properties: {
99
+ * id: new OasString({ title: 'ID' }),
100
+ * name: new OasString({ title: 'Name' })
101
+ * },
102
+ * required: ['id'],
103
+ * additionalProperties: false
104
+ * });
105
+ * ```
106
+ */
9
107
  constructor(fields = {}) {
10
108
  /**
11
109
  * Object is part the 'schema' set which is used
@@ -158,7 +256,32 @@ export class OasObject {
158
256
  this.deprecated = fields.deprecated;
159
257
  this.enums = fields.enums;
160
258
  }
161
- /** Creates new empty OasObject */
259
+ /**
260
+ * Creates a new empty OasObject with no properties.
261
+ *
262
+ * This factory method creates a non-nullable object with empty properties
263
+ * and required arrays, useful as a starting point for dynamic object building.
264
+ *
265
+ * @returns A new empty OasObject instance
266
+ *
267
+ * @example
268
+ * ```typescript
269
+ * // Start with empty object and build up
270
+ * let schema = OasObject.empty();
271
+ *
272
+ * schema = schema.addProperty({
273
+ * name: 'id',
274
+ * schema: new OasString(),
275
+ * required: true
276
+ * });
277
+ *
278
+ * schema = schema.addProperty({
279
+ * name: 'name',
280
+ * schema: new OasString(),
281
+ * required: true
282
+ * });
283
+ * ```
284
+ */
162
285
  static empty() {
163
286
  return new OasObject({
164
287
  nullable: false,
@@ -169,11 +292,47 @@ export class OasObject {
169
292
  /**
170
293
  * Adds a new property to the object.
171
294
  *
172
- * @param {AddPropertyArgs} args - The arguments for adding a property.
173
- * @param {string} args.name - The name of the property to add.
174
- * @param {OasSchema | OasRef<'schema'> | CustomValue | undefined} args.schema - The schema of the property to add.
175
- * @param {boolean} args.required - Whether the property is required.
176
- * @returns {OasObject} A new OasObject with the added property.
295
+ * This method returns a new OasObject instance with the added property,
296
+ * following an immutable pattern. If the property is marked as required,
297
+ * it will be added to the required array.
298
+ *
299
+ * @param args - Property addition arguments
300
+ * @param args.name - The name of the property to add
301
+ * @param args.schema - The schema definition for the property
302
+ * @param args.required - Whether the property should be required (default: false)
303
+ * @returns A new OasObject with the added property
304
+ *
305
+ * @example Adding a simple property
306
+ * ```typescript
307
+ * const original = OasObject.empty();
308
+ * const withName = original.addProperty({
309
+ * name: 'username',
310
+ * schema: new OasString({ minLength: 3 }),
311
+ * required: true
312
+ * });
313
+ *
314
+ * console.log(withName.required); // ['username']
315
+ * ```
316
+ *
317
+ * @example Chaining property additions
318
+ * ```typescript
319
+ * const userSchema = OasObject.empty()
320
+ * .addProperty({
321
+ * name: 'id',
322
+ * schema: new OasInteger(),
323
+ * required: true
324
+ * })
325
+ * .addProperty({
326
+ * name: 'email',
327
+ * schema: new OasString({ format: 'email' }),
328
+ * required: true
329
+ * })
330
+ * .addProperty({
331
+ * name: 'age',
332
+ * schema: new OasInteger({ minimum: 0 }),
333
+ * required: false
334
+ * });
335
+ * ```
177
336
  */
178
337
  addProperty({ name, schema, required }) {
179
338
  if (!schema) {
@@ -195,8 +354,31 @@ export class OasObject {
195
354
  /**
196
355
  * Removes a property from the object.
197
356
  *
198
- * @param {string} name - The name of the property to remove.
199
- * @returns {OasObject} A new OasObject with the removed property.
357
+ * This method returns a new OasObject instance with the specified property
358
+ * removed. If the property was required, it will also be removed from the
359
+ * required array. If the property doesn't exist, returns the same instance.
360
+ *
361
+ * @param name - The name of the property to remove
362
+ * @returns A new OasObject with the property removed, or the same instance if property doesn't exist
363
+ *
364
+ * @example
365
+ * ```typescript
366
+ * const userSchema = new OasObject({
367
+ * properties: {
368
+ * id: new OasString(),
369
+ * name: new OasString(),
370
+ * email: new OasString(),
371
+ * temporaryField: new OasString()
372
+ * },
373
+ * required: ['id', 'name', 'temporaryField']
374
+ * });
375
+ *
376
+ * // Remove temporary field
377
+ * const cleanedSchema = userSchema.removeProperty('temporaryField');
378
+ *
379
+ * console.log(cleanedSchema.required); // ['id', 'name']
380
+ * console.log('temporaryField' in cleanedSchema.properties); // false
381
+ * ```
200
382
  */
201
383
  removeProperty(name) {
202
384
  if (!this.properties?.[name]) {
@@ -222,6 +404,43 @@ export class OasObject {
222
404
  resolveOnce() {
223
405
  return this;
224
406
  }
407
+ /**
408
+ * Converts the OasObject to a standard JSON Schema object.
409
+ *
410
+ * This method serializes the object to the JSON Schema format used in
411
+ * OpenAPI specifications. It handles property conversion, additional
412
+ * properties rules, and validation constraints.
413
+ *
414
+ * @param options - Conversion options for handling references and context
415
+ * @returns A JSON Schema representation of the object
416
+ *
417
+ * @example
418
+ * ```typescript
419
+ * const userObject = new OasObject({
420
+ * title: 'User',
421
+ * properties: {
422
+ * id: new OasString(),
423
+ * name: new OasString()
424
+ * },
425
+ * required: ['id'],
426
+ * additionalProperties: false
427
+ * });
428
+ *
429
+ * const jsonSchema = userObject.toJsonSchema({ refContext: new Map() });
430
+ *
431
+ * console.log(jsonSchema);
432
+ * // {
433
+ * // type: 'object',
434
+ * // title: 'User',
435
+ * // properties: {
436
+ * // id: { type: 'string' },
437
+ * // name: { type: 'string' }
438
+ * // },
439
+ * // required: ['id'],
440
+ * // additionalProperties: false
441
+ * // }
442
+ * ```
443
+ */
225
444
  toJsonSchema(options) {
226
445
  return {
227
446
  type: 'object',