diff --git a/packages/apidom-ns-json-schema-draft-7/src/elements/LinkDescription.ts b/packages/apidom-ns-json-schema-draft-7/src/elements/LinkDescription.ts index 4d2a3cd214..7feae85248 100644 --- a/packages/apidom-ns-json-schema-draft-7/src/elements/LinkDescription.ts +++ b/packages/apidom-ns-json-schema-draft-7/src/elements/LinkDescription.ts @@ -1,6 +1,16 @@ -import { StringElement, ObjectElement, ArrayElement } from '@swagger-api/apidom-core'; +import { + StringElement, + ObjectElement, + ArrayElement, + BooleanElement, +} from '@swagger-api/apidom-core'; import { UnsupportedOperationError } from '@swagger-api/apidom-error'; -import { LinkDescriptionElement } from '@swagger-api/apidom-ns-json-schema-draft-6'; +import { + LinkDescriptionElement, + JSONReferenceElement, +} from '@swagger-api/apidom-ns-json-schema-draft-6'; + +import JSONSchema from './JSONSchema.ts'; /* eslint-disable class-methods-use-this */ @@ -104,6 +114,19 @@ class LinkDescription extends LinkDescriptionElement { this.set('$comment', $comment); } + /** + * Link Input. + * + * URI: https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-hyperschema-01#section-6.6 + */ + get headerSchema(): JSONSchema | BooleanElement | JSONReferenceElement | undefined { + return this.get('headerSchema'); + } + + set headerSchema(headerSchema: JSONSchema | BooleanElement | JSONReferenceElement | undefined) { + this.set('headerSchema', headerSchema); + } + /** * Submitting Data for Processing. * diff --git a/packages/apidom-ns-json-schema-draft-7/src/refractor/plugins/replace-empty-element.ts b/packages/apidom-ns-json-schema-draft-7/src/refractor/plugins/replace-empty-element.ts index 2f1cd4ed3f..32b699dca1 100644 --- a/packages/apidom-ns-json-schema-draft-7/src/refractor/plugins/replace-empty-element.ts +++ b/packages/apidom-ns-json-schema-draft-7/src/refractor/plugins/replace-empty-element.ts @@ -159,6 +159,9 @@ const schema = { targetHints(...args: any[]) { return new ObjectElement(...args); }, + headerSchema(...args: any[]) { + return new JSONSchemaElement(...args); + }, }, 'json-schema-properties': { '[key: *]': function key(...args: any[]) { diff --git a/packages/apidom-ns-json-schema-draft-7/src/refractor/specification.ts b/packages/apidom-ns-json-schema-draft-7/src/refractor/specification.ts index b9e178500d..7b29a61971 100644 --- a/packages/apidom-ns-json-schema-draft-7/src/refractor/specification.ts +++ b/packages/apidom-ns-json-schema-draft-7/src/refractor/specification.ts @@ -66,6 +66,10 @@ const specification = pipe( ['visitors', 'document', 'objects', 'LinkDescription', 'fixedFields', '$comment'], specificationObj.visitors.value, ), + assocPath( + ['visitors', 'document', 'objects', 'LinkDescription', 'fixedFields', 'headerSchema'], + specificationObj.visitors.JSONSchemaOrJSONReferenceVisitor, + ), dissocPath([ 'visitors', 'document', diff --git a/packages/apidom-ns-json-schema-draft-7/test/refractor/elements/LinkDescription/__snapshots__/index.mjs.snap b/packages/apidom-ns-json-schema-draft-7/test/refractor/elements/LinkDescription/__snapshots__/index.mjs.snap index 124b9d9f2b..a6dc94e19d 100644 --- a/packages/apidom-ns-json-schema-draft-7/test/refractor/elements/LinkDescription/__snapshots__/index.mjs.snap +++ b/packages/apidom-ns-json-schema-draft-7/test/refractor/elements/LinkDescription/__snapshots__/index.mjs.snap @@ -30,6 +30,9 @@ exports[`refractor elements LinkDescription should refract to semantic ApiDOM tr (MemberElement (StringElement) (JSONSchemaDraft7Element)) + (MemberElement + (StringElement) + (JSONSchemaDraft7Element)) (MemberElement (StringElement) (StringElement)) diff --git a/packages/apidom-ns-json-schema-draft-7/test/refractor/elements/LinkDescription/index.ts b/packages/apidom-ns-json-schema-draft-7/test/refractor/elements/LinkDescription/index.ts index bae3a0c501..f2914c4153 100644 --- a/packages/apidom-ns-json-schema-draft-7/test/refractor/elements/LinkDescription/index.ts +++ b/packages/apidom-ns-json-schema-draft-7/test/refractor/elements/LinkDescription/index.ts @@ -18,6 +18,7 @@ describe('refractor', function () { templateRequired: ['id'], href: 'things/{id}', hrefSchema: {}, + headerSchema: {}, rel: 'image/png', title: 'title', targetSchema: {}, diff --git a/packages/apidom-ns-json-schema-draft-7/test/refractor/plugins/replace-empty-element/__snapshots__/mappings.mjs.snap b/packages/apidom-ns-json-schema-draft-7/test/refractor/plugins/replace-empty-element/__snapshots__/mappings.mjs.snap index 6d01dd15a1..48a38077d6 100644 --- a/packages/apidom-ns-json-schema-draft-7/test/refractor/plugins/replace-empty-element/__snapshots__/mappings.mjs.snap +++ b/packages/apidom-ns-json-schema-draft-7/test/refractor/plugins/replace-empty-element/__snapshots__/mappings.mjs.snap @@ -13,6 +13,20 @@ exports[`given JSON Schema definition with no empty values should do nothing 1`] (JSONSchemaDraft7Element))))) `; +exports[`given empty value for LinkDescription.headerSchema field should replace empty value with semantic element 1`] = ` +(JSONSchemaDraft7Element + (MemberElement + (StringElement) + (StringElement)) + (MemberElement + (StringElement) + (ArrayElement + (LinkDescriptionElement + (MemberElement + (StringElement) + (JSONSchemaDraft7Element)))))) +`; + exports[`given empty value for LinkDescription.hrefSchema field should replace empty value with semantic element 1`] = ` (JSONSchemaDraft7Element (MemberElement diff --git a/packages/apidom-ns-json-schema-draft-7/test/refractor/plugins/replace-empty-element/mappings.ts b/packages/apidom-ns-json-schema-draft-7/test/refractor/plugins/replace-empty-element/mappings.ts index 2655dadac9..34f63cf41f 100644 --- a/packages/apidom-ns-json-schema-draft-7/test/refractor/plugins/replace-empty-element/mappings.ts +++ b/packages/apidom-ns-json-schema-draft-7/test/refractor/plugins/replace-empty-element/mappings.ts @@ -221,6 +221,22 @@ describe('given empty value for LinkDescription.targetHints field', function () }); }); +describe('given empty value for LinkDescription.headerSchema field', function () { + it('should replace empty value with semantic element', async function () { + const yamlDefinition = dedent` + $schema: 'http://json-schema.org/draft-07/schema#' + links: + - headerSchema: + `; + const apiDOM = await parse(yamlDefinition); + const jsonSchemaElement = JSONSchemaElement.refract(apiDOM.result, { + plugins: [refractorPluginReplaceEmptyElement()], + }) as JSONSchemaElement; + + expect(sexprs(jsonSchemaElement)).toMatchSnapshot(); + }); +}); + describe('given JSON Schema definition with no empty values', function () { it('should do nothing', async function () { const yamlDefinition = dedent`