Skip to content

Commit 34ca63a

Browse files
committed
Choices and references in components
1 parent 7de6f95 commit 34ca63a

File tree

126 files changed

+23029
-290
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

126 files changed

+23029
-290
lines changed

forward_engineering/helpers/commonHelper.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ const get = require('lodash.get');
22
const getExtensions = require('./extensionsHelper');
33
const { hasRef } = require('./typeHelper');
44

5-
function mapEnum(enums = [], key) {
5+
function mapEnum(enums, key) {
6+
if (!enums) {
7+
return;
8+
}
69
return enums
710
.filter(item => item[key])
811
.map(item => item[key]);

forward_engineering/helpers/componentsHelpers/index.js

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ const { getSecuritySchemes } = require('./securitySchemesHelper');
77
const { getExamples } = require('./examplesHelper');
88
const { getLinks } = require('./linksHelper');
99
const { getCallbacks } = require('../pathHelper');
10-
10+
const getExtensions = require('../extensionsHelper');
1111

1212
function getComponents(data) {
13-
const componentsData = get(JSON.parse(data.modelDefinitions), 'properties', {});
13+
const componentsData = get(JSON.parse(data.modelDefinitions), 'properties', {});
1414

15-
const schemas = getSchemas(componentsData.schemas);
15+
const schemas = getSchemas(componentsData.schemas);
1616
const responses = getResponses(componentsData.responses);
1717
const parameters = getParameters(componentsData.parameters);
1818
const examples = getExamples(componentsData.examples);
@@ -22,17 +22,23 @@ function getComponents(data) {
2222
const links = getLinks(componentsData.links);
2323
const callbacks = getCallbacks(componentsData.callbacks, data.containers);
2424

25-
return {
26-
schemas,
27-
responses,
28-
parameters,
29-
examples,
30-
requestBodies,
31-
headers,
32-
securitySchemes,
33-
links,
34-
callbacks
35-
};
25+
const extensions = getExtensions(get(componentsData, `['Specification Extensions'].scopesExtensions`));
26+
27+
return Object.assign(
28+
{},
29+
{
30+
schemas,
31+
responses,
32+
parameters,
33+
examples,
34+
requestBodies,
35+
headers,
36+
securitySchemes,
37+
links,
38+
callbacks
39+
},
40+
extensions
41+
);
3642
}
3743

3844
module.exports = getComponents;

forward_engineering/helpers/componentsHelpers/parametersHelper.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ function mapParameter(data, required) {
3838
style: data.style,
3939
explode: data.explode,
4040
allowReserved: data.allowReserved,
41-
schema: mapSchema(get(data, 'properties.schema')),
41+
schema: mapSchema(get(data, 'properties.schema'), 'schema'),
4242
example: data.sample,
4343
examples: getExamples(get(data, 'properties.examples')),
4444
content: getContent(get(data, 'properties.content'))
@@ -107,15 +107,15 @@ function mapMediaTypeObject(data) {
107107
if (!data || !data.properties) {
108108
return;
109109
}
110-
let schema = mapSchema(get(data, 'properties.schema'));
110+
let schema = mapSchema(get(data, 'properties.schema'), 'schema');
111111
if (!schema && hasChoice(data)) {
112112
schema = mapSchema({
113113
type: 'object',
114114
allOf: data.allOf,
115115
oneOf: data.oneOf,
116116
anyOf: data.anyOf,
117117
not: data.not
118-
});
118+
}, 'schema');
119119
}
120120
const examples = getExamples(get(data, 'properties.examples'));
121121
const encoding = mapEncoding(get(data, 'properties.encoding'));

forward_engineering/helpers/componentsHelpers/schemasHelper.js

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
const get = require('lodash.get');
21
const typeHelper = require('../typeHelper');
32

43
function getSchemas(data) {
@@ -7,38 +6,13 @@ function getSchemas(data) {
76
}
87

98
return Object.keys(data.properties).reduce((acc, key) => {
10-
acc[key] = mapSchema(prepareSchemaChoices(data.properties[key], key));
9+
acc[key] = mapSchema(data.properties[key], key);
1110
return acc;
1211
}, {});
1312
}
1413

15-
function mapSchema(data) {
16-
return typeHelper.getType(data);
17-
}
18-
19-
function prepareSchemaChoices(definition, key) {
20-
const mapChoice = (item) => {
21-
const choiceValue = get(item, `properties.${key}`);
22-
if (choiceValue) {
23-
return choiceValue;
24-
}
25-
return item;
26-
}
27-
28-
if (!definition) {
29-
return;
30-
}
31-
const multipleChoices = ['allOf', 'anyOf', 'oneOf', 'not'];
32-
return multipleChoices.reduce((acc, choice) => {
33-
if (acc[choice]) {
34-
if (choice === 'not') {
35-
acc[choice] = mapChoice(acc[choice]);
36-
} else {
37-
acc[choice] = acc[choice].map(mapChoice);
38-
}
39-
}
40-
return acc;
41-
}, Object.assign({}, definition));
14+
function mapSchema(data, key) {
15+
return typeHelper.getType(data, key);
4216
}
4317

4418
module.exports = {

forward_engineering/helpers/typeHelper.js

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
const get = require('lodash.get');
12
const getExtensions = require('./extensionsHelper');
23

3-
function getType(data) {
4+
function getType(data, key) {
45
if (!data) {
56
return;
67
}
@@ -13,10 +14,10 @@ function getType(data) {
1314
return getRef(data);
1415
}
1516

16-
return getTypeProps(data);
17+
return getTypeProps(data, key);
1718
}
1819

19-
function getTypeProps(data) {
20+
function getTypeProps(data, key) {
2021
const { type, properties, items, required } = data;
2122

2223
switch (type) {
@@ -30,9 +31,9 @@ function getTypeProps(data) {
3031
uniqueItems: data.uniqueItems || undefined,
3132
discriminator: data.discriminator,
3233
readOnly: data.readOnly,
33-
xml: getXml(data.xml),
34+
xml: getXml(data.xml)
3435
};
35-
const arrayChoices = getChoices(data);
36+
const arrayChoices = getChoices(data, key);
3637

3738
return Object.assign({}, arrayProps, arrayChoices);
3839
}
@@ -50,7 +51,7 @@ function getTypeProps(data) {
5051
example: parseExample(data.sample),
5152
xml: getXml(data.xml)
5253
};
53-
const objectChoices = getChoices(data);
54+
const objectChoices = getChoices(data, key);
5455

5556
return Object.assign({}, objectProps, objectChoices);
5657
}
@@ -87,7 +88,7 @@ function getObjectProperties(properties) {
8788
return;
8889
}
8990
return Object.keys(properties).reduce((acc, propName) => {
90-
acc[propName] = getType(properties[propName]);
91+
acc[propName] = getType(properties[propName], propName);
9192
return acc;
9293
}, {});
9394
}
@@ -151,19 +152,31 @@ function getAdditionalProperties(data) {
151152
return getAdditionalPropsObject(data);
152153
}
153154

154-
function getChoices(data) {
155-
const choices = {};
156-
const multipleChoices = ['allOf', 'anyOf', 'oneOf'];
157-
multipleChoices.forEach(choiceName => {
158-
if (data[choiceName]) {
159-
choices[choiceName] = data[choiceName].map(getType);
155+
function getChoices(data, key) {
156+
const mapChoice = (item, key) => {
157+
const choiceValue = get(item, `properties.${key}`);
158+
if (choiceValue) {
159+
return getType(choiceValue);
160160
}
161-
})
162-
if (data.not) {
163-
choices.not = getType(data.not);
161+
return getType(item);
164162
}
165163

166-
return choices;
164+
if (!data) {
165+
return;
166+
}
167+
const { allOf, anyOf, oneOf, not } = data;
168+
const multipleChoices = ['allOf', 'anyOf', 'oneOf', 'not'];
169+
170+
return multipleChoices.reduce((acc, choice) => {
171+
if (acc[choice]) {
172+
if (choice === 'not') {
173+
acc[choice] = mapChoice(acc[choice], key);
174+
} else {
175+
acc[choice] = acc[choice].map(item => mapChoice(item, key));
176+
}
177+
}
178+
return acc;
179+
}, { allOf, anyOf, oneOf, not });
167180
}
168181

169182
function hasChoice(data) {

package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "OpenAPI",
3-
"version": "0.1.1",
4-
"versionDate": "2019-06-23",
3+
"version": "0.1.2",
4+
"versionDate": "2019-06-26",
55
"author": "hackolade",
66
"engines": {
77
"hackolade": "3.3.0",
@@ -44,7 +44,10 @@
4444
"entityLevel": true,
4545
"containerLevel": true,
4646
"fieldLevel": {
47-
"componentObject": true
47+
"componentObject": true,
48+
"operationObject": true,
49+
"extensions": true,
50+
"media": true
4851
}
4952
},
5053
"disableChildren": {

properties_pane/container_level/containerLevelConfig.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,9 @@ making sure that you maintain a proper JSON format.
164164
{
165165
"propertyName": "pattern",
166166
"propertyKeyword": "extensionPattern",
167-
"shouldValidate": false,
168-
"propertyType": "text"
167+
"shouldValidate": true,
168+
"propertyType": "text",
169+
"regex":"^x-"
169170
},
170171
{
171172
"propertyName": "value",

properties_pane/entity_level/entityLevelConfig.json

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,9 @@ making sure that you maintain a proper JSON format.
301301
{
302302
"propertyName": "pattern",
303303
"propertyKeyword": "extensionPattern",
304-
"shouldValidate": false,
305-
"propertyType": "text"
304+
"shouldValidate": true,
305+
"propertyType": "text",
306+
"regex":"^x-"
306307
},
307308
{
308309
"propertyName": "value",
@@ -446,8 +447,9 @@ making sure that you maintain a proper JSON format.
446447
{
447448
"propertyName": "pattern",
448449
"propertyKeyword": "extensionPattern",
449-
"shouldValidate": false,
450-
"propertyType": "text"
450+
"shouldValidate": true,
451+
"propertyType": "text",
452+
"regex":"^x-"
451453
},
452454
{
453455
"propertyName": "value",
@@ -472,8 +474,9 @@ making sure that you maintain a proper JSON format.
472474
{
473475
"propertyName": "pattern",
474476
"propertyKeyword": "extensionPattern",
475-
"shouldValidate": false,
476-
"propertyType": "text"
477+
"shouldValidate": true,
478+
"propertyType": "text",
479+
"regex":"^x-"
477480
},
478481
{
479482
"propertyName": "value",
@@ -498,8 +501,9 @@ making sure that you maintain a proper JSON format.
498501
{
499502
"propertyName": "pattern",
500503
"propertyKeyword": "extensionPattern",
501-
"shouldValidate": false,
502-
"propertyType": "text"
504+
"shouldValidate": true,
505+
"propertyType": "text",
506+
"regex":"^x-"
503507
},
504508
{
505509
"propertyName": "value",

0 commit comments

Comments
 (0)