Skip to content

Commit 6047588

Browse files
committed
feat: support for nextJS
1 parent f4a3eab commit 6047588

4 files changed

Lines changed: 62 additions & 3 deletions

File tree

generator/e2e-tests-generator.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const _ = require('lodash');
22
const namor = require('namor');
3-
const getDefinitionSchemaFromRef = require('../src/helpers/get-definition-schema');
3+
const getDefinitionSchemaFromRef = require('../src/helpers/get-definition-schema-nodejs');
44

55
const generateTestFile = ({
66
schema,

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@
153153
"immutability-helper": "^2.6.5 || ^3.0.0",
154154
"shortid": "2.2.15"
155155
},
156-
"version": "3.0.0-alpha.3",
156+
"version": "3.0.0-alpha.4",
157157
"directories": {
158158
"doc": "docs"
159159
},
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Library
2+
const get = require('lodash/get');
3+
const find = require('lodash/find');
4+
const omit = require('lodash/omit');
5+
6+
const getDefinitionSchemaFromRef = (
7+
givenDefinitions,
8+
schemaProperties,
9+
formData,
10+
// transformSchema,
11+
) => {
12+
try {
13+
const definitions = { ...givenDefinitions };
14+
const definitionSchema = {
15+
...get(
16+
definitions,
17+
schemaProperties.$ref.replace('#/definitions/', '').replace('/', '.'),
18+
),
19+
};
20+
if (definitionSchema.dependencies) {
21+
Object.keys(definitionSchema.properties).forEach((propId) => {
22+
const propIdValue = formData && formData[propId];
23+
if (definitionSchema.dependencies[propId]) {
24+
const conditionals = definitionSchema.dependencies[propId].oneOf
25+
|| definitionSchema.dependencies[propId].anyOf;
26+
const conditionalSchemaProps = find(conditionals, [
27+
`properties.${propId}.const`,
28+
propIdValue,
29+
]);
30+
if (definitionSchema.properties) {
31+
definitionSchema.properties = conditionalSchemaProps
32+
? {
33+
...conditionalSchemaProps.properties,
34+
...definitionSchema.properties,
35+
}
36+
: {
37+
...definitionSchema.properties,
38+
};
39+
}
40+
}
41+
});
42+
}
43+
44+
return {
45+
...schemaProperties,
46+
title: schemaProperties.title || definitionSchema.title,
47+
...omit(definitionSchema, ['dependencies']),
48+
};
49+
}
50+
catch (err) {
51+
console.log('error found', err);
52+
return {
53+
...schemaProperties,
54+
title: schemaProperties.title,
55+
};
56+
}
57+
};
58+
59+
module.exports = getDefinitionSchemaFromRef;

src/helpers/get-definition-schema.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,4 @@ const getDefinitionSchemaFromRef = (
5656
}
5757
};
5858

59-
module.exports = getDefinitionSchemaFromRef;
59+
export default getDefinitionSchemaFromRef;

0 commit comments

Comments
 (0)