Skip to content
This repository was archived by the owner on Nov 8, 2024. It is now read-only.
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
39 changes: 33 additions & 6 deletions packages/openapi3-parser/lib/parser/oas/parseSchemaObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,38 @@ const parseReference = require('../parseReference');

const name = 'Schema Object';
const unsupportedKeys = [
// JSON Schema
'multipleOf', 'maximum', 'exclusiveMaximum', 'minimum',
'exclusiveMinimum', 'maxLength', 'minLength', 'pattern', 'maxItems',
'minItems', 'uniqueItems', 'maxProperties', 'minProperties',
// JSON Schema Core applicators
'allOf', 'anyOf', 'not',

// JSON Schema + OAS 3 specific rules
'allOf', 'anyOf', 'not', 'additionalProperties', 'format',
// JSON Schema Validation (6.2 Numeric)
'multipleOf', 'maximum', 'exclusiveMaximum', 'minimum', 'exclusiveMinimum',

// JSON Schema Validation (6.3 Strings)
'maxLength', 'minLength', 'pattern', 'format',

// JSON Schema Validation (6.4 Array)
'maxItems', 'minItems', 'uniqueItems',

// JSON Schema Validation (6.5 Objects)
'maxProperties', 'minProperties',

// OAS 3 specific
'discriminator', 'readOnly', 'writeOnly', 'xml', 'externalDocs', 'deprecated',
];
const unsupportedJSONSchemaDraft202012 = [
// General applicators
'if', 'then', 'else', 'dependentSchemas',

// Array
'prefixItems', 'unevaluatedItems', 'contains', 'minContains', 'maxContains',

// Object
'propertiesNames', 'unevaluatedProperties', 'dependentRequired',
];
const isUnsupportedKey = R.anyPass(R.map(hasKey, unsupportedKeys));
const isUnsupportedKeyJSONSchemaDraft202012 = R.anyPass(
R.map(hasKey, unsupportedJSONSchemaDraft202012)
);


function constructObjectStructure(namespace, schema) {
Expand Down Expand Up @@ -252,6 +272,13 @@ function parseSchema(context) {
[hasKey('oneOf'), R.compose(parseOneOf, getValue)],

[isUnsupportedKey, createUnsupportedMemberWarning(namespace, name)],
[
R.both(
isUnsupportedKeyJSONSchemaDraft202012,
R.always(context.isOpenAPIVersionMoreThanOrEqual(3, 1))
),
createUnsupportedMemberWarning(namespace, name),
],

// Return a warning for additional properties
[R.T, createInvalidMemberWarning(namespace, name)],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1017,4 +1017,43 @@ describe('Schema Object', () => {
expect(element.enumerations.get(1)).to.be.instanceof(namespace.elements.Array);
});
});

describe('warnings for unsupported properties', () => {
it('provides warning for unsupported property', () => {
const schema = new namespace.elements.Object({
deprecated: true,
});

const parseResult = parse(context, schema);

expect(parseResult).to.contain.warning(
"'Schema Object' contains unsupported key 'deprecated'"
);
});

it('provides invalid warning for unsupported OpenAPI 3.1 property on OpenAPI 3.0', () => {
const schema = new namespace.elements.Object({
if: true,
});

const parseResult = parse(context, schema);

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

it('provides warning for unsupported OpenAPI 3.1 property', () => {
context.openapiVersion = { major: 3, minor: 1 };
const schema = new namespace.elements.Object({
if: true,
});

const parseResult = parse(context, schema);

expect(parseResult).to.contain.warning(
"'Schema Object' contains unsupported key 'if'"
);
});
});
});