Skip to content

Commit 3e39097

Browse files
Merge main into fix-ir-validation (resolve version conflict)
Co-Authored-By: naman.anand@buildwithfern.com <iamnamananand996@gmail.com>
2 parents d578e52 + f08a2e9 commit 3e39097

File tree

5 files changed

+734
-36
lines changed

5 files changed

+734
-36
lines changed

packages/cli/api-importers/v3-importer-commons/src/converters/ExampleConverter.ts

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -886,9 +886,6 @@ export class ExampleConverter extends AbstractConverter<AbstractConverterContext
886886
return exampleConverter.convert();
887887
});
888888

889-
const isValid =
890-
resultsByKey.every((entry) => entry.result.isValid) && allOfResults.every((result) => result.isValid);
891-
892889
const usedProvidedExample =
893890
this.example !== undefined &&
894891
(resultsByKey.some(({ result }) => result.usedProvidedExample) ||
@@ -939,26 +936,43 @@ export class ExampleConverter extends AbstractConverter<AbstractConverterContext
939936
}
940937
});
941938
});
942-
} else {
943-
// Additional properties are allowed, but create warning errors for unexpected properties
944-
// We'll add these as separate warning results that don't affect validation
939+
} else if (
940+
resolvedSchema.additionalProperties === true ||
941+
resolvedSchema.additionalProperties === undefined
942+
) {
943+
// additionalProperties: true or undefined - preserve values without validation
945944
additionalPropertyKeys.forEach((key) => {
946-
const breadcrumbPath = [...this.breadcrumbs, key].join(".");
947-
const warningError = {
948-
message: `Additional property ${key} is not allowed`,
949-
path: [...this.breadcrumbs, key]
950-
};
951945
additionalPropertiesResults.push({
952946
key,
953947
result: {
954-
isValid: true, // Keep as valid since additional properties are allowed
948+
isValid: true,
955949
coerced: false,
956950
usedProvidedExample: true,
957-
validExample: undefined, // Don't provide a valid example to avoid further validation
958-
errors: [warningError] // Include as warning error
951+
validExample: exampleObj[key],
952+
errors: []
959953
}
960954
});
961955
});
956+
} else {
957+
// additionalProperties is a schema object - validate each additional property against it
958+
const additionalPropsSchema = resolvedSchema.additionalProperties as OpenAPIV3_1.SchemaObject;
959+
additionalPropertyKeys.forEach((key) => {
960+
const exampleConverter = new ExampleConverter({
961+
breadcrumbs: [...this.breadcrumbs, key],
962+
context: this.context,
963+
schema: additionalPropsSchema,
964+
example: exampleObj[key],
965+
depth: this.depth + 1,
966+
generateOptionalProperties: this.generateOptionalProperties,
967+
exampleGenerationStrategy: this.exampleGenerationStrategy,
968+
seenRefs: this.getMaybeUpdatedSeenRefs()
969+
});
970+
const result = exampleConverter.convert();
971+
additionalPropertiesResults.push({
972+
key,
973+
result
974+
});
975+
});
962976
}
963977
}
964978

@@ -969,6 +983,11 @@ export class ExampleConverter extends AbstractConverter<AbstractConverterContext
969983
}
970984
}
971985

986+
const isValid =
987+
resultsByKey.every((entry) => entry.result.isValid) &&
988+
allOfResults.every((result) => result.isValid) &&
989+
additionalPropertiesResults.every(({ result }) => result.isValid);
990+
972991
if (Object.keys(example).length === 0) {
973992
const firstValidNonObject = allOfResults.find(
974993
(result) =>

0 commit comments

Comments
 (0)