Skip to content

Commit f1ef6bb

Browse files
committed
[INTERNAL] Schema: Validate optional/development flag in framework libraries
1 parent e840853 commit f1ef6bb

File tree

4 files changed

+281
-13
lines changed

4 files changed

+281
-13
lines changed

lib/validation/schema/specVersion/2.0/kind/project.json

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,47 @@
290290
"type": "boolean",
291291
"default": false
292292
}
293+
},
294+
"if": {
295+
"not": {
296+
"anyOf": [
297+
{
298+
"properties": {
299+
"optional": {"enum": [false, null]}
300+
}
301+
},
302+
{
303+
"properties": {
304+
"development": {"enum": [false, null]}
305+
}
306+
},
307+
{
308+
"not": {
309+
"properties": {
310+
"optional": {"type": "boolean"}
311+
}
312+
}
313+
},
314+
{
315+
"not": {
316+
"properties": {
317+
"development": {"type": "boolean"}
318+
}
319+
}
320+
}
321+
],
322+
"$comment": "Unfortunately it doesn't seem to work to check for both properties to be true, so instead checking for not having any of the properties to other values like false, not defined or any other type."
323+
}
324+
},
325+
"then": {
326+
"additionalProperties": false,
327+
"properties": {
328+
"name": {
329+
"type": "string"
330+
}
331+
},
332+
"errorMessage": "Either \"development\" or \"optional\" can be true, but not both",
333+
"$comment": "Defining a custom error message and only allowing the \"name\" property causes editors to show the custom error on both properties."
293334
}
294335
}
295336
}

test/lib/validation/schema/specVersion/2.0/kind/project/application.js

Lines changed: 80 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ test.before((t) => {
2626
test.after.always((t) => {
2727
t.context.ajvCoverage.createReport("html", {dir: "coverage/ajv-project-application"});
2828
const thresholds = {
29-
statements: 75,
30-
branches: 65,
29+
statements: 80,
30+
branches: 70,
3131
functions: 100,
32-
lines: 75
32+
lines: 80
3333
};
3434
t.context.ajvCoverage.verify(thresholds);
3535
});
@@ -543,7 +543,10 @@ test("framework configuration: SAPUI5", async (t) => {
543543
{"name": "sap.ui.core"},
544544
{"name": "sap.m"},
545545
{"name": "sap.f", "optional": true},
546-
{"name": "sap.ui.support", "development": true}
546+
{"name": "sap.ui.support", "development": true},
547+
{"name": "sap.ui.comp", "development": true, "optional": false},
548+
{"name": "sap.fe", "development": false, "optional": true},
549+
{"name": "sap.ui.export", "development": false, "optional": false}
547550
]
548551
}
549552
});
@@ -638,7 +641,6 @@ test("framework configuration: Invalid", async (t) => {
638641
params: {
639642
type: "boolean"
640643
},
641-
642644
schemaPath: "../project.json#/definitions/framework/properties/libraries/items/properties/optional/type",
643645
},
644646
{
@@ -673,3 +675,76 @@ test("framework configuration: Missing 'name'", async (t) => {
673675
}
674676
]);
675677
});
678+
679+
test("framework configuration: library with optional and development", async (t) => {
680+
await assertValidation(t, {
681+
"specVersion": "2.0",
682+
"type": "application",
683+
"metadata": {
684+
"name": "my-application"
685+
},
686+
"framework": {
687+
"name": "OpenUI5",
688+
"libraries": [
689+
{
690+
name: "sap.ui.lib1",
691+
development: true,
692+
optional: true
693+
},
694+
{
695+
// This should only complain about wrong types, not that both are true
696+
name: "sap.ui.lib2",
697+
development: "true",
698+
optional: "true"
699+
}
700+
]
701+
}
702+
}, [
703+
{
704+
dataPath: "/framework/libraries/0",
705+
keyword: "errorMessage",
706+
message: "Either \"development\" or \"optional\" can be true, but not both",
707+
params: {
708+
errors: [
709+
{
710+
dataPath: "/framework/libraries/0",
711+
keyword: "additionalProperties",
712+
message: "should NOT have additional properties",
713+
params: {
714+
additionalProperty: "development",
715+
},
716+
schemaPath: "../project.json#/definitions/framework/properties/libraries/items/then/additionalProperties",
717+
},
718+
{
719+
dataPath: "/framework/libraries/0",
720+
keyword: "additionalProperties",
721+
message: "should NOT have additional properties",
722+
params: {
723+
additionalProperty: "optional",
724+
},
725+
schemaPath: "../project.json#/definitions/framework/properties/libraries/items/then/additionalProperties",
726+
},
727+
],
728+
},
729+
schemaPath: "../project.json#/definitions/framework/properties/libraries/items/then/errorMessage",
730+
},
731+
{
732+
dataPath: "/framework/libraries/1/optional",
733+
keyword: "type",
734+
message: "should be boolean",
735+
params: {
736+
type: "boolean",
737+
},
738+
schemaPath: "../project.json#/definitions/framework/properties/libraries/items/properties/optional/type",
739+
},
740+
{
741+
dataPath: "/framework/libraries/1/development",
742+
keyword: "type",
743+
message: "should be boolean",
744+
params: {
745+
type: "boolean",
746+
},
747+
schemaPath: "../project.json#/definitions/framework/properties/libraries/items/properties/development/type",
748+
},
749+
]);
750+
});

