Skip to content

Commit

Permalink
feat(ns-json-schema-draft-4): complete replace empty elements plugin
Browse files Browse the repository at this point in the history
Refs #1814
  • Loading branch information
char0n committed Aug 17, 2022
1 parent 4367a9e commit 52ac8d4
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,14 @@ const schema = {
return new MediaElement(...args);
},
},
LinkDescriptionElement: {
targetSchema(...args: any[]) {
return new JSONSchemaElement(...args);
},
schema(...args: any[]) {
return new JSONSchemaElement(...args);
},
},
'json-schema-properties': {
'[key: *]': function key(...args: any[]) {
return new JSONSchemaElement(...args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,34 @@ exports[`given JSON Schema definition with no empty values should do nothing 1`]
(JSONSchemaDraft4Element)))))
`;

exports[`given empty value for LinkDescription.schema field should replace empty value with semantic element 1`] = `
(JSONSchemaDraft4Element
(MemberElement
(StringElement)
(StringElement))
(MemberElement
(StringElement)
(ArrayElement
(LinkDescriptionElement
(MemberElement
(StringElement)
(JSONSchemaDraft4Element))))))
`;

exports[`given empty value for LinkDescription.targetSchema field should replace empty value with semantic element 1`] = `
(JSONSchemaDraft4Element
(MemberElement
(StringElement)
(StringElement))
(MemberElement
(StringElement)
(ArrayElement
(LinkDescriptionElement
(MemberElement
(StringElement)
(JSONSchemaDraft4Element))))))
`;

exports[`given empty value for field additionalItems should replace empty value with semantic element 1`] = `
(JSONSchemaDraft4Element
(MemberElement
Expand Down Expand Up @@ -43,6 +71,19 @@ exports[`given empty value for field patternProperties should replace empty valu
(ObjectElement)))
`;

exports[`given empty value for properties field should replace empty value with semantic element 1`] = `
(JSONSchemaDraft4Element
(MemberElement
(StringElement)
(StringElement))
(MemberElement
(StringElement)
(ObjectElement
(MemberElement
(StringElement)
(JSONSchemaDraft4Element)))))
`;

exports[`given empty value instead for properties field keys should replace empty value with semantic element 1`] = `
(JSONSchemaDraft4Element
(MemberElement
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe('given empty value for field enum', function () {
});
});

describe('given empty value instead for properties field keys', function () {
describe('given empty value for properties field', function () {
it('should replace empty value with semantic element', async function () {
const yamlDefinition = dedent`
$schema: 'http://json-schema.org/draft-04/schema#'
Expand All @@ -66,6 +66,38 @@ describe('given empty value instead for properties field keys', function () {
});
});

describe('given empty value for LinkDescription.targetSchema field', function () {
it('should replace empty value with semantic element', async function () {
const yamlDefinition = dedent`
$schema: 'http://json-schema.org/draft-04/schema#'
links:
- targetSchema:
`;
const apiDOM = await parse(yamlDefinition);
const jsonSchemaElement = JSONSchemaElement.refract(apiDOM.result, {
plugins: [refractorPluginReplaceEmptyElement()],
}) as JSONSchemaElement;

expect(sexprs(jsonSchemaElement)).toMatchSnapshot();
});
});

describe('given empty value for LinkDescription.schema field', function () {
it('should replace empty value with semantic element', async function () {
const yamlDefinition = dedent`
$schema: 'http://json-schema.org/draft-04/schema#'
links:
- schema:
`;
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`
Expand Down

0 comments on commit 52ac8d4

Please sign in to comment.