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

Commit 6bb1b2d

Browse files
committed
fix(oas3): no type includes nullable on OpenAPI 3.1
1 parent 87112f5 commit 6bb1b2d

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,10 @@ function parseSchema(context) {
326326
constructObjectStructure(namespace, schema),
327327
constructArrayStructure(namespace, schema),
328328
];
329+
330+
if (context.isOpenAPIVersionMoreThanOrEqual(3, 1)) {
331+
element.attributes.set('typeAttributes', ['nullable']);
332+
}
329333
}
330334

331335
const title = schema.getValue('title');

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

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ describe('Schema Object', () => {
4141
);
4242
});
4343

44-
it('returns a data structure representing all types for no type limitations', () => {
44+
it('returns a data structure representing all types excluding null for no type limitations on OpenAPI less than 3.1', () => {
4545
const schema = new namespace.elements.Object({});
4646
const parseResult = parse(context, schema);
4747

@@ -58,6 +58,28 @@ describe('Schema Object', () => {
5858
expect(element.enumerations.get(2)).to.be.instanceof(namespace.elements.Boolean);
5959
expect(element.enumerations.get(3)).to.be.instanceof(namespace.elements.Object);
6060
expect(element.enumerations.get(4)).to.be.instanceof(namespace.elements.Array);
61+
expect(element.attributes.getValue('typeAttributes')).to.be.undefined;
62+
});
63+
64+
it('returns a data structure representing all types for no type limitations on OpenAPI 3.1', () => {
65+
context.openapiVersion = { major: 3, minor: 1 };
66+
const schema = new namespace.elements.Object({});
67+
const parseResult = parse(context, schema);
68+
69+
expect(parseResult.length).to.equal(1);
70+
expect(parseResult.get(0)).to.be.instanceof(namespace.elements.DataStructure);
71+
expect(parseResult).to.not.contain.annotations;
72+
73+
const element = parseResult.get(0).content;
74+
expect(element).to.be.instanceof(namespace.elements.Enum);
75+
76+
expect(element.enumerations.length).to.equal(5);
77+
expect(element.enumerations.get(0)).to.be.instanceof(namespace.elements.String);
78+
expect(element.enumerations.get(1)).to.be.instanceof(namespace.elements.Number);
79+
expect(element.enumerations.get(2)).to.be.instanceof(namespace.elements.Boolean);
80+
expect(element.enumerations.get(3)).to.be.instanceof(namespace.elements.Object);
81+
expect(element.enumerations.get(4)).to.be.instanceof(namespace.elements.Array);
82+
expect(element.attributes.getValue('typeAttributes')).to.deep.equal(['nullable']);
6183
});
6284

6385
it('returns a boolean structure for boolean type', () => {
@@ -577,6 +599,7 @@ describe('Schema Object', () => {
577599

578600
it('adds nullable type attribute to element', () => {
579601
const schema = new namespace.elements.Object({
602+
type: 'array',
580603
nullable: true,
581604
});
582605
const parseResult = parse(context, schema);

0 commit comments

Comments
 (0)