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