Skip to content

Commit e2bc6c2

Browse files
committed
fix
1 parent 2c83d5a commit e2bc6c2

1 file changed

Lines changed: 27 additions & 30 deletions

File tree

tools/proto-convert/src/SchemaModifier.ts

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ export class SchemaModifier {
3333
this.handleOneOfConst(schema, schemaName)
3434
this.collapseOrMergeOneOfArray(schema)
3535
this.collapseOneOfObjectPropContainsTitleSchema(schema)
36-
// Mark oneOf extensions (x-oneof on properties, x-oneof-constraint on schema)
3736
this.markOneOfExtensions(schema, schemaName);
3837
},
3938
});
@@ -439,33 +438,6 @@ export class SchemaModifier {
439438
this.logger.info(`Converted additionalProperties to named property '${propertyName}' with type: object`);
440439
}
441440

442-
/**
443-
* Marks schemas and properties with oneOf extensions.
444-
* Adds x-oneof to properties when schema has minProperties=1 and maxProperties=1.
445-
* Adds x-oneof-constraint to top-level schemas that contain such patterns.
446-
**/
447-
markOneOfExtensions(schema: OpenAPIV3.SchemaObject, schemaName?: string): void {
448-
// Check if this schema or nested items have the oneOf pattern
449-
const hasDirectPattern = schema.minProperties === 1 && schema.maxProperties === 1;
450-
const hasNestedPattern = this.hasNestedOneOfPattern(schema);
451-
452-
if (!hasDirectPattern && !hasNestedPattern) {
453-
return;
454-
}
455-
456-
// Add x-oneof to properties of this schema if it has the pattern
457-
if (hasDirectPattern && schema.properties) {
458-
for (const propName in schema.properties) {
459-
const prop = schema.properties[propName] as any;
460-
if (prop && typeof prop === 'object') {
461-
prop['x-oneof'] = true;
462-
}
463-
}
464-
this.logger.info(`Added x-oneof to properties with minProperties=1 and maxProperties=1`);
465-
}
466-
467-
// Add x-oneof-constraint to top-level schemas (not nested in allOf/anyOf/oneOf)
468-
if (schemaName && !['allOf', 'anyOf', 'oneOf'].includes(schemaName)) {
469441
/**
470442
* Removes the array wrapper if the schema is an array of maps (additionalProperties).
471443
* Converts array of objects with only additionalProperties into just the additionalProperties schema.
@@ -504,8 +476,33 @@ export class SchemaModifier {
504476
}
505477
}
506478

507-
markTopLevelOneOfConstraint(schema: OpenAPIV3.SchemaObject): void {
508-
if (schema.minProperties === 1 && schema.maxProperties === 1) {
479+
/**
480+
* Marks schemas and properties with oneOf extensions.
481+
* Adds x-oneof to properties when schema has minProperties=1 and maxProperties=1.
482+
* Adds x-oneof-constraint to top-level schemas that contain such patterns.
483+
**/
484+
markOneOfExtensions(schema: OpenAPIV3.SchemaObject, schemaName?: string): void {
485+
// Check if this schema or nested items have the oneOf pattern
486+
const hasDirectPattern = schema.minProperties === 1 && schema.maxProperties === 1;
487+
const hasNestedPattern = this.hasNestedOneOfPattern(schema);
488+
489+
if (!hasDirectPattern && !hasNestedPattern) {
490+
return;
491+
}
492+
493+
// Add x-oneof to properties of this schema if it has the pattern
494+
if (hasDirectPattern && schema.properties) {
495+
for (const propName in schema.properties) {
496+
const prop = schema.properties[propName] as any;
497+
if (prop && typeof prop === 'object') {
498+
prop['x-oneof'] = true;
499+
}
500+
}
501+
this.logger.info(`Added x-oneof to properties with minProperties=1 and maxProperties=1`);
502+
}
503+
504+
// Add x-oneof-constraint to top-level schemas (not nested in allOf/anyOf/oneOf)
505+
if (schemaName && !['allOf', 'anyOf', 'oneOf'].includes(schemaName)) {
509506
(schema as any)['x-oneof-constraint'] = true;
510507
this.logger.info(`Marked schema with x-oneof-constraint`);
511508
}

0 commit comments

Comments
 (0)