Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ns-openapi-3): support only subset of JSON Schema Draft 4/5 #3265

Merged
merged 1 commit into from
Oct 13, 2023
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
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/apidom-ns-openapi-3-0/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
98 changes: 96 additions & 2 deletions packages/apidom-ns-openapi-3-0/src/elements/Schema.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,49 @@
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<string, unknown>, meta?: Meta, attributes?: Attributes) {
super(content, meta, attributes);
this.element = 'schema';
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
*/
Expand Down Expand Up @@ -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
*/
Expand All @@ -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
*/
Expand Down Expand Up @@ -127,5 +220,6 @@ class Schema extends JSONSchemaElement {
this.set('deprecated', deprecated);
}
}
/* eslint-disable class-methods-use-this */

export default Schema;
114 changes: 63 additions & 51 deletions packages/apidom-ns-openapi-3-0/src/refractor/specification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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: {
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading