mirror of
https://github.com/Redocly/redoc.git
synced 2024-11-22 08:36:33 +03:00
chore: add tests for one of titles
This commit is contained in:
parent
865f3ced4b
commit
81c0df092a
79
src/services/__tests__/fixtures/oneOfTitles.json
Normal file
79
src/services/__tests__/fixtures/oneOfTitles.json
Normal file
|
@ -0,0 +1,79 @@
|
|||
{
|
||||
"openapi": "3.0.0",
|
||||
"info": {
|
||||
"version": "1.0",
|
||||
"title": "Foo"
|
||||
},
|
||||
"components": {
|
||||
"schemas": {
|
||||
"Test": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"any": {
|
||||
"anyOf": [
|
||||
{
|
||||
"$ref": "#/components/schemas/Foo"
|
||||
},
|
||||
{
|
||||
"$ref": "#/components/schemas/Bar"
|
||||
}
|
||||
]
|
||||
},
|
||||
"one": {
|
||||
"oneOf": [
|
||||
{
|
||||
"$ref": "#/components/schemas/Foo"
|
||||
},
|
||||
{
|
||||
"$ref": "#/components/schemas/Bar"
|
||||
}
|
||||
]
|
||||
},
|
||||
"all": {
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "#/components/schemas/Foo"
|
||||
},
|
||||
{
|
||||
"$ref": "#/components/schemas/Bar"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"Foo": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"foo": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"Bar": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"bar": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"WithArray": {
|
||||
"oneOf": [{
|
||||
"type" : "array",
|
||||
"items": {
|
||||
"oneOf": [
|
||||
{
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"type": "number"
|
||||
}
|
||||
]
|
||||
}
|
||||
}, {
|
||||
"type": "string"
|
||||
}]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -15,5 +15,29 @@ describe('Models', () => {
|
|||
expect(schema.oneOf).toHaveLength(1);
|
||||
expect(schema.discriminatorProp).toEqual('type');
|
||||
});
|
||||
|
||||
test('oneOf/allOf titles', () => {
|
||||
const spec = require('../fixtures/oneOfTitles.json');
|
||||
parser = new OpenAPIParser(spec, undefined, opts);
|
||||
const schema = new SchemaModel(parser, spec.components.schemas.Test, '', opts);
|
||||
expect(schema.fields).toHaveLength(3);
|
||||
const oneOfField = schema.fields[0];
|
||||
expect(oneOfField.schema.displayType).toBe('Foo (object) or Bar (object)');
|
||||
expect(oneOfField.schema.oneOf[0].title).toBe('Foo');
|
||||
expect(oneOfField.schema.oneOf[1].title).toBe('Bar');
|
||||
|
||||
const anyOfField = schema.fields[1];
|
||||
expect(anyOfField.schema.displayType).toBe('Foo (object) or Bar (object)');
|
||||
expect(anyOfField.schema.oneOf[0].title).toBe('Foo');
|
||||
expect(anyOfField.schema.oneOf[1].title).toBe('Bar');
|
||||
});
|
||||
|
||||
test('oneOf/allOf schema complex displayType', () => {
|
||||
const spec = require('../fixtures/oneOfTitles.json');
|
||||
parser = new OpenAPIParser(spec, undefined, opts);
|
||||
const schema = new SchemaModel(parser, spec.components.schemas.WithArray, '', opts);
|
||||
expect(schema.oneOf).toHaveLength(2);
|
||||
expect(schema.displayType).toBe('(Array of string or number) or string');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue
Block a user