@api-client/core 0.19.19 → 0.19.20

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 (124) hide show
  1. package/build/src/authorization/Utils.js +3 -3
  2. package/build/src/authorization/Utils.js.map +1 -1
  3. package/build/src/modeling/ApiModel.d.ts +16 -5
  4. package/build/src/modeling/ApiModel.d.ts.map +1 -1
  5. package/build/src/modeling/ApiModel.js +17 -2
  6. package/build/src/modeling/ApiModel.js.map +1 -1
  7. package/build/src/modeling/ApiValidation.d.ts.map +1 -1
  8. package/build/src/modeling/ApiValidation.js +2 -1
  9. package/build/src/modeling/ApiValidation.js.map +1 -1
  10. package/build/src/modeling/DomainProperty.d.ts +12 -0
  11. package/build/src/modeling/DomainProperty.d.ts.map +1 -1
  12. package/build/src/modeling/DomainProperty.js +23 -28
  13. package/build/src/modeling/DomainProperty.js.map +1 -1
  14. package/build/src/modeling/DomainSerialization.js +1 -1
  15. package/build/src/modeling/DomainSerialization.js.map +1 -1
  16. package/build/src/modeling/ExposedEntity.d.ts +15 -1
  17. package/build/src/modeling/ExposedEntity.d.ts.map +1 -1
  18. package/build/src/modeling/ExposedEntity.js +42 -4
  19. package/build/src/modeling/ExposedEntity.js.map +1 -1
  20. package/build/src/modeling/actions/Action.d.ts.map +1 -1
  21. package/build/src/modeling/actions/Action.js +1 -0
  22. package/build/src/modeling/actions/Action.js.map +1 -1
  23. package/build/src/modeling/actions/ListAction.d.ts +3 -17
  24. package/build/src/modeling/actions/ListAction.d.ts.map +1 -1
  25. package/build/src/modeling/actions/ListAction.js +18 -38
  26. package/build/src/modeling/actions/ListAction.js.map +1 -1
  27. package/build/src/modeling/actions/SearchAction.d.ts +4 -4
  28. package/build/src/modeling/actions/SearchAction.d.ts.map +1 -1
  29. package/build/src/modeling/actions/SearchAction.js +16 -13
  30. package/build/src/modeling/actions/SearchAction.js.map +1 -1
  31. package/build/src/modeling/generators/oas_312/OasGenerator.d.ts +32 -0
  32. package/build/src/modeling/generators/oas_312/OasGenerator.d.ts.map +1 -0
  33. package/build/src/modeling/generators/oas_312/OasGenerator.js +1452 -0
  34. package/build/src/modeling/generators/oas_312/OasGenerator.js.map +1 -0
  35. package/build/src/modeling/generators/oas_312/OasSchemaGenerator.d.ts +27 -0
  36. package/build/src/modeling/generators/oas_312/OasSchemaGenerator.d.ts.map +1 -0
  37. package/build/src/modeling/generators/oas_312/OasSchemaGenerator.js +295 -0
  38. package/build/src/modeling/generators/oas_312/OasSchemaGenerator.js.map +1 -0
  39. package/build/src/modeling/generators/oas_312/types.d.ts +1010 -0
  40. package/build/src/modeling/generators/oas_312/types.d.ts.map +1 -0
  41. package/build/src/modeling/generators/oas_312/types.js +2 -0
  42. package/build/src/modeling/generators/oas_312/types.js.map +1 -0
  43. package/build/src/modeling/generators/oas_320/OasGenerator.d.ts +16 -0
  44. package/build/src/modeling/generators/oas_320/OasGenerator.d.ts.map +1 -0
  45. package/build/src/modeling/generators/oas_320/OasGenerator.js +306 -0
  46. package/build/src/modeling/generators/oas_320/OasGenerator.js.map +1 -0
  47. package/build/src/modeling/generators/oas_320/OasSchemaGenerator.d.ts +25 -0
  48. package/build/src/modeling/generators/oas_320/OasSchemaGenerator.d.ts.map +1 -0
  49. package/build/src/modeling/generators/oas_320/OasSchemaGenerator.js +237 -0
  50. package/build/src/modeling/generators/oas_320/OasSchemaGenerator.js.map +1 -0
  51. package/build/src/modeling/generators/oas_320/types.d.ts +1219 -0
  52. package/build/src/modeling/generators/oas_320/types.d.ts.map +1 -0
  53. package/build/src/modeling/generators/oas_320/types.js +2 -0
  54. package/build/src/modeling/generators/oas_320/types.js.map +1 -0
  55. package/build/src/modeling/types.d.ts +50 -13
  56. package/build/src/modeling/types.d.ts.map +1 -1
  57. package/build/src/modeling/types.js.map +1 -1
  58. package/build/src/modeling/validation/api_model_rules.d.ts +1 -0
  59. package/build/src/modeling/validation/api_model_rules.d.ts.map +1 -1
  60. package/build/src/modeling/validation/api_model_rules.js +105 -29
  61. package/build/src/modeling/validation/api_model_rules.js.map +1 -1
  62. package/build/src/models/ProjectRequest.d.ts.map +1 -1
  63. package/build/src/models/ProjectRequest.js +0 -4
  64. package/build/src/models/ProjectRequest.js.map +1 -1
  65. package/build/src/models/transformers/ArcDexieTransformer.d.ts.map +1 -1
  66. package/build/src/models/transformers/ArcDexieTransformer.js +0 -4
  67. package/build/src/models/transformers/ArcDexieTransformer.js.map +1 -1
  68. package/build/src/models/transformers/ImportUtils.js +1 -1
  69. package/build/src/models/transformers/ImportUtils.js.map +1 -1
  70. package/build/src/models/transformers/PostmanBackupTransformer.d.ts.map +1 -1
  71. package/build/src/models/transformers/PostmanBackupTransformer.js +0 -4
  72. package/build/src/models/transformers/PostmanBackupTransformer.js.map +1 -1
  73. package/build/src/runtime/constants.d.ts +7 -0
  74. package/build/src/runtime/constants.d.ts.map +1 -0
  75. package/build/src/runtime/constants.js +8 -0
  76. package/build/src/runtime/constants.js.map +1 -0
  77. package/build/src/runtime/http-engine/ntlm/Des.d.ts.map +1 -1
  78. package/build/src/runtime/http-engine/ntlm/Des.js +1 -0
  79. package/build/src/runtime/http-engine/ntlm/Des.js.map +1 -1
  80. package/build/src/runtime/variables/EvalFunctions.d.ts.map +1 -1
  81. package/build/src/runtime/variables/EvalFunctions.js +0 -1
  82. package/build/src/runtime/variables/EvalFunctions.js.map +1 -1
  83. package/build/tsconfig.tsbuildinfo +1 -1
  84. package/eslint.config.js +6 -0
  85. package/package.json +3 -1
  86. package/src/authorization/Utils.ts +3 -3
  87. package/src/modeling/ApiModel.ts +23 -8
  88. package/src/modeling/ApiValidation.ts +2 -0
  89. package/src/modeling/DomainProperty.ts +22 -18
  90. package/src/modeling/DomainSerialization.ts +1 -1
  91. package/src/modeling/ExposedEntity.ts +44 -4
  92. package/src/modeling/actions/Action.ts +1 -0
  93. package/src/modeling/actions/ListAction.ts +12 -30
  94. package/src/modeling/actions/SearchAction.ts +11 -8
  95. package/src/modeling/generators/oas_312/OasGenerator.ts +1685 -0
  96. package/src/modeling/generators/oas_312/OasSchemaGenerator.ts +322 -0
  97. package/src/modeling/generators/oas_312/types.ts +1052 -0
  98. package/src/modeling/generators/oas_320/OasGenerator.ts +359 -0
  99. package/src/modeling/generators/oas_320/OasSchemaGenerator.ts +255 -0
  100. package/src/modeling/generators/oas_320/types.ts +1259 -0
  101. package/src/modeling/types.ts +55 -22
  102. package/src/modeling/validation/api_model_rules.ts +103 -32
  103. package/src/models/ProjectRequest.ts +0 -4
  104. package/src/models/transformers/ArcDexieTransformer.ts +0 -4
  105. package/src/models/transformers/ImportUtils.ts +1 -1
  106. package/src/models/transformers/PostmanBackupTransformer.ts +0 -5
  107. package/src/runtime/constants.ts +9 -0
  108. package/src/runtime/http-engine/ntlm/Des.ts +1 -0
  109. package/src/runtime/variables/EvalFunctions.ts +0 -1
  110. package/tests/test-utils.ts +6 -2
  111. package/tests/unit/decorators/observed.spec.ts +8 -24
  112. package/tests/unit/decorators/observed_recursive.spec.ts +0 -1
  113. package/tests/unit/events/EventsTestHelpers.ts +0 -1
  114. package/tests/unit/events/events_polyfills.ts +0 -1
  115. package/tests/unit/legacy-transformers/DataTestHelper.ts +0 -2
  116. package/tests/unit/legacy-transformers/LegacyExportProcessor.spec.ts +0 -1
  117. package/tests/unit/modeling/actions/ListAction.spec.ts +9 -69
  118. package/tests/unit/modeling/actions/SearchAction.spec.ts +9 -35
  119. package/tests/unit/modeling/api_model.spec.ts +28 -0
  120. package/tests/unit/modeling/definitions/sku.spec.ts +0 -2
  121. package/tests/unit/modeling/domain_property.spec.ts +20 -1
  122. package/tests/unit/modeling/exposed_entity.spec.ts +71 -0
  123. package/tests/unit/modeling/generators/OasGenerator.spec.ts +302 -0
  124. package/tests/unit/modeling/validation/api_model_rules.spec.ts +113 -15
