@twin.org/tools-core 0.0.3-next.29 → 0.0.3-next.30
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.
|
@@ -178,7 +178,7 @@ export class JsonSchemaBuilder {
|
|
|
178
178
|
}
|
|
179
179
|
else {
|
|
180
180
|
// Const-and-type enum patterns always take priority so that JsDoc descriptions
|
|
181
|
-
// on the const object members are preserved in the generated
|
|
181
|
+
// on the const object members are preserved in the generated anyOf schema.
|
|
182
182
|
const constValues = Enum.extractEnumValuesFromConstAndType(statement.name.text, sourceFile);
|
|
183
183
|
if (constValues) {
|
|
184
184
|
schema = JsonSchemaBuilder.buildBaseSchema(context.namespace, title, statement);
|
|
@@ -399,7 +399,7 @@ export class JsonSchemaBuilder {
|
|
|
399
399
|
* @param entries The enum entries.
|
|
400
400
|
*/
|
|
401
401
|
static buildEnumSchema(schema, entries) {
|
|
402
|
-
schema.
|
|
402
|
+
schema.anyOf = entries.map(entry => ({
|
|
403
403
|
const: entry.value,
|
|
404
404
|
description: entry.description
|
|
405
405
|
}));
|
|
@@ -2571,19 +2571,18 @@ export class JsonSchemaBuilder {
|
|
|
2571
2571
|
// Expand all allOf branches
|
|
2572
2572
|
for (const branch of allOf) {
|
|
2573
2573
|
if (Is.object(branch)) {
|
|
2574
|
-
const branchRecord = branch;
|
|
2575
2574
|
let branchSourceTitle;
|
|
2576
2575
|
let referencedSchema;
|
|
2577
2576
|
// If the branch is a reference, resolve it
|
|
2578
|
-
if (Is.stringValue(
|
|
2579
|
-
const refTitle =
|
|
2577
|
+
if (Is.stringValue(branch.$ref) && !branch.properties) {
|
|
2578
|
+
const refTitle = branch.$ref.split("/").pop();
|
|
2580
2579
|
if (refTitle) {
|
|
2581
2580
|
// Look up the referenced schema in the context
|
|
2582
2581
|
referencedSchema =
|
|
2583
2582
|
context.schemas[context.packageName]?.[refTitle] ??
|
|
2584
2583
|
Object.values(context.schemas)
|
|
2585
2584
|
.flatMap(entries => Object.values(entries))
|
|
2586
|
-
.find(s => s.$id ===
|
|
2585
|
+
.find(s => s.$id === branch.$ref || s.title === refTitle);
|
|
2587
2586
|
referencedSchema ??= JsonSchemaBuilder.tryLoadExternalSchemaByTitle(context, refTitle);
|
|
2588
2587
|
if (referencedSchema) {
|
|
2589
2588
|
branchSourceTitle = referencedSchema.title ?? refTitle;
|
|
@@ -2610,8 +2609,8 @@ export class JsonSchemaBuilder {
|
|
|
2610
2609
|
}
|
|
2611
2610
|
else {
|
|
2612
2611
|
// Merge properties from direct schema in allOf
|
|
2613
|
-
if (Is.object(
|
|
2614
|
-
for (const [propertyKey, propertySchema] of Object.entries(
|
|
2612
|
+
if (Is.object(branch.properties)) {
|
|
2613
|
+
for (const [propertyKey, propertySchema] of Object.entries(branch.properties)) {
|
|
2615
2614
|
if (Is.object(propertySchema)) {
|
|
2616
2615
|
mergedProperties[propertyKey] = ObjectHelper.clone(propertySchema);
|
|
2617
2616
|
if (branchSourceTitle) {
|
|
@@ -2621,8 +2620,8 @@ export class JsonSchemaBuilder {
|
|
|
2621
2620
|
}
|
|
2622
2621
|
}
|
|
2623
2622
|
// Merge required fields
|
|
2624
|
-
if (Is.array(
|
|
2625
|
-
for (const field of
|
|
2623
|
+
if (Is.array(branch.required)) {
|
|
2624
|
+
for (const field of branch.required) {
|
|
2626
2625
|
if (Is.stringValue(field)) {
|
|
2627
2626
|
mergedRequired.add(field);
|
|
2628
2627
|
}
|