From ac4ba5cb219d6591124a80678a448851cc5ed4dd Mon Sep 17 00:00:00 2001 From: Vladimir Gorej Date: Fri, 13 Oct 2023 12:20:08 +0200 Subject: [PATCH] fix(ns-openapi-3): support only subset of JSON Schema Draft 4/5 OpenAPI 3.0.x defines explicit subset of JSON Schema Draft 4/5 and considers the rest of the keywords as strictly unsupported. --- package-lock.json | 1 + packages/apidom-ns-openapi-3-0/package.json | 1 + .../src/elements/Schema.ts | 98 ++++++++++++++- .../src/refractor/specification.ts | 114 ++++++++++-------- .../open-api-3-0/schema/DefinitionsVisitor.ts | 29 ----- .../schema/DependenciesVisitor.ts | 29 ----- .../schema/PatternPropertiesVisitor.ts | 29 ----- .../schema/inherited-fixed-fields.ts | 16 --- .../Schema/__snapshots__/index.ts.snap | 96 +-------------- .../test/refractor/elements/Schema/index.ts | 78 ++---------- 10 files changed, 174 insertions(+), 317 deletions(-) delete mode 100644 packages/apidom-ns-openapi-3-0/src/refractor/visitors/open-api-3-0/schema/DefinitionsVisitor.ts delete mode 100644 packages/apidom-ns-openapi-3-0/src/refractor/visitors/open-api-3-0/schema/DependenciesVisitor.ts delete mode 100644 packages/apidom-ns-openapi-3-0/src/refractor/visitors/open-api-3-0/schema/PatternPropertiesVisitor.ts delete mode 100644 packages/apidom-ns-openapi-3-0/src/refractor/visitors/open-api-3-0/schema/inherited-fixed-fields.ts diff --git a/package-lock.json b/package-lock.json index b6b7850907..2ee96092a4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -35062,6 +35062,7 @@ "dependencies": { "@babel/runtime-corejs3": "^7.20.7", "@swagger-api/apidom-core": "^0.77.0", + "@swagger-api/apidom-error": "^0.77.0", "@swagger-api/apidom-ns-json-schema-draft-4": "^0.77.0", "@types/ramda": "~0.29.3", "ramda": "~0.29.0", diff --git a/packages/apidom-ns-openapi-3-0/package.json b/packages/apidom-ns-openapi-3-0/package.json index c2004e5882..997cbacee9 100644 --- a/packages/apidom-ns-openapi-3-0/package.json +++ b/packages/apidom-ns-openapi-3-0/package.json @@ -43,6 +43,7 @@ "dependencies": { "@babel/runtime-corejs3": "^7.20.7", "@swagger-api/apidom-core": "^0.77.0", + "@swagger-api/apidom-error": "^0.77.0", "@swagger-api/apidom-ns-json-schema-draft-4": "^0.77.0", "@types/ramda": "~0.29.3", "ramda": "~0.29.0", diff --git a/packages/apidom-ns-openapi-3-0/src/elements/Schema.ts b/packages/apidom-ns-openapi-3-0/src/elements/Schema.ts index 14d92a7be1..8f46f7e5f3 100644 --- a/packages/apidom-ns-openapi-3-0/src/elements/Schema.ts +++ b/packages/apidom-ns-openapi-3-0/src/elements/Schema.ts @@ -1,11 +1,21 @@ -import { StringElement, BooleanElement, Element, Attributes, Meta } from '@swagger-api/apidom-core'; -import { JSONSchemaElement } from '@swagger-api/apidom-ns-json-schema-draft-4'; +import { UnsupportedOperationError } from '@swagger-api/apidom-error'; +import { + StringElement, + BooleanElement, + Element, + Attributes, + Meta, + ObjectElement, + ArrayElement, +} from '@swagger-api/apidom-core'; +import { JSONSchemaElement, MediaElement } from '@swagger-api/apidom-ns-json-schema-draft-4'; import ReferenceElement from './Reference'; import DiscriminatorElement from './Discriminator'; import XmlElement from './Xml'; import ExternalDocumentationElement from './ExternalDocumentation'; +/* eslint-disable class-methods-use-this */ class Schema extends JSONSchemaElement { constructor(content?: Record, meta?: Meta, attributes?: Attributes) { super(content, meta, attributes); @@ -13,6 +23,27 @@ class Schema extends JSONSchemaElement { this.classes.push('json-schema-draft-4'); } + /** + * Core vocabulary + * + * URI: https://tools.ietf.org/html/draft-wright-json-schema-00 + */ + get idProp(): StringElement | undefined { + throw new UnsupportedOperationError('idProp getter in Schema class is not not supported.'); + } + + set idProp(idProps: StringElement | undefined) { + throw new UnsupportedOperationError('idProp setter in Schema class is not not supported.'); + } + + get $schema(): StringElement | undefined { + throw new UnsupportedOperationError('$schema getter in Schema class is not not supported.'); + } + + set $schema($schema: StringElement | undefined) { + throw new UnsupportedOperationError('$schema setter in Schema class is not not supported.'); + } + /** * Validation keywords for arrays */ @@ -47,6 +78,30 @@ class Schema extends JSONSchemaElement { this.set('additionalProperties', additionalProperties); } + get patternProperties(): ObjectElement | undefined { + throw new UnsupportedOperationError( + 'patternProperties getter in Schema class is not not supported.', + ); + } + + set patternProperties(patternProperties: ObjectElement | undefined) { + throw new UnsupportedOperationError( + 'patternProperties setter in Schema class is not not supported.', + ); + } + + get dependencies(): ObjectElement | undefined { + throw new UnsupportedOperationError( + 'dependencies getter in Schema class is not not supported.', + ); + } + + set dependencies(dependencies: ObjectElement | undefined) { + throw new UnsupportedOperationError( + 'dependencies setter in Schema class is not not supported.', + ); + } + /** * Validation keywords for any instance type */ @@ -67,6 +122,44 @@ class Schema extends JSONSchemaElement { this.set('not', not); } + get definitions(): ObjectElement | undefined { + throw new UnsupportedOperationError('definitions getter in Schema class is not not supported.'); + } + + set definitions(definitions: ObjectElement | undefined) { + throw new UnsupportedOperationError('definitions setter in Schema class is not not supported.'); + } + + /** + * JSON Hyper-Schema + * + * URI: https://datatracker.ietf.org/doc/html/draft-wright-json-schema-hyperschema-00 + */ + + get base(): StringElement | undefined { + throw new UnsupportedOperationError('base getter in Schema class is not not supported.'); + } + + set base(base: StringElement | undefined) { + throw new UnsupportedOperationError('base setter in Schema class is not not supported.'); + } + + get links(): ArrayElement | undefined { + throw new UnsupportedOperationError('links getter in Schema class is not not supported.'); + } + + set links(links: ArrayElement | undefined) { + throw new UnsupportedOperationError('links setter in Schema class is not not supported.'); + } + + get media(): MediaElement | undefined { + throw new UnsupportedOperationError('media getter in Schema class is not not supported.'); + } + + set media(media: MediaElement | undefined) { + throw new UnsupportedOperationError('media setter in Schema class is not not supported.'); + } + /** * OpenAPI vocabulary */ @@ -127,5 +220,6 @@ class Schema extends JSONSchemaElement { this.set('deprecated', deprecated); } } +/* eslint-disable class-methods-use-this */ export default Schema; diff --git a/packages/apidom-ns-openapi-3-0/src/refractor/specification.ts b/packages/apidom-ns-openapi-3-0/src/refractor/specification.ts index 51fe823484..0e104686b0 100644 --- a/packages/apidom-ns-openapi-3-0/src/refractor/specification.ts +++ b/packages/apidom-ns-openapi-3-0/src/refractor/specification.ts @@ -71,17 +71,14 @@ import SchemaVisitor from './visitors/open-api-3-0/schema'; import SchemaAllOfVisitor from './visitors/open-api-3-0/schema/AllOfVisitor'; import SchemaAnyOfVisitor from './visitors/open-api-3-0/schema/AnyOfVisitor'; import SchemaOneOfVisitor from './visitors/open-api-3-0/schema/OneOfVisitor'; -import SchemaDefinitionsVisitor from './visitors/open-api-3-0/schema/DefinitionsVisitor'; -import SchemaDependenciesVisitor from './visitors/open-api-3-0/schema/DependenciesVisitor'; import SchemaItemsVisitor from './visitors/open-api-3-0/schema/ItemsVisitor'; import SchemaPropertiesVisitor from './visitors/open-api-3-0/schema/PropertiesVisitor'; -import SchemaPatternPropertiesVisitor from './visitors/open-api-3-0/schema/PatternPropertiesVisitor'; import SchemaTypeVisitor from './visitors/open-api-3-0/schema/TypeVisitor'; import SchemaNullableVisitor from './visitors/open-api-3-0/schema/NullableVisitor'; import SchemaWriteOnlyVisitor from './visitors/open-api-3-0/schema/WriteOnlyVisitor'; import SchemaExampleVisitor from './visitors/open-api-3-0/schema/ExampleVisitor'; import SchemaDeprecatedVisitor from './visitors/open-api-3-0/schema/DeprecatedVisitor'; -import schemaInheritedFixedFields from './visitors/open-api-3-0/schema/inherited-fixed-fields'; +import SchemaOrReferenceVisitor from './visitors/open-api-3-0/schema/SchemaOrReferenceVisitor'; import DiscriminatorVisitor from './visitors/open-api-3-0/distriminator'; import DiscriminatorPropertyNameVisitor from './visitors/open-api-3-0/distriminator/PropertyNameVisitor'; import DiscriminatorMappingVisitor from './visitors/open-api-3-0/distriminator/MappingVisitor'; @@ -172,47 +169,8 @@ import TagsVisitor from './visitors/open-api-3-0/TagsVisitor'; * Note: Specification object allows to use absolute internal JSON pointers. */ -const ReferenceSpecification = { - $visitor: ReferenceVisitor, - fixedFields: { - $ref: Reference$RefVisitor, - }, -}; - -const SchemaSpecification = { - $visitor: SchemaVisitor, - fixedFields: { - ...schemaInheritedFixedFields, - // validation vocabulary - // validation keywords for any instance type - allOf: SchemaAllOfVisitor, - anyOf: SchemaAnyOfVisitor, - oneOf: SchemaOneOfVisitor, - definitions: SchemaDefinitionsVisitor, - // validation keywords for arrays - items: SchemaItemsVisitor, - // Validation keywords for objects - dependencies: SchemaDependenciesVisitor, - properties: SchemaPropertiesVisitor, - patternProperties: SchemaPatternPropertiesVisitor, - // validation keywords for any instance type - type: SchemaTypeVisitor, - // OpenAPI vocabulary - nullable: SchemaNullableVisitor, - discriminator: { - $ref: '#/visitors/document/objects/Discriminator', - }, - writeOnly: SchemaWriteOnlyVisitor, - xml: { - $ref: '#/visitors/document/objects/XML', - }, - externalDocs: { - $ref: '#/visitors/document/objects/ExternalDocumentation', - }, - example: SchemaExampleVisitor, - deprecated: SchemaDeprecatedVisitor, - }, -}; +const { fixedFields: jsonSchemaFixedFields } = + JSONSchemaDraft4Specification.visitors.document.objects.JSONSchema; const specification = { visitors: { @@ -476,12 +434,66 @@ const specification = { }, }, }, - JSONReference: ReferenceSpecification, - Reference: ReferenceSpecification, - JSONSchema: SchemaSpecification, - Schema: SchemaSpecification, - LinkDescription: JSONSchemaDraft4Specification.visitors.document.objects.LinkDescription, - Media: JSONSchemaDraft4Specification.visitors.document.objects.Media, + Reference: { + $visitor: ReferenceVisitor, + fixedFields: { + $ref: Reference$RefVisitor, + }, + }, + JSONSchema: { + $ref: '#/visitors/document/objects/Schema', + }, + JSONReference: { + $ref: '#/visitors/document/objects/Reference', + }, + Schema: { + $visitor: SchemaVisitor, + fixedFields: { + // the following properties are taken directly from the JSON Schema definition and follow the same specifications + title: jsonSchemaFixedFields.title, + multipleOf: jsonSchemaFixedFields.multipleOf, + maximum: jsonSchemaFixedFields.maximum, + exclusiveMaximum: jsonSchemaFixedFields.exclusiveMaximum, + minimum: jsonSchemaFixedFields.minimum, + exclusiveMinimum: jsonSchemaFixedFields.exclusiveMinimum, + maxLength: jsonSchemaFixedFields.maxLength, + minLength: jsonSchemaFixedFields.minLength, + pattern: jsonSchemaFixedFields.pattern, + maxItems: jsonSchemaFixedFields.maxItems, + minItems: jsonSchemaFixedFields.minItems, + uniqueItems: jsonSchemaFixedFields.uniqueItems, + maxProperties: jsonSchemaFixedFields.maxProperties, + minProperties: jsonSchemaFixedFields.minProperties, + required: jsonSchemaFixedFields.required, + enum: jsonSchemaFixedFields.enum, + // the following properties are taken from the JSON Schema definition but their definitions were adjusted to the OpenAPI Specification + type: SchemaTypeVisitor, + allOf: SchemaAllOfVisitor, + anyOf: SchemaAnyOfVisitor, + oneOf: SchemaOneOfVisitor, + not: SchemaOrReferenceVisitor, + items: SchemaItemsVisitor, + properties: SchemaPropertiesVisitor, + additionalProperties: SchemaOrReferenceVisitor, + description: jsonSchemaFixedFields.description, + format: jsonSchemaFixedFields.format, + default: jsonSchemaFixedFields.default, + // OpenAPI vocabulary + nullable: SchemaNullableVisitor, + discriminator: { + $ref: '#/visitors/document/objects/Discriminator', + }, + writeOnly: SchemaWriteOnlyVisitor, + xml: { + $ref: '#/visitors/document/objects/XML', + }, + externalDocs: { + $ref: '#/visitors/document/objects/ExternalDocumentation', + }, + example: SchemaExampleVisitor, + deprecated: SchemaDeprecatedVisitor, + }, + }, Discriminator: { $visitor: DiscriminatorVisitor, fixedFields: { diff --git a/packages/apidom-ns-openapi-3-0/src/refractor/visitors/open-api-3-0/schema/DefinitionsVisitor.ts b/packages/apidom-ns-openapi-3-0/src/refractor/visitors/open-api-3-0/schema/DefinitionsVisitor.ts deleted file mode 100644 index 5df8fc90ef..0000000000 --- a/packages/apidom-ns-openapi-3-0/src/refractor/visitors/open-api-3-0/schema/DefinitionsVisitor.ts +++ /dev/null @@ -1,29 +0,0 @@ -import stampit from 'stampit'; -import { ObjectElement } from '@swagger-api/apidom-core'; -import { specificationObj as JSONSchemaDraft4Specification } from '@swagger-api/apidom-ns-json-schema-draft-4'; - -import ReferenceElement from '../../../../elements/Reference'; -import { isReferenceElement } from '../../../../predicates'; - -const { definitions: JSONSchemaDefinitionsVisitor } = - JSONSchemaDraft4Specification.visitors.document.objects.JSONSchema.fixedFields; - -const DefinitionsVisitor = stampit(JSONSchemaDefinitionsVisitor, { - methods: { - ObjectElement(objectElement: ObjectElement) { - // @ts-ignore - const result = JSONSchemaDefinitionsVisitor.compose.methods.ObjectElement.call( - this, - objectElement, - ); - - this.element.filter(isReferenceElement).forEach((referenceElement: ReferenceElement) => { - referenceElement.setMetaProperty('referenced-element', 'schema'); - }); - - return result; - }, - }, -}); - -export default DefinitionsVisitor; diff --git a/packages/apidom-ns-openapi-3-0/src/refractor/visitors/open-api-3-0/schema/DependenciesVisitor.ts b/packages/apidom-ns-openapi-3-0/src/refractor/visitors/open-api-3-0/schema/DependenciesVisitor.ts deleted file mode 100644 index 38b7f70863..0000000000 --- a/packages/apidom-ns-openapi-3-0/src/refractor/visitors/open-api-3-0/schema/DependenciesVisitor.ts +++ /dev/null @@ -1,29 +0,0 @@ -import stampit from 'stampit'; -import { ObjectElement } from '@swagger-api/apidom-core'; -import { specificationObj as JSONSchemaDraft4Specification } from '@swagger-api/apidom-ns-json-schema-draft-4'; - -import ReferenceElement from '../../../../elements/Reference'; -import { isReferenceElement } from '../../../../predicates'; - -const { dependencies: JSONSchemaDependenciesVisitor } = - JSONSchemaDraft4Specification.visitors.document.objects.JSONSchema.fixedFields; - -const DependenciesVisitor = stampit(JSONSchemaDependenciesVisitor, { - methods: { - ObjectElement(objectElement: ObjectElement) { - // @ts-ignore - const result = JSONSchemaDependenciesVisitor.compose.methods.ObjectElement.call( - this, - objectElement, - ); - - this.element.filter(isReferenceElement).forEach((referenceElement: ReferenceElement) => { - referenceElement.setMetaProperty('referenced-element', 'schema'); - }); - - return result; - }, - }, -}); - -export default DependenciesVisitor; diff --git a/packages/apidom-ns-openapi-3-0/src/refractor/visitors/open-api-3-0/schema/PatternPropertiesVisitor.ts b/packages/apidom-ns-openapi-3-0/src/refractor/visitors/open-api-3-0/schema/PatternPropertiesVisitor.ts deleted file mode 100644 index bff2ecfa27..0000000000 --- a/packages/apidom-ns-openapi-3-0/src/refractor/visitors/open-api-3-0/schema/PatternPropertiesVisitor.ts +++ /dev/null @@ -1,29 +0,0 @@ -import stampit from 'stampit'; -import { ObjectElement } from '@swagger-api/apidom-core'; -import { specificationObj as JSONSchemaDraft4Specification } from '@swagger-api/apidom-ns-json-schema-draft-4'; - -import ReferenceElement from '../../../../elements/Reference'; -import { isReferenceElement } from '../../../../predicates'; - -const { patternProperties: JSONSchemaPatternPropertiesVisitor } = - JSONSchemaDraft4Specification.visitors.document.objects.JSONSchema.fixedFields; - -const PatternPropertiesVisitor = stampit(JSONSchemaPatternPropertiesVisitor, { - methods: { - ObjectElement(objectElement: ObjectElement) { - // @ts-ignore - const result = JSONSchemaPatternPropertiesVisitor.compose.methods.ObjectElement.call( - this, - objectElement, - ); - - this.element.filter(isReferenceElement).forEach((referenceElement: ReferenceElement) => { - referenceElement.setMetaProperty('referenced-element', 'schema'); - }); - - return result; - }, - }, -}); - -export default PatternPropertiesVisitor; diff --git a/packages/apidom-ns-openapi-3-0/src/refractor/visitors/open-api-3-0/schema/inherited-fixed-fields.ts b/packages/apidom-ns-openapi-3-0/src/refractor/visitors/open-api-3-0/schema/inherited-fixed-fields.ts deleted file mode 100644 index 8ead320548..0000000000 --- a/packages/apidom-ns-openapi-3-0/src/refractor/visitors/open-api-3-0/schema/inherited-fixed-fields.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { specificationObj as JSONSchemaDraft4Specification } from '@swagger-api/apidom-ns-json-schema-draft-4'; - -import SchemaOrReferenceVisitor from './SchemaOrReferenceVisitor'; - -const inheritedFixedFields = Object.fromEntries( - Object.entries( - JSONSchemaDraft4Specification.visitors.document.objects.JSONSchema.fixedFields, - ).map(([fieldName, visitor]) => { - if (visitor === JSONSchemaDraft4Specification.visitors.JSONSchemaOrJSONReferenceVisitor) { - return [fieldName, SchemaOrReferenceVisitor]; - } - return [fieldName, visitor]; - }), -); - -export default inheritedFixedFields; diff --git a/packages/apidom-ns-openapi-3-0/test/refractor/elements/Schema/__snapshots__/index.ts.snap b/packages/apidom-ns-openapi-3-0/test/refractor/elements/Schema/__snapshots__/index.ts.snap index 7c4e1174f3..86604259d5 100644 --- a/packages/apidom-ns-openapi-3-0/test/refractor/elements/Schema/__snapshots__/index.ts.snap +++ b/packages/apidom-ns-openapi-3-0/test/refractor/elements/Schema/__snapshots__/index.ts.snap @@ -22,43 +22,8 @@ exports[`refractor elements SchemaElement given anyOf keyword with reference sho (StringElement)))))) `; -exports[`refractor elements SchemaElement given definitions keyword with reference should refract to semantic ApiDOM tree 1`] = ` -(SchemaElement - (MemberElement - (StringElement) - (ObjectElement - (MemberElement - (StringElement) - (ReferenceElement - (MemberElement - (StringElement) - (StringElement))))))) -`; - -exports[`refractor elements SchemaElement given dependencies keyword with reference should refract to semantic ApiDOM tree 1`] = ` -(SchemaElement - (MemberElement - (StringElement) - (ObjectElement - (MemberElement - (StringElement) - (ReferenceElement - (MemberElement - (StringElement) - (StringElement))))))) -`; - exports[`refractor elements SchemaElement given embedded SchemaElements should refract to semantic ApiDOM tree 1`] = ` (SchemaElement - (MemberElement - (StringElement) - (ObjectElement - (MemberElement - (StringElement) - (SchemaElement - (MemberElement - (StringElement) - (SchemaElement)))))) (MemberElement (StringElement) (ArrayElement @@ -86,19 +51,6 @@ exports[`refractor elements SchemaElement given oneOf keyword with reference sho (StringElement)))))) `; -exports[`refractor elements SchemaElement given patternProperties keyword with reference should refract to semantic ApiDOM tree 1`] = ` -(SchemaElement - (MemberElement - (StringElement) - (ObjectElement - (MemberElement - (StringElement) - (ReferenceElement - (MemberElement - (StringElement) - (StringElement))))))) -`; - exports[`refractor elements SchemaElement given properties keyword with reference should refract to semantic ApiDOM tree 1`] = ` (SchemaElement (MemberElement @@ -117,9 +69,6 @@ exports[`refractor elements SchemaElement should refract to semantic ApiDOM tree (MemberElement (StringElement) (StringElement)) - (MemberElement - (StringElement) - (StringElement)) (MemberElement (StringElement) (NumberElement)) @@ -144,13 +93,6 @@ exports[`refractor elements SchemaElement should refract to semantic ApiDOM tree (MemberElement (StringElement) (StringElement)) - (MemberElement - (StringElement) - (SchemaElement)) - (MemberElement - (StringElement) - (ArrayElement - (ObjectElement))) (MemberElement (StringElement) (NumberElement)) @@ -171,27 +113,6 @@ exports[`refractor elements SchemaElement should refract to semantic ApiDOM tree (ArrayElement (StringElement) (StringElement))) - (MemberElement - (StringElement) - (ObjectElement - (MemberElement - (StringElement) - (SchemaElement)))) - (MemberElement - (StringElement) - (SchemaElement)) - (MemberElement - (StringElement) - (ObjectElement - (MemberElement - (StringElement) - (SchemaElement)))) - (MemberElement - (StringElement) - (ObjectElement - (MemberElement - (StringElement) - (SchemaElement)))) (MemberElement (StringElement) (ArrayElement @@ -216,6 +137,9 @@ exports[`refractor elements SchemaElement should refract to semantic ApiDOM tree (MemberElement (StringElement) (SchemaElement)) + (MemberElement + (StringElement) + (SchemaElement)) (MemberElement (StringElement) (ObjectElement @@ -224,13 +148,7 @@ exports[`refractor elements SchemaElement should refract to semantic ApiDOM tree (SchemaElement)))) (MemberElement (StringElement) - (StringElement)) - (MemberElement - (StringElement) - (StringElement)) - (MemberElement - (StringElement) - (NumberElement)) + (SchemaElement)) (MemberElement (StringElement) (StringElement)) @@ -239,11 +157,7 @@ exports[`refractor elements SchemaElement should refract to semantic ApiDOM tree (StringElement)) (MemberElement (StringElement) - (ArrayElement - (LinkDescriptionElement))) - (MemberElement - (StringElement) - (MediaElement)) + (NumberElement)) (MemberElement (StringElement) (BooleanElement)) diff --git a/packages/apidom-ns-openapi-3-0/test/refractor/elements/Schema/index.ts b/packages/apidom-ns-openapi-3-0/test/refractor/elements/Schema/index.ts index 430b7da2c7..dc88a5fb0a 100644 --- a/packages/apidom-ns-openapi-3-0/test/refractor/elements/Schema/index.ts +++ b/packages/apidom-ns-openapi-3-0/test/refractor/elements/Schema/index.ts @@ -8,9 +8,8 @@ describe('refractor', function () { context('SchemaElement', function () { specify('should refract to semantic ApiDOM tree', function () { const schemaElement = SchemaElement.refract({ - // JSON Schema vocabulary - id: 'http://x.y.z/rootschema.json#', - $schema: 'http://json-schema.org/draft-04/schema#', + // the following properties are taken directly from the JSON Schema definition and follow the same specifications + title: 'title', multipleOf: 1, maximum: 2, exclusiveMaximum: true, @@ -19,34 +18,27 @@ describe('refractor', function () { maxLength: 6, minLength: 7, pattern: '[a-z]+', - additionalItems: {}, - items: [{}], maxItems: 8, minItems: 9, uniqueItems: true, maxProperties: 10, minProperties: 11, required: ['prop1', 'prop2'], - properties: { prop1: {} }, - additionalProperties: {}, - patternProperties: { '[a-z]+': {} }, - dependencies: { dep1: {} }, enum: [1, '2', null], + // the following properties are taken from the JSON Schema definition but their definitions were adjusted to the OpenAPI Specification type: 'string', allOf: [{}], anyOf: [{}], oneOf: [{}], not: {}, - definitions: { def1: {} }, - title: 'title', + items: {}, + properties: { prop1: {} }, + additionalProperties: {}, description: 'description', - default: 3, format: 'url', - base: '/object/{id}', - links: [{}], - media: {}, + default: 3, readOnly: false, - // OpenAPI vocabulary, + // OpenAPI vocabulary nullable: true, discriminator: {}, writeOnly: false, @@ -72,9 +64,6 @@ describe('refractor', function () { context('given embedded SchemaElements', function () { specify('should refract to semantic ApiDOM tree', function () { const schemaElement = SchemaElement.refract({ - definitions: { - enabledToggle: { not: {} }, - }, allOf: [{ not: {} }], }); @@ -133,40 +122,6 @@ describe('refractor', function () { }); }); - context('given definitions keyword with reference', function () { - const schemaElement = SchemaElement.refract({ - definitions: { def1: { $ref: '#/path/to/schema' } }, - }) as SchemaElement; - - specify('should refract to semantic ApiDOM tree', function () { - expect(sexprs(schemaElement)).toMatchSnapshot(); - }); - - specify('should contain referenced-element meta', function () { - const referenceElement = schemaElement.definitions?.get('def1'); - const referencedElementMeta = referenceElement?.getMetaProperty('referenced-element'); - - assert.strictEqual(toValue(referencedElementMeta), 'schema'); - }); - }); - - context('given dependencies keyword with reference', function () { - const schemaElement = SchemaElement.refract({ - dependencies: { dep1: { $ref: '#/path/to/schema' } }, - }) as SchemaElement; - - specify('should refract to semantic ApiDOM tree', function () { - expect(sexprs(schemaElement)).toMatchSnapshot(); - }); - - specify('should contain referenced-element meta', function () { - const referenceElement = schemaElement.dependencies?.get('dep1'); - const referencedElementMeta = referenceElement?.getMetaProperty('referenced-element'); - - assert.strictEqual(toValue(referencedElementMeta), 'schema'); - }); - }); - context('given properties keyword with reference', function () { const schemaElement = SchemaElement.refract({ properties: { prop1: { $ref: '#/path/to/schema' } }, @@ -183,23 +138,6 @@ describe('refractor', function () { assert.strictEqual(toValue(referencedElementMeta), 'schema'); }); }); - - context('given patternProperties keyword with reference', function () { - const schemaElement = SchemaElement.refract({ - patternProperties: { pattern: { $ref: '#/path/to/schema' } }, - }) as SchemaElement; - - specify('should refract to semantic ApiDOM tree', function () { - expect(sexprs(schemaElement)).toMatchSnapshot(); - }); - - specify('should contain referenced-element meta', function () { - const referenceElement = schemaElement.patternProperties?.get('pattern'); - const referencedElementMeta = referenceElement?.getMetaProperty('referenced-element'); - - assert.strictEqual(toValue(referencedElementMeta), 'schema'); - }); - }); }); }); });