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

Commit

Permalink
fix(oas3): remove support for nullable in OpenAPI 3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
kylef committed Feb 23, 2021
1 parent d3b2a5a commit f781a34
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/openapi3-parser/lib/parser/oas/parseSchemaObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,13 +330,19 @@ function parseSchema(context) {
return element;
};

const parseNullable = R.ifElse(
R.always(context.isOpenAPIVersionMoreThanOrEqual(3, 1)),
createWarning(context.namespace, `'${name}' 'nullable' is removed in OpenAPI 3.1, use 'null' in type`),
parseBoolean(context, name, false)
);

const parseMember = R.cond([
[hasKey('type'), R.compose(parseType(context), getValue)],
[hasKey('enum'), R.compose(parseEnum(context, name), getValue)],
[hasKey('properties'), R.compose(parseProperties, getValue)],
[hasKey('items'), R.compose(parseSubSchema, getValue)],
[hasKey('required'), R.compose(parseRequired, getValue)],
[hasKey('nullable'), parseBoolean(context, name, false)],
[hasKey('nullable'), parseNullable],
[hasKey('title'), parseString(context, name, false)],
[hasKey('description'), parseString(context, name, false)],
[hasKey('default'), e => e.clone()],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,20 @@ describe('Schema Object', () => {
});

describe('#nullable', () => {
it('warns when nullable is used with OpenAPI 3.1', () => {
context.openapiVersion = { major: 3, minor: 1 };
const schema = new namespace.elements.Object({
nullable: true,
});
const parseResult = parse(context, schema);

expect(parseResult.length).to.equal(2);

expect(parseResult).to.contain.warning(
"'Schema Object' 'nullable' is removed in OpenAPI 3.1, use 'null' in type"
);
});

it('warns when nullable is not boolean', () => {
const schema = new namespace.elements.Object({
nullable: 1,
Expand Down

0 comments on commit f781a34

Please sign in to comment.