chore: add tests for one of titles

This commit is contained in:
Roman Hotsiy 2018-08-24 11:54:26 +03:00
parent 865f3ced4b
commit 81c0df092a
No known key found for this signature in database
GPG Key ID: 5CB7B3ACABA57CB0
2 changed files with 103 additions and 0 deletions

View 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"
}]
}
}
}
}

View File

@ -15,5 +15,29 @@ describe('Models', () => {
expect(schema.oneOf).toHaveLength(1); expect(schema.oneOf).toHaveLength(1);
expect(schema.discriminatorProp).toEqual('type'); 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');
});
}); });
}); });