test/lib/validation/schema/specVersion/2.0/kind/project/library.js

Lines changed: 80 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ test.before((t) => {
2626
test.after.always((t) => {
2727
t.context.ajvCoverage.createReport("html", {dir: "coverage/ajv-project-library"});
2828
const thresholds = {
29-
statements: 75,
30-
branches: 65,
29+
statements: 80,
30+
branches: 70,
3131
functions: 100,
32-
lines: 75
32+
lines: 80
3333
};
3434
t.context.ajvCoverage.verify(thresholds);
3535
});
@@ -615,7 +615,10 @@ test("framework configuration: SAPUI5", async (t) => {
615615
{"name": "sap.ui.core"},
616616
{"name": "sap.m"},
617617
{"name": "sap.f", "optional": true},
618-
{"name": "sap.ui.support", "development": true}
618+
{"name": "sap.ui.support", "development": true},
619+
{"name": "sap.ui.comp", "development": true, "optional": false},
620+
{"name": "sap.fe", "development": false, "optional": true},
621+
{"name": "sap.ui.export", "development": false, "optional": false}
619622
]
620623
}
621624
});
@@ -745,3 +748,76 @@ test("framework configuration: Missing 'name'", async (t) => {
745748
}
746749
]);
747750
});
751+
752+
test("framework configuration: library with optional and development", async (t) => {
753+
await assertValidation(t, {
754+
"specVersion": "2.0",
755+
"type": "library",
756+
"metadata": {
757+
"name": "my-library"
758+
},
759+
"framework": {
760+
"name": "OpenUI5",
761+
"libraries": [
762+
{
763+
name: "sap.ui.lib1",
764+
development: true,
765+
optional: true
766+
},
767+
{
768+
// This should only complain about wrong types, not that both are true
769+
name: "sap.ui.lib2",
770+
development: "true",
771+
optional: "true"
772+
}
773+
]
774+
}
775+
}, [
776+
{
777+
dataPath: "/framework/libraries/0",
778+
keyword: "errorMessage",
779+
message: "Either \"development\" or \"optional\" can be true, but not both",
780+
params: {
781+
errors: [
782+
{
783+
dataPath: "/framework/libraries/0",
784+
keyword: "additionalProperties",
785+
message: "should NOT have additional properties",
786+
params: {
787+
additionalProperty: "development",
788+
},
789+
schemaPath: "../project.json#/definitions/framework/properties/libraries/items/then/additionalProperties",
790+
},
791+
{
792+
dataPath: "/framework/libraries/0",
793+
keyword: "additionalProperties",
794+
message: "should NOT have additional properties",
795+
params: {
796+
additionalProperty: "optional",
797+
},
798+
schemaPath: "../project.json#/definitions/framework/properties/libraries/items/then/additionalProperties",
799+
},
800+
],
801+
},
802+
schemaPath: "../project.json#/definitions/framework/properties/libraries/items/then/errorMessage",
803+
},
804+
{
805+
dataPath: "/framework/libraries/1/optional",
806+
keyword: "type",
807+
message: "should be boolean",
808+
params: {
809+
type: "boolean",
810+
},
811+
schemaPath: "../project.json#/definitions/framework/properties/libraries/items/properties/optional/type",
812+
},
813+
{
814+
dataPath: "/framework/libraries/1/development",
815+
keyword: "type",
816+
message: "should be boolean",
817+
params: {
818+
type: "boolean",
819+
},
820+
schemaPath: "../project.json#/definitions/framework/properties/libraries/items/properties/development/type",
821+
},
822+
]);
823+
});

