fix(ui): handle missing schema reference case for discriminant definitions (#8257)

Co-authored-by: Tim Lai <timothy.lai@gmail.com>
This commit is contained in:
Guillaume Tassery
2022-10-26 21:14:28 +02:00
committed by GitHub
parent 0e8a0407fa
commit b010b558f1
2 changed files with 61 additions and 0 deletions

View File

@@ -671,6 +671,65 @@ describe("sampleFromSchema", () => {
expect(sampleFromSchema(definition)).toEqual(expected)
})
it("should not throw if expected $$ref is missing, and should fallback to default behavior", () => {
let definition = {
"type": "array",
"items": {
"oneOf": [
{
"required": [
"type"
],
"type": "object",
"properties": {
"type": {
"type": "string",
"enum": [
"TYPE1",
"TYPE2"
]
}
},
"discriminator": {
"propertyName": "type",
"mapping": {
"TYPE1": "#/components/schemas/FirstDto",
"TYPE2": "#/components/schemas/SecondDto"
}
},
},
{
"required": [
"type"
],
"type": "object",
"properties": {
"type": {
"type": "string",
"enum": [
"TYPE1",
"TYPE2"
]
}
},
"discriminator": {
"propertyName": "type",
"mapping": {
"TYPE1": "#/components/schemas/FirstDto",
"TYPE2": "#/components/schemas/SecondDto"
}
},
}
]
}
}
expect(() => {
sampleFromSchema(definition)
}).not.toThrow()
})
})
it("should use overrideExample when defined", () => {