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

Warn for unsupported OpenAPI 3.1 feature jsonSchemaDialect #593

Merged
merged 1 commit into from
Feb 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const parseSecurityRequirementsArray = require('./parseSecurityRequirementsArray
const name = 'OpenAPI Object';
const requiredKeys = ['openapi', 'info', 'paths'];
const unsupportedKeys = ['tags', 'externalDocs'];
const unsupportedOpenAPI31Keys = ['webhooks', 'jsonSchemaDialect'];

/**
* Returns whether the given member element is unsupported
Expand All @@ -28,6 +29,7 @@ const unsupportedKeys = ['tags', 'externalDocs'];
* @private
*/
const isUnsupportedKey = R.anyPass(R.map(hasKey, unsupportedKeys));
const isUnsupportedOpenAPI31Key = R.anyPass(R.map(hasKey, unsupportedOpenAPI31Keys));

function parseOASObject(context, object) {
const { namespace } = context;
Expand All @@ -52,7 +54,7 @@ function parseOASObject(context, object) {
[isExtension, () => new namespace.elements.ParseResult()],

[
R.both(hasKey('webhooks'), isOpenAPI31OrHigher),
R.both(isUnsupportedOpenAPI31Key, isOpenAPI31OrHigher),
createUnsupportedMemberWarning(namespace, name),
],
[isUnsupportedKey, createUnsupportedMemberWarning(namespace, name)],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,38 @@ describe('#parseOpenAPIObject', () => {
expect(parseResult.warnings.get(1).toValue()).to.equal("'OpenAPI Object' contains unsupported key 'webhooks'");
});

it('provides warning for invalid key jsonSchemaDialect in OpenAPI 3.0', () => {
const object = new namespace.elements.Object({
openapi: '3.0.0',
info: {
title: 'My API',
version: '1.0.0',
},
paths: {},
jsonSchemaDialect: 'https://spec.openapis.org/oas/3.1/dialect/base',
});

const parseResult = parse(context, object);

expect(parseResult).to.contain.warning("'OpenAPI Object' contains invalid key 'jsonSchemaDialect'");
});

it('provides warning for unsupported jsonSchemaDialect key in OpenAPI 3.1', () => {
const object = new namespace.elements.Object({
openapi: '3.1.0',
info: {
title: 'My API',
version: '1.0.0',
},
paths: {},
jsonSchemaDialect: 'https://spec.openapis.org/oas/3.1/dialect/base',
});

const parseResult = parse(context, object);

expect(parseResult.warnings.get(1).toValue()).to.equal("'OpenAPI Object' contains unsupported key 'jsonSchemaDialect'");
});

it('provides warning for invalid key webhooks in OpenAPI 3.0', () => {
const object = new namespace.elements.Object({
openapi: '3.0.0',
Expand Down