Skip to content

Commit 4be7821

Browse files
committed
Merge branch 'oneOf' into 'master'
Implement oneOf, anyOf & discriminator, refactor schema resolution See merge request mistio/mist-form!42
2 parents db5b35f + c850d9d commit 4be7821

25 files changed

+2987
-17430
lines changed

.gitignore

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44

55
## system files
66
.DS_Store
7-
7+
.storybook
8+
/stories
9+
/storybook-static
810
## npm
911
/node_modules/
1012
/npm-debug.log
11-
13+
/instrumented/
1214
## testing
1315
/coverage/
1416

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ Add mist-form to the DOM, providing a JSON Schema document. You may also provide
2929

3030
As an alternative, pass a url to the JSON Schema. The file may include the UI Schema & initial form data.
3131
```html
32-
<mist-form .url=${url}>
33-
32+
<mist-form method="POST" action="/api/v2/clouds"
33+
url="https://storage.googleapis.com/mist-api-spec/v2/master/mist-api-v2.json#/components/schemas/AddCloudRequest">
3434
</mist-form>
3535
```
3636

cypress/plugins/index.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,12 @@
1515
/**
1616
* @type {Cypress.PluginConfig}
1717
*/
18-
// eslint-disable-next-line no-unused-vars
1918
module.exports = (on, config) => {
20-
// `on` is used to hook into various events Cypress emits
21-
// `config` is the resolved Cypress config
19+
// eslint-disable-next-line global-require
20+
require('@cypress/code-coverage/task')(on, config);
21+
// include any other plugin code...
22+
23+
// It's IMPORTANT to return the config object
24+
// with any changed environment variables
25+
return config;
2226
};

cypress/support/commands.js

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,29 +24,29 @@
2424
// -- This will overwrite an existing command --
2525
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
2626

27-
Cypress.Commands.add('paperTextAreaType', (locator, text) => {
28-
cy.get(locator, {
29-
includeShadowDom: true,
30-
})
31-
.find('textarea')
32-
.type(text, { force: true, delay: 150 });
33-
cy.get(locator, {
34-
includeShadowDom: true,
35-
})
36-
.find('textarea')
37-
.then(el => {
38-
cy.window().then(win => {
39-
el[0].dispatchEvent(new win.Event('input', { composed: true }));
40-
});
41-
});
42-
});
27+
// Cypress.Commands.add('paperTextAreaType', (locator, text) => {
28+
// cy.get(locator, {
29+
// includeShadowDom: true,
30+
// })
31+
// .find('textarea')
32+
// .type(text, { force: true, delay: 150 });
33+
// cy.get(locator, {
34+
// includeShadowDom: true,
35+
// })
36+
// .find('textarea')
37+
// .then(el => {
38+
// cy.window().then(win => {
39+
// el[0].dispatchEvent(new win.Event('input', { composed: true }));
40+
// });
41+
// });
42+
// });
4343

44-
Cypress.Commands.add('testPaperDropdownSelected', (locator, text) => {
45-
cy.get(locator, {
46-
includeShadowDom: true,
47-
})
48-
.find('paper-dropdown-menu > paper-listbox')
49-
.then(el => {
50-
expect(el[0].selected).to.equal(text);
51-
});
52-
});
44+
// Cypress.Commands.add('testPaperDropdownSelected', (locator, text) => {
45+
// cy.get(locator, {
46+
// includeShadowDom: true,
47+
// })
48+
// .find('paper-dropdown-menu > paper-listbox')
49+
// .then(el => {
50+
// expect(el[0].selected).to.equal(text);
51+
// });
52+
// });

cypress/support/index.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212
// You can read more here:
1313
// https://on.cypress.io/configuration
1414
// ***********************************************************
15+
import '@cypress/code-coverage/support';
1516

1617
// Import commands.js using ES2015 syntax:
1718
import './commands.js';
18-
19-
// Alternatively you can use CommonJS syntax:
20-
// require('./commands')

demo/demo.html

Lines changed: 0 additions & 79 deletions
This file was deleted.