test/lib/validation/schema/specVersion/2.0/kind/project/theme-library.js

Lines changed: 80 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ test.before((t) => {
2626
test.after.always((t) => {
2727
t.context.ajvCoverage.createReport("html", {dir: "coverage/ajv-project-theme-library"});
2828
const thresholds = {
29-
statements: 70,
30-
branches: 60,
29+
statements: 75,
30+
branches: 65,
3131
functions: 100,
32-
lines: 70
32+
lines: 75
3333
};
3434
t.context.ajvCoverage.verify(thresholds);
3535
});
@@ -188,7 +188,10 @@ test("framework configuration: SAPUI5", async (t) => {
188188
{"name": "sap.ui.core"},
189189
{"name": "sap.m"},
190190
{"name": "sap.f", "optional": true},
191-
{"name": "sap.ui.support", "development": true}
191+
{"name": "sap.ui.support", "development": true},
192+
{"name": "sap.ui.comp", "development": true, "optional": false},
193+
{"name": "sap.fe", "development": false, "optional": true},
194+
{"name": "sap.ui.export", "development": false, "optional": false}
192195
]
193196
}
194197
});
@@ -297,3 +300,76 @@ test("framework configuration: Invalid", async (t) => {
297300
}
298301
]);
299302
});
303+
304+
test("framework configuration: library with optional and development", async (t) => {
305+
await assertValidation(t, {
306+
"specVersion": "2.0",
307+
"type": "theme-library",
308+
"metadata": {
309+
"name": "my-theme-library"
310+
},
311+
"framework": {
312+
"name": "OpenUI5",
313+
"libraries": [
314+
{
315+
name: "sap.ui.lib1",
316+
development: true,
317+
optional: true
318+
},
319+
{
320+
// This should only complain about wrong types, not that both are true
321+
name: "sap.ui.lib2",
322+
development: "true",
323+
optional: "true"
324+
}
325+
]
326+
}
327+
}, [
328+
{
329+
dataPath: "/framework/libraries/0",
330+
keyword: "errorMessage",
331+
message: "Either \"development\" or \"optional\" can be true, but not both",
332+
params: {
333+
errors: [
334+
{
335+
dataPath: "/framework/libraries/0",
336+
keyword: "additionalProperties",
337+
message: "should NOT have additional properties",
338+
params: {
339+
additionalProperty: "development",
340+
},
341+
schemaPath: "../project.json#/definitions/framework/properties/libraries/items/then/additionalProperties",
342+
},
343+
{
344+
dataPath: "/framework/libraries/0",
345+
keyword: "additionalProperties",
346+
message: "should NOT have additional properties",
347+
params: {
348+
additionalProperty: "optional",
349+
},
350+
schemaPath: "../project.json#/definitions/framework/properties/libraries/items/then/additionalProperties",
351+
},
352+
],
353+
},
354+
schemaPath: "../project.json#/definitions/framework/properties/libraries/items/then/errorMessage",
355+
},
356+
{
357+
dataPath: "/framework/libraries/1/optional",
358+
keyword: "type",
359+
message: "should be boolean",
360+
params: {
361+
type: "boolean",
362+
},
363+
schemaPath: "../project.json#/definitions/framework/properties/libraries/items/properties/optional/type",
364+
},
365+
{
366+
dataPath: "/framework/libraries/1/development",
367+
keyword: "type",
368+
message: "should be boolean",
369+
params: {
370+
type: "boolean",
371+
},
372+
schemaPath: "../project.json#/definitions/framework/properties/libraries/items/properties/development/type",
373+
},
374+
]);
375+
});

0 commit comments

Comments
 (0)