Skip to content

Commit 72dd1dd

Browse files
authored
Merge branch 'master' into feature/json-and-model-external-references-fe
2 parents a86141f + 717b86b commit 72dd1dd

File tree

10 files changed

+137
-61
lines changed

10 files changed

+137
-61
lines changed

forward_engineering/api.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,14 @@ const addCommentsSigns = (string, format) => {
107107
const commentsEnd = /hackoladeCommentEnd\d+/i;
108108
const innerCommentStart = /hackoladeInnerCommentStart/i;
109109
const innerCommentEnd = /hackoladeInnerCommentEnd/i;
110+
const innerCommentStartYamlArrayItem = /- hackoladeInnerCommentStart/i;
110111

111112
const { result } = string.split('\n').reduce(({ isCommented, result }, line, index, array) => {
112113
if (commentsStart.test(line) || innerCommentStart.test(line)) {
114+
if (innerCommentStartYamlArrayItem.test(line)) {
115+
const lineBeginsAt = array[index + 1].search(/\S/);
116+
array[index + 1] = array[index + 1].slice(0, lineBeginsAt) + '- ' + array[index + 1].slice(lineBeginsAt);
117+
}
113118
return { isCommented: true, result: result };
114119
}
115120
if (commentsEnd.test(line)) {
@@ -123,7 +128,7 @@ const addCommentsSigns = (string, format) => {
123128
}
124129

125130
const isNextLineInnerCommentStart = index + 1 < array.length && innerCommentStart.test(array[index + 1]);
126-
if (isCommented || isNextLineInnerCommentStart) {
131+
if ((isCommented || isNextLineInnerCommentStart) && !innerCommentStartYamlArrayItem.test(array[index + 1])) {
127132
result = result + '# ' + line + '\n';
128133
} else {
129134
result = result + line + '\n';
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
const commentFlags = {
2+
inner: {
3+
start: 'hackoladeInnerCommentStart',
4+
end: 'hackoladeInnerCommentEnd'
5+
},
6+
outer: {
7+
start: 'hackoladeCommentStart',
8+
end: 'hackoladeCommentEnd'
9+
}
10+
};
11+
12+
function commentDeactivatedItem(item, isActivated, isParentActivated, commentFlagNames) {
13+
if (!item || !isParentActivated) {
14+
return item;
15+
}
16+
17+
if (isActivated === false) {
18+
return {
19+
[commentFlagNames.start]: true,
20+
...item,
21+
[commentFlagNames.end]: true
22+
};
23+
}
24+
25+
return item;
26+
}
27+
28+
function commentDeactivatedItemInner(item, isActivated, isParentActivated) {
29+
return commentDeactivatedItem(item, isActivated, isParentActivated, commentFlags.inner);
30+
}
31+
32+
function commentDeactivatedItemOuter(item, isActivated, isParentActivated) {
33+
return commentDeactivatedItem(item, isActivated, isParentActivated, commentFlags.outer);
34+
}
35+
36+
module.exports = { commentFlags, commentDeactivatedItemInner, commentDeactivatedItemOuter };

forward_engineering/helpers/componentsHelpers/parametersHelper.js

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const getExtensions = require('../extensionsHelper');
33
const { mapSchema } = require('./schemasHelper');
44
const { getExamples } = require('./examplesHelper');
55
const { getRef, hasRef, hasChoice } = require('../typeHelper');
6+
const { commentDeactivatedItemInner } = require('../commentsHelper');
67

78
function getParameters(data) {
89
if (!data || !data.properties) {
@@ -20,14 +21,14 @@ function getParameters(data) {
2021
}, {});
2122
}
2223

23-
function mapParameter(data, required) {
24+
function mapParameter(data, required, isParentActivated = false) {
2425
if (!data) {
2526
return;
2627
}
2728
if (hasRef(data)) {
28-
return getRef(data);
29+
return commentDeactivatedItemInner(getRef(data), data.isActivated, isParentActivated);
2930
}
30-
31+
const isActivated = data.isActivated && isParentActivated;
3132
const parameter = {
3233
name: data.parameterName,
3334
in: getIn(data.type),
@@ -38,14 +39,14 @@ function mapParameter(data, required) {
3839
style: data.style,
3940
explode: data.explode,
4041
allowReserved: data.allowReserved,
41-
schema: mapSchema(get(data, 'properties.schema'), 'schema'),
42+
schema: mapSchema(get(data, 'properties.schema'), 'schema', isActivated),
4243
example: data.sample,
4344
examples: getExamples(get(data, 'properties.examples')),
44-
content: getContent(get(data, 'properties.content'))
45+
content: getContent(get(data, 'properties.content'), isActivated)
4546
};
4647
const extensions = getExtensions(data.scopesExtensions);
4748

48-
return Object.assign({}, parameter, extensions);
49+
return commentDeactivatedItemInner(Object.assign({}, parameter, extensions), data.isActivated, isParentActivated);
4950
}
5051

5152
function getIn(parameterType) {
@@ -59,37 +60,39 @@ function getIn(parameterType) {
5960
return parameterTypeToIn[parameterType];
6061
}
6162

62-
function getHeaders(data) {
63+
function getHeaders(data, isParentActivated = false) {
6364
if (!data || !data.properties) {
6465
return;
6566
}
6667

6768
return Object.entries(data.properties)
6869
.map(([key, value]) => {
70+
const isActivated = value.isActivated;
6971
return {
7072
key,
71-
value: mapHeader(value)
73+
value: mapHeader(value, isActivated && isParentActivated),
74+
isActivated
7275
};
7376
})
74-
.reduce((acc, { key, value }) => {
75-
acc[key] = value;
77+
.reduce((acc, { key, value, isActivated }) => {
78+
acc[key] = commentDeactivatedItemInner(value, isActivated, isParentActivated);
7679
return acc;
7780
}, {});
7881
}
7982

80-
function mapHeader(data) {
83+
function mapHeader(data, isParentActivated = false) {
8184
if (!data) {
8285
return;
8386
}
8487
if (hasRef(data)) {
85-
return getRef(data);
88+
return commentDeactivatedItemInner(getRef(data), data.isActivated, isParentActivated);
8689
}
8790

8891
delete data.parameterName;
89-
return mapParameter(data);
92+
return mapParameter(data, false, isParentActivated);
9093
}
9194

92-
function getContent(data) {
95+
function getContent(data, isParentActivated) {
9396
if (!data || !data.properties) {
9497
return;
9598
}
@@ -104,24 +107,32 @@ function getContent(data) {
104107
if (isSchemaEmpty && isExamplesEmpty) {
105108
return;
106109
}
107-
acc[key] = mapMediaTypeObject(data.properties[key]);
110+
const isActivated = data.properties[key].isActivated;
111+
acc[key] = commentDeactivatedItemInner(
112+
mapMediaTypeObject(
113+
data.properties[key],
114+
isActivated && isParentActivated
115+
),
116+
isActivated,
117+
isParentActivated
118+
);
108119
return acc;
109120
}, {});
110121
}
111122

112-
function mapMediaTypeObject(data) {
123+
function mapMediaTypeObject(data, isParentActivated = false) {
113124
if (!data || !data.properties) {
114125
return;
115126
}
116-
let schema = mapSchema(get(data, 'properties.schema'), 'schema');
127+
let schema = mapSchema(get(data, 'properties.schema'), 'schema', isParentActivated);
117128
if (!schema && hasChoice(data)) {
118129
schema = mapSchema({
119130
type: 'object',
120131
allOf: data.allOf,
121132
oneOf: data.oneOf,
122133
anyOf: data.anyOf,
123134
not: data.not
124-
}, 'schema');
135+
}, 'schema', isParentActivated);
125136
}
126137
const examples = getExamples(get(data, 'properties.examples'));
127138
const encoding = mapEncoding(get(data, 'properties.encoding'));

forward_engineering/helpers/componentsHelpers/requestBodiesHelper.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const get = require('lodash.get');
22
const { getContent } = require('./parametersHelper');
33
const getExtensions = require('../extensionsHelper');
44
const { getRef, hasRef } = require('../typeHelper');
5+
const { commentDeactivatedItemInner } = require('../commentsHelper');
56

67
function getRequestBodies(data) {
78
if (!data || !data.properties) {
@@ -21,15 +22,15 @@ function getRequestBodies(data) {
2122
}, {});
2223
}
2324

24-
function mapRequestBody(data, required) {
25+
function mapRequestBody(data, required, isParentActivated = false) {
2526
if (!data) {
2627
return;
2728
}
2829
if (hasRef(data)) {
29-
return getRef(data);
30+
return commentDeactivatedItemInner(getRef(data), data.isActivated, isParentActivated);
3031
}
3132

32-
const content = getContent(data);
33+
const content = getContent(data, data.isActivated && isParentActivated);
3334
if (!content) {
3435
return;
3536
}
@@ -41,7 +42,7 @@ function mapRequestBody(data, required) {
4142
}
4243
const extensions = getExtensions(data.scopesExtensions);
4344

44-
return Object.assign({}, requestBody, extensions);
45+
return commentDeactivatedItemInner(Object.assign({}, requestBody, extensions), data.isActivated, isParentActivated);
4546
}
4647

4748
module.exports = {

forward_engineering/helpers/componentsHelpers/responsesHelper.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ function mapResponse(data, responseCollectionDescription, shouldResponseBeCommen
3030
return getRef(data);
3131
}
3232
const description = data.description || responseCollectionDescription || '';
33-
const headers = getHeaders(get(data, `properties.headers`));
34-
const content = getContent(get(data, `properties.content`));
33+
const headers = getHeaders(get(data, `properties.headers`), !shouldResponseBeCommented);
34+
const content = getContent(get(data, `properties.content`), !shouldResponseBeCommented);
3535
const links = getLinks(get(data, `properties.links`));
3636
const extensions = getExtensions(data.scopesExtensions);
3737
const response = {};

forward_engineering/helpers/componentsHelpers/schemasHelper.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ function getSchemas(data) {
1111
}, {});
1212
}
1313

14-
function mapSchema(data, key) {
15-
return typeHelper.getType(data, key);
14+
function mapSchema(data, key, isParentActivated = false) {
15+
return typeHelper.getType(data, key, isParentActivated);
1616
}
1717

1818
module.exports = {

forward_engineering/helpers/pathHelper.js

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const { mapParameter } = require('./componentsHelpers/parametersHelper');
66
const { mapRequestBody } = require('./componentsHelpers/requestBodiesHelper');
77
const { mapResponse } = require('./componentsHelpers/responsesHelper');
88
const { hasRef, getRef } = require('./typeHelper');
9+
const { commentDeactivatedItemInner } = require('./commentsHelper');
910

1011
function getPaths(containers, containersIdsForCallbacks = []) {
1112
return containers
@@ -46,21 +47,38 @@ function getRequestData(collections, containers, containerId, containersPath = [
4647
return collections
4748
.filter(collection => collection.entityType === 'request')
4849
.map(data => {
50+
const isRequestActivated = data.isActivated && isPathActivated;
4951
const request = {
5052
tags: commonHelper.mapArrayFieldByName(data.tags, 'tag'),
5153
summary: data.summary,
5254
description: data.description,
5355
externalDocs: commonHelper.mapExternalDocs(data.externalDocs),
5456
operationId: data.operationId,
55-
parameters: mapRequestParameters(get(data, 'properties.parameters')),
56-
requestBody: mapRequestBody(get(data, 'properties.requestBody'), get(data, 'required', []).includes('requestBody')),
57-
responses: mapResponses(collections, data.GUID, isPathActivated && data.isActivated),
58-
callbacks: getCallbacks(get(data, 'properties.callbacks'), containers, containerId, containersPath),
57+
parameters: mapRequestParameters(
58+
get(data, 'properties.parameters'),
59+
isRequestActivated
60+
),
61+
requestBody: mapRequestBody(
62+
get(data, 'properties.requestBody'),
63+
get(data, 'required', []).includes('requestBody'),
64+
isRequestActivated
65+
),
66+
responses: mapResponses(
67+
collections,
68+
data.GUID,
69+
isRequestActivated
70+
),
71+
callbacks: getCallbacks(
72+
get(data, 'properties.callbacks'),
73+
containers,
74+
containerId,
75+
containersPath
76+
),
5977
deprecated: data.deprecated,
6078
security: commonHelper.mapSecurity(data.security),
6179
servers: getServers(data.servers),
6280
methodName: data.collectionName,
63-
isActivated: data.isActivated
81+
isActivated: data.isActivated,
6482
};
6583
const extensions = getExtensions(data.scopesExtensions);
6684

@@ -82,15 +100,14 @@ function getRequestData(collections, containers, containerId, containersPath = [
82100
}, {});
83101
}
84102

85-
function mapRequestParameters(parameters) {
103+
function mapRequestParameters(parameters, isParentActivated = false) {
86104
if (!parameters || !parameters.items) {
87105
return;
88106
}
89107
if (Array.isArray(parameters.items)) {
90-
return parameters.items.map(item => mapParameter(item));
108+
return parameters.items.map(item => mapParameter(item, false, isParentActivated));
91109
}
92-
93-
return [mapParameter(parameters.items)];
110+
return [mapParameter(parameters.items, false, isParentActivated)];
94111
}
95112

96113
function mapResponses(collections, collectionId, isParentActivated) {

0 commit comments

Comments
 (0)