demo/index.html

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ <h1>mist-form</h1>
6868
// {id: 'ordering'},
6969
{id: 'references'},
7070
// {id: 'custom'},
71-
{id: 'errors'},
71+
// {id: 'errors'},
7272
{id: 'examples'},
7373
{id: 'large'},
7474
{id: 'datetime', title: "Date & Time"},
@@ -81,8 +81,8 @@ <h1>mist-form</h1>
8181
// {id: 'propdeps', title: "Property dependencies"},
8282
// {id: 'schemadeps', title: "Schema dependencies"},
8383
// {id: 'addprops', title: "Additional Properties"},
84-
// {id: 'anyof', title: "Any Of"},
85-
// {id: 'oneof', title: "One Of"},
84+
{id: 'anyof', title: "Any Of"},
85+
{id: 'oneof', title: "One Of"},
8686
{id: 'allof', title: "All Of"},
8787
{id: 'ifthenelse', title: "If Then Else"},
8888
// {id: 'nullfields', title: "Null Fields"},
@@ -99,10 +99,12 @@ <h1>mist-form</h1>
9999
]
100100
}
101101

102+
// eslint-disable-next-line func-names
102103
export const debouncer = function (callback, wait) {
103104
let timeout = 1000;
104105
return (...args) => {
105106
clearTimeout(timeout);
107+
// eslint-disable-next-line func-names
106108
timeout = setTimeout(function () {
107109
callback.apply(this, args);
108110
}, wait);
@@ -165,13 +167,14 @@ <h1>mist-form</h1>
165167
const newValue = formDataEditor.getValue();
166168
try {
167169
document.querySelector('mist-form').formData = JSON.parse(newValue);
168-
} catch(e) {
170+
} catch {
169171
if (document.querySelector('mist-form').formData !== newValue) {
170172
document.querySelector('mist-form').formData = newValue;
171173
}
172174
}
173175
}, 150));
174-
document.querySelector('mist-form').addEventListener('form-data-changed', function(e) {
176+
// eslint-disable-next-line func-names
177+
document.querySelector('mist-form').addEventListener('form-data-changed', function() {
175178
let newValue = this.domValue;
176179
switch (typeof(newValue)) {
177180
case "string":
@@ -191,7 +194,7 @@ <h1>mist-form</h1>
191194
formDataEditor.setValue(newValue);
192195
}
193196
});
194-
updateTab();
197+
document.querySelector('mist-form').dispatchEvent(new CustomEvent('form-data-changed', {detail: {}, bubbles:true, composed: true}));
195198
});
196199
function updateTab(e) {
197200
const preset = e ? e.detail.value : 0;
@@ -200,9 +203,10 @@ <h1>mist-form</h1>
200203
.then(response => response.json())
201204
.then(async body => {
202205
const form = document.querySelector('mist-form#playground');
203-
form.jsonSchema = body.jsonSchema;
206+
// debugger;
207+
form.formData = body.formData || {};
208+
form.jsonSchema = body.jsonSchema || body;
204209
form.uiSchema = body.uiSchema;
205-
form.formData = body.formData;
206210
if (jsonSchemaEditor) jsonSchemaEditor.setValue(JSON.stringify(body.jsonSchema || body, null, 2));
207211
if (uiSchemaEditor) uiSchemaEditor.setValue(JSON.stringify(body.uiSchema || {}, null, 2));
208212
if (formDataEditor) formDataEditor.setValue(JSON.stringify(body.formData || {}, null, 2));

demo/mist/addcloud.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"jsonSchema": {
3+
"$ref": "https://storage.googleapis.com/mist-api-spec/v2/amazon-regions/mist-api-v2.json#/components/schemas/AddCloudRequest"
4+
},
5+
"uiSchema": {},
6+
"formData": {}
7+
}

demo/oneof.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"type": "object",
44
"oneOf": [
55
{
6+
"title": "lorem",
67
"properties": {
78
"lorem": {
89
"type": "string"
@@ -13,6 +14,7 @@
1314
]
1415
},
1516
{
17+
"title": "ipsum",
1618
"properties": {
1719
"ipsum": {
1820
"type": "string"

demo/references.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
"children": {
3030
"type": "array",
3131
"items": {
32-
"$ref": "#/definitions/node"
3332
}
3433
}
3534
}
@@ -44,10 +43,6 @@
4443
"shipping_address": {
4544
"title": "Shipping address",
4645
"$ref": "#/definitions/address"
47-
},
48-
"tree": {
49-
"title": "Recursive references",
50-
"$ref": "#/definitions/node"
5146
}
5247
}
5348
},

0 commit comments

Comments
 (0)