Skip to content

Commit eb8bb3f

Browse files
Merge pull request #6 from lenchvolodymyr/feature/enable-forward-to-api-schema
Feature/enable forward to api schema
2 parents 653cd59 + b187f1b commit eb8bb3f

File tree

1,839 files changed

+19926
-114807
lines changed

Some content is hidden

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

1,839 files changed

+19926
-114807
lines changed

forward_engineering/config.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,6 @@
2121
{ "name": "YAML", "keyword": "yaml", "fileExtensions": [ {
2222
"label": "application/yaml", "value": "yaml"
2323
} ] }
24-
]
24+
],
25+
"isApiSchema": true
2526
}

forward_engineering/helpers/componentsHelpers/parametersHelper.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,15 @@ function getContent(data) {
9595
}
9696

9797
return Object.keys(data.properties).reduce((acc, key) => {
98-
if (!get(data, `properties[${key}].properties`)) {
98+
const properties = get(data, `properties[${key}].properties`);
99+
if (!properties) {
99100
return;
100-
}
101+
}
102+
const isSchemaEmpty = properties.schema && get(properties.schema, 'type') === 'object' && !get(properties.schema, 'properties');
103+
const isExamplesEmpty = !get(properties, 'examples.properties');
104+
if (isSchemaEmpty && isExamplesEmpty) {
105+
return;
106+
}
101107
acc[key] = mapMediaTypeObject(data.properties[key]);
102108
return acc;
103109
}, {});

forward_engineering/helpers/pathHelper.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ function getRequestData(collections, containers, containerId, containersPath = [
6262
methodName: data.collectionName,
6363
isActivated: data.isActivated
6464
};
65-
const extensions = getExtensions(data.operationExtensions);
65+
const extensions = getExtensions(data.scopesExtensions);
6666

6767
return Object.assign({}, request, extensions);
6868
})
@@ -103,9 +103,10 @@ function mapResponses(collections, collectionId, isParentActivated) {
103103
.map(collection => {
104104
const responseCode = collection.collectionName;
105105
const shouldResponseBeCommented = !collection.isActivated && isParentActivated;
106+
const extensions = getExtensions(collection.scopesExtensions);
106107
const response = mapResponse(get(collection, 'properties.response'), collection.description, shouldResponseBeCommented);
107108

108-
return { responseCode, response };
109+
return { responseCode, response: { ...response, ...extensions } };
109110
})
110111
.reduce((acc, { responseCode, response }) => {
111112
acc[responseCode] = response;
@@ -137,8 +138,9 @@ function getCallbacks(data, containers, containerId, containersPath = []) {
137138
containers,
138139
[...containersPath, containerId]
139140
);
141+
const extensions = getExtensions(value.scopesExtensions);
140142

141-
return { [key]: { [value.callbackExpression]: callbackData }};
143+
return { [key]: { [value.callbackExpression]: callbackData, ...extensions }};
142144

143145
})
144146
.reduce((acc, item) => {

forward_engineering/helpers/typeHelper.js

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ function getType(data, key) {
2121
function getTypeProps(data, key) {
2222
const { type, properties, items, required } = data;
2323

24+
const extensions = getExtensions(data.scopesExtensions);
25+
2426
switch (type) {
2527
case 'array': {
2628
const arrayProps = {
@@ -37,7 +39,7 @@ function getTypeProps(data, key) {
3739
};
3840
const arrayChoices = getChoices(data, key);
3941

40-
return Object.assign({}, arrayProps, arrayChoices);
42+
return Object.assign({}, arrayProps, arrayChoices, extensions);
4143
}
4244
case 'object': {
4345
const objectProps = {
@@ -56,7 +58,7 @@ function getTypeProps(data, key) {
5658
};
5759
const objectChoices = getChoices(data, key);
5860

59-
return Object.assign({}, objectProps, objectChoices);
61+
return Object.assign({}, objectProps, objectChoices, extensions);
6062
}
6163
case 'parameter':
6264
if (!properties || properties.length === 0) {
@@ -90,16 +92,22 @@ function getRef({ $ref: ref }) {
9092
}
9193

9294
const schemaIndex = path.indexOf('schema');
93-
const schemaPath = schemaIndex === -1 ? [] : path.slice(schemaIndex);
94-
const pathWithoutProperties = path.slice(0, schemaIndex).filter(item => item !== 'properties');
95-
const bucketWithRequest = (path[1] === 'definitions') ? path[1] : pathWithoutProperties.slice(0,2);
96-
95+
const hasSchema = schemaIndex !== -1;
96+
const isComponents = (path[1] === 'definitions');
97+
const schemaPath = !hasSchema ? [] : path.slice(schemaIndex);
98+
const pathWithoutProperties = (hasSchema ? path.slice(0, schemaIndex) : path).filter(item => item !== 'properties');
99+
const bucketWithRequest = isComponents ? ['components'] : pathWithoutProperties.slice(0,2);
100+
const parentElementName = isComponents ? 'components' : 'paths';
97101
if (pathWithoutProperties[3] !== 'response') {
98102
if (pathWithoutProperties[2] !== 'requestBody') {
99-
return { $ref: `${pathToFile}#/paths/${[ ...pathWithoutProperties, ...schemaPath].join('/')}` };
103+
if (isComponents) {
104+
return { $ref: `${pathToFile}#/${parentElementName}/${[ ...pathWithoutProperties.slice(2), ...schemaPath].join('/')}` };
105+
}
106+
107+
return { $ref: `${pathToFile}#/${parentElementName}/${[ ...pathWithoutProperties , ...schemaPath].join('/')}` };
100108
}
101109

102-
return { $ref: `${pathToFile}#/paths/${[ ...bucketWithRequest, 'requestBody', 'content', ...pathWithoutProperties.slice(3), ...schemaPath].join('/')}` };
110+
return { $ref: `${pathToFile}#/${parentElementName}/${[ ...bucketWithRequest, 'requestBody', 'content', ...pathWithoutProperties.slice(3), ...schemaPath].join('/')}` };
103111
}
104112

105113
const response = pathWithoutProperties[2];
@@ -161,7 +169,8 @@ function getPrimitiveTypeProps(data) {
161169
maxLength: data.maxLength,
162170
multipleOf: data.multipleOf,
163171
xml: getXml(data.xml),
164-
example: data.sample
172+
example: data.sample,
173+
...getExtensions(data.scopesExtensions)
165174
};
166175

167176
return addIfTrue(properties, 'nullable', data.nullable);

forward_engineering/node_modules/.bin/z-schema

Lines changed: 0 additions & 1 deletion
This file was deleted.

forward_engineering/node_modules/.bin/z-schema

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

forward_engineering/node_modules/@apidevtools/json-schema-ref-parser/CHANGELOG.md

Lines changed: 167 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)