Skip to content
This repository was archived by the owner on Nov 8, 2024. It is now read-only.

Commit f855a73

Browse files
committed
feat(oas3): support Schema Object title
1 parent 8bfacf3 commit f855a73

File tree

4 files changed

+42
-2
lines changed

4 files changed

+42
-2
lines changed

packages/openapi3-parser/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# API Elements: OpenAPI 3 Parser Changelog
22

3+
## Master
4+
5+
### Enhancements
6+
7+
- Adds support for the Schema Object title property.
8+
39
## 0.14.0 (2020-06-24)
410

511
### Enhancements

packages/openapi3-parser/STATUS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ support.
196196
| type ||
197197
| enum ||
198198
| encoding ||
199-
| title | |
199+
| title | |
200200
| multipleOf ||
201201
| maximum ||
202202
| exclusiveMaximum ||

packages/openapi3-parser/lib/parser/oas/parseSchemaObject.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const parseReference = require('../parseReference');
1818
const name = 'Schema Object';
1919
const unsupportedKeys = [
2020
// JSON Schema
21-
'title', 'multipleOf', 'maximum', 'exclusiveMaximum', 'minimum',
21+
'multipleOf', 'maximum', 'exclusiveMaximum', 'minimum',
2222
'exclusiveMinimum', 'maxLength', 'minLength', 'pattern', 'maxItems',
2323
'minItems', 'uniqueItems', 'maxProperties', 'minProperties',
2424

@@ -206,6 +206,7 @@ function parseSchema(context) {
206206
[hasKey('items'), R.compose(parseSubSchema, getValue)],
207207
[hasKey('required'), R.compose(parseRequired, getValue)],
208208
[hasKey('nullable'), parseBoolean(context, name, false)],
209+
[hasKey('title'), parseString(context, name, false)],
209210
[hasKey('description'), parseString(context, name, false)],
210211
[hasKey('default'), e => e.clone()],
211212
[hasKey('example'), e => e.clone()],
@@ -253,6 +254,11 @@ function parseSchema(context) {
253254
];
254255
}
255256

257+
const title = schema.getValue('title');
258+
if (title) {
259+
element.title = title;
260+
}
261+
256262
const description = schema.getValue('description');
257263
if (description) {
258264
element.description = description;

packages/openapi3-parser/test/unit/parser/oas/parseSchemaObject-test.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,34 @@ describe('Schema Object', () => {
552552
});
553553
});
554554

555+
describe('#title', () => {
556+
it('warns when title is not a string', () => {
557+
const schema = new namespace.elements.Object({
558+
title: true,
559+
});
560+
const parseResult = parse(context, schema);
561+
562+
expect(parseResult.length).to.equal(2);
563+
564+
expect(parseResult).to.contain.warning(
565+
"'Schema Object' 'title' is not a string"
566+
);
567+
});
568+
569+
it('adds a title to the returned element', () => {
570+
const schema = new namespace.elements.Object({
571+
title: 'User',
572+
});
573+
const parseResult = parse(context, schema);
574+
575+
expect(parseResult.length).to.equal(1);
576+
expect(parseResult.get(0)).to.be.instanceof(namespace.elements.DataStructure);
577+
578+
const element = parseResult.get(0).content;
579+
expect(element.title.toValue()).to.equal('User');
580+
});
581+
});
582+
555583
describe('#description', () => {
556584
it('warns when description is not a string', () => {
557585
const schema = new namespace.elements.Object({

0 commit comments

Comments
 (0)