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

Commit 415abb8

Browse files
committed
feat(oas3): support parameter object title/description
1 parent fa75519 commit 415abb8

File tree

3 files changed

+55
-4
lines changed

3 files changed

+55
-4
lines changed

packages/openapi3-parser/CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
### Enhancements
66

7-
- Support for the 'enum' property in 'Schema Object's found within 'Parameter
8-
Object'.
7+
- Support for the 'title', 'description', and 'enum' properties in 'Schema
8+
Object's found within 'Parameter Object'.
99

1010
## 0.15.2 (2021-02-15)
1111

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ const name = 'Schema Object';
1616
const unsupportedKeys = [
1717
'$ref', 'multipleOf', 'maximum', 'exclusiveMaximum', 'minimum',
1818
'exclusiveMinimum', 'maxLength', 'minLength', 'pattern', 'maxItems',
19-
'minItems', 'uniqueItems', 'maxProperties', 'minProperties', 'enum',
20-
'properties', 'items', 'required', 'nullable', 'title', 'description',
19+
'minItems', 'uniqueItems', 'maxProperties', 'minProperties',
20+
'properties', 'items', 'required', 'nullable',
2121
'default', 'oneOf', 'allOf', 'anyOf', 'not', 'additionalProperties',
2222
'format', 'discriminator', 'readOnly', 'writeOnly', 'xml', 'externalDocs',
2323
'deprecated',
@@ -91,6 +91,9 @@ function parseSchemaObject(context) {
9191
[hasKey('example'), e => e.clone()],
9292
[hasKey('enum'), R.compose(parseEnum(context, name), getValue)],
9393

94+
[hasKey('title'), parseString(context, name, false)],
95+
[hasKey('description'), parseString(context, name, false)],
96+
9497
[isUnsupportedKey, createUnsupportedMemberWarning(namespace, name)],
9598
[isExtension, () => new namespace.elements.ParseResult()],
9699
[R.T, createInvalidMemberWarning(namespace, name)],
@@ -121,6 +124,16 @@ function parseSchemaObject(context) {
121124
return new namespace.elements.ParseResult([]);
122125
}
123126

127+
const title = schema.getValue('title');
128+
if (title) {
129+
element.title = title;
130+
}
131+
132+
const description = schema.getValue('description');
133+
if (description) {
134+
element.description = description;
135+
}
136+
124137
const example = schema.get('example');
125138
if (example) {
126139
element.attributes.set('samples', [example]);

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,44 @@ describe('Parameter Object', () => {
648648
expect(member.value.enumerations.toValue()).to.deep.equal(['0', '1']);
649649
});
650650

651+
it('attaches title', () => {
652+
const parameter = new namespace.elements.Object({
653+
name: 'example',
654+
in: 'query',
655+
schema: {
656+
type: 'string',
657+
title: 'Example Title',
658+
},
659+
});
660+
661+
const parseResult = parse(context, parameter);
662+
663+
expect(parseResult.length).to.equal(1);
664+
const member = parseResult.get(0);
665+
expect(member).to.be.instanceof(namespace.elements.Member);
666+
expect(member.value).to.be.instanceof(namespace.elements.String);
667+
expect(member.value.title.toValue()).to.equal('Example Title');
668+
});
669+
670+
it('attaches description', () => {
671+
const parameter = new namespace.elements.Object({
672+
name: 'example',
673+
in: 'query',
674+
schema: {
675+
type: 'string',
676+
description: 'Example Description',
677+
},
678+
});
679+
680+
const parseResult = parse(context, parameter);
681+
682+
expect(parseResult.length).to.equal(1);
683+
const member = parseResult.get(0);
684+
expect(member).to.be.instanceof(namespace.elements.Member);
685+
expect(member.value).to.be.instanceof(namespace.elements.String);
686+
expect(member.value.description.toValue()).to.equal('Example Description');
687+
});
688+
651689
it('provides a warning when schema is not an object', () => {
652690
const parameter = new namespace.elements.Object({
653691
name: 'example',

0 commit comments

Comments
 (0)