@@ -0,0 +1,237 @@
1
+ import { SemanticType } from '../../Semantics.js';
2
+ export class OasSchemaGenerator {
3
+ domain;
4
+ memorySchemas = {};
5
+ memoryNames = {};
6
+ constructor(domain) {
7
+ this.domain = domain;
8
+ }
9
+ /**
10
+ * Retrieves the dictionary of all processed OAS JSON schemas.
11
+ */
12
+ getSchemas() {
13
+ const result = {};
14
+ for (const [key, value] of Object.entries(this.memorySchemas)) {
15
+ result[this.memoryNames[key]] = value;
16
+ }
17
+ return result;
18
+ }
19
+ /**
20
+ * Generates schemas recursively for an entity and returns the $ref pointing to the root representation.
21
+ * @param entity
22
+ */
23
+ generateRootRef(entity) {
24
+ this.generateEntity(entity);
25
+ return { $ref: `#/components/schemas/${this.generateSchemaKey(entity)}` };
26
+ }
27
+ /**
28
+ * Generates a schema key for an entity.
29
+ */
30
+ generateSchemaKey(entity) {
31
+ return entity.info.name || 'entity ' + entity.key;
32
+ }
33
+ generateEntity(entity) {
34
+ if (this.memorySchemas[entity.key]) {
35
+ return; // Already processed or processing
36
+ }
37
+ // Preemptively assign to avoid infinite recursion over bidirectional associations
38
+ const schema = {
39
+ type: 'object',
40
+ properties: {},
41
+ required: [],
42
+ };
43
+ this.memorySchemas[entity.key] = schema;
44
+ const schemaKey = this.generateSchemaKey(entity);
45
+ this.memoryNames[entity.key] = schemaKey;
46
+ const required = [];
47
+ for (const prop of entity.properties) {
48
+ if (prop.required && !prop.readOnly) {
49
+ required.push(prop.info.name || prop.key);
50
+ }
51
+ if (!schema.properties) {
52
+ schema.properties = {};
53
+ }
54
+ const webBindings = prop.readBinding('web');
55
+ if (webBindings?.hidden) {
56
+ continue;
57
+ }
58
+ schema.properties[prop.info.name || prop.key] = this.mapPropertyBase(prop, webBindings);
59
+ }
60
+ for (const assoc of entity.associations) {
61
+ const bindings = assoc.readBinding('web');
62
+ if (bindings?.hidden) {
63
+ continue;
64
+ }
65
+ const targets = Array.from(assoc.listTargets());
66
+ if (targets.length === 0)
67
+ continue;
68
+ const linked = assoc.schema?.linked === true;
69
+ const targetRefs = [];
70
+ for (const targetEntity of targets) {
71
+ if (linked) {
72
+ // When an entity is linked then we treat it as a regular property, which value is a key to
73
+ // the target entity. The consuming application has to construct the endpoint manually.
74
+ const targetName = targetEntity.info.displayName || targetEntity.info.name || targetEntity.key;
75
+ targetRefs.push({
76
+ type: 'string',
77
+ description: `The ID of the linked ${targetName}.`,
78
+ });
79
+ }
80
+ else {
81
+ // If not linked, embed the resource as a reference to the schema.
82
+ if (targetEntity !== entity) {
83
+ this.generateEntity(targetEntity);
84
+ }
85
+ targetRefs.push({ $ref: `#/components/schemas/${this.generateSchemaKey(targetEntity)}` });
86
+ }
87
+ }
88
+ let assocSchema;
89
+ if (targetRefs.length > 1) {
90
+ const unionType = assoc.schema?.unionType || 'anyOf';
91
+ if (unionType === 'oneOf') {
92
+ assocSchema = { oneOf: targetRefs };
93
+ }
94
+ else if (unionType === 'allOf') {
95
+ assocSchema = { allOf: targetRefs };
96
+ }
97
+ else {
98
+ assocSchema = { anyOf: targetRefs };
99
+ }
100
+ }
101
+ else {
102
+ assocSchema = targetRefs[0];
103
+ }
104
+ const propName = assoc.info.name || assoc.key;
105
+ if (!schema.properties) {
106
+ schema.properties = {};
107
+ }
108
+ if (assoc.multiple) {
109
+ schema.properties[propName] = {
110
+ type: 'array',
111
+ items: assocSchema,
112
+ };
113
+ }
114
+ else {
115
+ schema.properties[propName] = assocSchema;
116
+ }
117
+ }
118
+ if (required.length > 0) {
119
+ schema.required = required;
120
+ }
121
+ else {
122
+ delete schema.required;
123
+ }
124
+ }
125
+ mapPropertyBase(prop, webBindings) {
126
+ const base = {};
127
+ if (prop.readOnly) {
128
+ base.readOnly = true;
129
+ }
130
+ if (prop.writeOnly) {
131
+ base.writeOnly = true;
132
+ }
133
+ if (prop.deprecated) {
134
+ base.deprecated = true;
135
+ }
136
+ if (prop.schema) {
137
+ if (prop.schema.minimum !== undefined) {
138
+ if (prop.schema.exclusiveMinimum) {
139
+ base.exclusiveMinimum = prop.schema.minimum;
140
+ }
141
+ else {
142
+ base.minimum = prop.schema.minimum;
143
+ }
144
+ }
145
+ if (prop.schema.maximum !== undefined) {
146
+ if (prop.schema.exclusiveMaximum) {
147
+ base.exclusiveMaximum = prop.schema.maximum;
148
+ }
149
+ else {
150
+ base.maximum = prop.schema.maximum;
151
+ }
152
+ }
153
+ if (prop.schema.pattern) {
154
+ base.pattern = prop.schema.pattern;
155
+ }
156
+ if (prop.schema.enum) {
157
+ base.enum = [...prop.schema.enum];
158
+ }
159
+ if (prop.schema.defaultValue?.value !== undefined) {
160
+ base.default = prop.schema.defaultValue.value;
161
+ }
162
+ if (prop.schema.examples) {
163
+ base.examples = [...prop.schema.examples];
164
+ }
165
+ }
166
+ if (prop.info && prop.info.description) {
167
+ base.description = prop.info.description;
168
+ }
169
+ if (prop.hasSemantic(SemanticType.Password)) {
170
+ base.format = 'password';
171
+ }
172
+ if (webBindings?.xml) {
173
+ base.xml = { ...webBindings.xml };
174
+ }
175
+ switch (prop.type) {
176
+ case 'string':
177
+ base.type = 'string';
178
+ break;
179
+ case 'number':
180
+ if (webBindings?.format === 'int32' || webBindings?.format === 'int64') {
181
+ base.type = 'integer';
182
+ }
183
+ else {
184
+ base.type = 'number';
185
+ }
186
+ if (prop.schema?.multipleOf !== undefined) {
187
+ base.multipleOf = prop.schema.multipleOf;
188
+ }
189
+ break;
190
+ case 'boolean':
191
+ base.type = 'boolean';
192
+ break;
193
+ case 'date':
194
+ base.type = 'string';
195
+ base.format = 'date';
196
+ break;
197
+ case 'datetime':
198
+ base.type = 'string';
199
+ base.format = 'date-time';
200
+ break;
201
+ case 'time':
202
+ base.type = 'string';
203
+ base.format = 'time';
204
+ break;
205
+ case 'binary':
206
+ base.type = 'string';
207
+ if (webBindings?.format) {
208
+ base.format = webBindings.format;
209
+ }
210
+ else {
211
+ base.format = 'binary';
212
+ }
213
+ if (webBindings?.fileTypes && webBindings.fileTypes.length > 0) {
214
+ const typesStr = webBindings.fileTypes.join(', ');
215
+ // Standard JSON Schema keyword for media wrapping (single value string usually,
216
+ // but some tools handle comma separated)
217
+ base.contentMediaType = webBindings.fileTypes.length === 1 ? webBindings.fileTypes[0] : typesStr;
218
+ // Vendor extension for tools supporting multiple explicit arrays
219
+ // ;(base as any)['x-file-types'] = webBindings.fileTypes
220
+ // Append to description so viewers can always see the requirements natively
221
+ const typesDesc = `**Allowed file types:** ${typesStr}`;
222
+ base.description = base.description ? `${base.description}\n\n${typesDesc}` : typesDesc;
223
+ }
224
+ break;
225
+ default:
226
+ base.type = 'string'; // fallback
227
+ }
228
+ if (prop.multiple) {
229
+ return {
230
+ type: 'array',
231
+ items: base,
232
+ };
233
+ }
234
+ return base;
235
+ }
236
+ }
237
+ //# sourceMappingURL=OasSchemaGenerator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OasSchemaGenerator.js","sourceRoot":"","sources":["../../../../../src/modeling/generators/oas_320/OasSchemaGenerator.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAEjD,MAAM,OAAO,kBAAkB;IAIT;IAHZ,aAAa,GAAiC,EAAE,CAAA;IAChD,WAAW,GAA2B,EAAE,CAAA;IAEhD,YAAoB,MAAkB;QAAlB,WAAM,GAAN,MAAM,CAAY;IAAG,CAAC;IAE1C;;OAEG;IACI,UAAU;QACf,MAAM,MAAM,GAAiC,EAAE,CAAA;QAC/C,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,EAAE,CAAC;YAC9D,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,GAAG,KAAK,CAAA;QACvC,CAAC;QACD,OAAO,MAAM,CAAA;IACf,CAAC;IAED;;;OAGG;IACI,eAAe,CAAC,MAAoB;QACzC,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,CAAA;QAC3B,OAAO,EAAE,IAAI,EAAE,wBAAwB,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAAC,EAAE,EAAE,CAAA;IAC3E,CAAC;IAED;;OAEG;IACI,iBAAiB,CAAC,MAAoB;QAC3C,O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BACE,IAAI,CAAC,IAAI,GAAG,QAAQ,CAAA,CAAC,WAAW;QACpC,CAAC;QAED,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YAClB,OAAO;gBACL,IAAI,EAAE,OAAO;gBACb,KAAK,EAAE,IAAI;aACZ,CAAA;QACH,CAAC;QAED,OAAO,IAAI,CAAA;IACb,CAAC;CACF","sourcesContent":["import type { ReferenceObject, SchemaObject } from './types.js'\nimport { AssociationWebBindings, PropertyWebBindings } from '../../Bindings.js'\nimport type { DataDomain } from '../../DataDomain.js'\nimport type { DomainEntity } from '../../DomainEntity.js'\nimport type { DomainProperty } from '../../DomainProperty.js'\nimport { SemanticType } from '../../Semantics.js'\n\nexport class OasSchemaGenerator {\n private memorySchemas: Record<string, SchemaObject> = {}\n private memoryNames: Record<string, string> = {}\n\n constructor(private domain: DataDomain) {}\n\n /**\n * Retrieves the dictionary of all processed OAS JSON schemas.\n */\n public getSchemas(): Record<string, SchemaObject> {\n const result: Record<string, SchemaObject> = {}\n for (const [key, value] of Object.entries(this.memorySchemas)) {\n result[this.memoryNames[key]] = value\n }\n return result\n }\n\n /**\n * Generates schemas recursively for an entity and returns the $ref pointing to the root representation.\n * @param entity\n */\n public generateRootRef(entity: DomainEntity): ReferenceObject {\n this.generateEntity(entity)\n return { $ref: `#/components/schemas/${this.generateSchemaKey(entity)}` }\n }\n\n /**\n * Generates a schema key for an entity.\n */\n public generateSchemaKey(entity: DomainEntity): string {\n return entity.info.name || 'entity ' + entity.key\n }\n\n private generateEntity(entity: DomainEntity): void {\n if (this.memorySchemas[entity.key]) {\n return // Already processed or processing\n }\n\n // Preemptively assign to avoid infinite recursion over bidirectional associations\n const schema: SchemaObject = {\n type: 'object',\n properties: {},\n required: [],\n }\n this.memorySchemas[entity.key] = schema\n const schemaKey = this.generateSchemaKey(entity)\n this.memoryNames[entity.key] = schemaKey\n\n const required: string[] = []\n\n for (const prop of entity.properties) {\n if (prop.required && !prop.readOnly) {\n required.push(prop.info.name || prop.key)\n }\n if (!schema.properties) {\n schema.properties = {}\n }\n const webBindings = prop.readBinding('web') as PropertyWebBindings | undefined\n if (webBindings?.hidden) {\n continue\n }\n schema.properties[prop.info.name || prop.key] = this.mapPropertyBase(prop, webBindings)\n }\n\n for (const assoc of entity.associations) {\n const bindings = assoc.readBinding('web') as AssociationWebBindings | undefined\n if (bindings?.hidden) {\n continue\n }\n\n const targets = Array.from(assoc.listTargets())\n if (targets.length === 0) continue\n\n const linked = assoc.schema?.linked === true\n const targetRefs: (SchemaObject | ReferenceObject)[] = []\n\n for (const targetEntity of targets) {\n if (linked) {\n // When an entity is linked then we treat it as a regular property, which value is a key to\n // the target entity. The consuming application has to construct the endpoint manually.\n const targetName = targetEntity.info.displayName || targetEntity.info.name || targetEntity.key\n targetRefs.push({\n type: 'string',\n description: `The ID of the linked ${targetName}.`,\n })\n } else {\n // If not linked, embed the resource as a reference to the schema.\n if (targetEntity !== entity) {\n this.generateEntity(targetEntity)\n }\n targetRefs.push({ $ref: `#/components/schemas/${this.generateSchemaKey(targetEntity)}` })\n }\n }\n\n let assocSchema: SchemaObject | ReferenceObject\n if (targetRefs.length > 1) {\n const unionType = assoc.schema?.unionType || 'anyOf'\n if (unionType === 'oneOf') {\n assocSchema = { oneOf: targetRefs }\n } else if (unionType === 'allOf') {\n assocSchema = { allOf: targetRefs }\n } else {\n assocSchema = { anyOf: targetRefs }\n }\n } else {\n assocSchema = targetRefs[0]\n }\n\n const propName = assoc.info.name || assoc.key\n if (!schema.properties) {\n schema.properties = {}\n }\n\n if (assoc.multiple) {\n schema.properties[propName] = {\n type: 'array',\n items: assocSchema,\n }\n } else {\n schema.properties[propName] = assocSchema\n }\n }\n\n if (required.length > 0) {\n schema.required = required\n } else {\n delete schema.required\n }\n }\n\n private mapPropertyBase(prop: DomainProperty, webBindings?: PropertyWebBindings): SchemaObject | ReferenceObject {\n const base: SchemaObject = {}\n\n if (prop.readOnly) {\n base.readOnly = true\n }\n\n if (prop.writeOnly) {\n base.writeOnly = true\n }\n\n if (prop.deprecated) {\n base.deprecated = true\n }\n\n if (prop.schema) {\n if (prop.schema.minimum !== undefined) {\n if (prop.schema.exclusiveMinimum) {\n base.exclusiveMinimum = prop.schema.minimum\n } else {\n base.minimum = prop.schema.minimum\n }\n }\n if (prop.schema.maximum !== undefined) {\n if (prop.schema.exclusiveMaximum) {\n base.exclusiveMaximum = prop.schema.maximum\n } else {\n base.maximum = prop.schema.maximum\n }\n }\n if (prop.schema.pattern) {\n base.pattern = prop.schema.pattern\n }\n if (prop.schema.enum) {\n base.enum = [...prop.schema.enum]\n }\n if (prop.schema.defaultValue?.value !== undefined) {\n base.default = prop.schema.defaultValue.value\n }\n if (prop.schema.examples) {\n base.examples = [...prop.schema.examples]\n }\n }\n\n if (prop.info && prop.info.description) {\n base.description = prop.info.description\n }\n\n if (prop.hasSemantic(SemanticType.Password)) {\n base.format = 'password'\n }\n\n if (webBindings?.xml) {\n base.xml = { ...webBindings.xml }\n }\n\n switch (prop.type) {\n case 'string':\n base.type = 'string'\n break\n case 'number':\n if (webBindings?.format === 'int32' || webBindings?.format === 'int64') {\n base.type = 'integer'\n } else {\n base.type = 'number'\n }\n if (prop.schema?.multipleOf !== undefined) {\n base.multipleOf = prop.schema.multipleOf\n }\n break\n case 'boolean':\n base.type = 'boolean'\n break\n case 'date':\n base.type = 'string'\n base.format = 'date'\n break\n case 'datetime':\n base.type = 'string'\n base.format = 'date-time'\n break\n case 'time':\n base.type = 'string'\n base.format = 'time'\n break\n case 'binary':\n base.type = 'string'\n if (webBindings?.format) {\n base.format = webBindings.format\n } else {\n base.format = 'binary'\n }\n if (webBindings?.fileTypes && webBindings.fileTypes.length > 0) {\n const typesStr = webBindings.fileTypes.join(', ')\n // Standard JSON Schema keyword for media wrapping (single value string usually,\n // but some tools handle comma separated)\n base.contentMediaType = webBindings.fileTypes.length === 1 ? webBindings.fileTypes[0] : typesStr\n // Vendor extension for tools supporting multiple explicit arrays\n // ;(base as any)['x-file-types'] = webBindings.fileTypes\n // Append to description so viewers can always see the requirements natively\n const typesDesc = `**Allowed file types:** ${typesStr}`\n base.description = base.description ? `${base.description}\\n\\n${typesDesc}` : typesDesc\n }\n break\n default:\n base.type = 'string' // fallback\n }\n\n if (prop.multiple) {\n return {\n type: 'array',\n items: base,\n }\n }\n\n return base\n }\n}\n"]}