Skip to content

Commit 52ac8d4

Browse files
committed
feat(ns-json-schema-draft-4): complete replace empty elements plugin
Refs #1814
1 parent 4367a9e commit 52ac8d4

File tree

3 files changed

+82
-1
lines changed

3 files changed

+82
-1
lines changed

packages/apidom-ns-json-schema-draft-4/src/refractor/plugins/replace-empty-element.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,14 @@ const schema = {
121121
return new MediaElement(...args);
122122
},
123123
},
124+
LinkDescriptionElement: {
125+
targetSchema(...args: any[]) {
126+
return new JSONSchemaElement(...args);
127+
},
128+
schema(...args: any[]) {
129+
return new JSONSchemaElement(...args);
130+
},
131+
},
124132
'json-schema-properties': {
125133
'[key: *]': function key(...args: any[]) {
126134
return new JSONSchemaElement(...args);

packages/apidom-ns-json-schema-draft-4/test/refractor/plugins/replace-empty-element/__snapshots__/mappings.ts.snap

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,34 @@ exports[`given JSON Schema definition with no empty values should do nothing 1`]
1313
(JSONSchemaDraft4Element)))))
1414
`;
1515

16+
exports[`given empty value for LinkDescription.schema field should replace empty value with semantic element 1`] = `
17+
(JSONSchemaDraft4Element
18+
(MemberElement
19+
(StringElement)
20+
(StringElement))
21+
(MemberElement
22+
(StringElement)
23+
(ArrayElement
24+
(LinkDescriptionElement
25+
(MemberElement
26+
(StringElement)
27+
(JSONSchemaDraft4Element))))))
28+
`;
29+
30+
exports[`given empty value for LinkDescription.targetSchema field should replace empty value with semantic element 1`] = `
31+
(JSONSchemaDraft4Element
32+
(MemberElement
33+
(StringElement)
34+
(StringElement))
35+
(MemberElement
36+
(StringElement)
37+
(ArrayElement
38+
(LinkDescriptionElement
39+
(MemberElement
40+
(StringElement)
41+
(JSONSchemaDraft4Element))))))
42+
`;
43+
1644
exports[`given empty value for field additionalItems should replace empty value with semantic element 1`] = `
1745
(JSONSchemaDraft4Element
1846
(MemberElement
@@ -43,6 +71,19 @@ exports[`given empty value for field patternProperties should replace empty valu
4371
(ObjectElement)))
4472
`;
4573

74+
exports[`given empty value for properties field should replace empty value with semantic element 1`] = `
75+
(JSONSchemaDraft4Element
76+
(MemberElement
77+
(StringElement)
78+
(StringElement))
79+
(MemberElement
80+
(StringElement)
81+
(ObjectElement
82+
(MemberElement
83+
(StringElement)
84+
(JSONSchemaDraft4Element)))))
85+
`;
86+
4687
exports[`given empty value instead for properties field keys should replace empty value with semantic element 1`] = `
4788
(JSONSchemaDraft4Element
4889
(MemberElement

packages/apidom-ns-json-schema-draft-4/test/refractor/plugins/replace-empty-element/mappings.ts

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ describe('given empty value for field enum', function () {
5050
});
5151
});
5252

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

69+
describe('given empty value for LinkDescription.targetSchema field', function () {
70+
it('should replace empty value with semantic element', async function () {
71+
const yamlDefinition = dedent`
72+
$schema: 'http://json-schema.org/draft-04/schema#'
73+
links:
74+
- targetSchema:
75+
`;
76+
const apiDOM = await parse(yamlDefinition);
77+
const jsonSchemaElement = JSONSchemaElement.refract(apiDOM.result, {
78+
plugins: [refractorPluginReplaceEmptyElement()],
79+
}) as JSONSchemaElement;
80+
81+
expect(sexprs(jsonSchemaElement)).toMatchSnapshot();
82+
});
83+
});
84+
85+
describe('given empty value for LinkDescription.schema field', function () {
86+
it('should replace empty value with semantic element', async function () {
87+
const yamlDefinition = dedent`
88+
$schema: 'http://json-schema.org/draft-04/schema#'
89+
links:
90+
- schema:
91+
`;
92+
const apiDOM = await parse(yamlDefinition);
93+
const jsonSchemaElement = JSONSchemaElement.refract(apiDOM.result, {
94+
plugins: [refractorPluginReplaceEmptyElement()],
95+
}) as JSONSchemaElement;
96+
97+
expect(sexprs(jsonSchemaElement)).toMatchSnapshot();
98+
});
99+
});
100+
69101
describe('given JSON Schema definition with no empty values', function () {
70102
it('should do nothing', async function () {
71103
const yamlDefinition = dedent`

0 commit comments

Comments
 (0)