@@ -3,7 +3,7 @@ const commonHelper = require('./commonHelper');
33const getExtensions = require ( './extensionsHelper' ) ;
44const { getServers } = require ( './serversHelper' ) ;
55const { mapParameter } = require ( './componentsHelpers/parametersHelper' ) ;
6- const { mapRequestBody } = require ( './componentsHelpers/requestBodiesHelper' ) ;
6+ const { mapRequestBody, getIsRequestBodySupported } = require ( './componentsHelpers/requestBodiesHelper' ) ;
77const { mapResponse } = require ( './componentsHelpers/responsesHelper' ) ;
88const { hasRef, getRef } = require ( './typeHelper' ) ;
99const { getArrayItems } = require ( './sharedHelper' ) ;
@@ -13,16 +13,22 @@ function getPaths(containers, containersIdsForCallbacks = [], specVersion) {
1313 . filter ( ( { id } ) => ! containersIdsForCallbacks . includes ( id ) )
1414 . reduce ( ( acc , container , index ) => {
1515 const { name, isActivated } = container . containerData [ 0 ] ;
16- const containerData = getRequestsForContainer ( { container, containers, containersPath : [ ] , isPathActivated : isActivated , specVersion } ) ;
16+ const containerData = getRequestsForContainer ( {
17+ container,
18+ containers,
19+ containersPath : [ ] ,
20+ isPathActivated : isActivated ,
21+ specVersion,
22+ } ) ;
1723
1824 if ( ! isActivated ) {
19- acc [ `hackoladeCommentStart${ index } ` ] = true ;
25+ acc [ `hackoladeCommentStart${ index } ` ] = true ;
2026 }
2127
2228 acc [ name ] = containerData ;
2329
2430 if ( ! isActivated ) {
25- acc [ `hackoladeCommentEnd${ index } ` ] = true ;
31+ acc [ `hackoladeCommentEnd${ index } ` ] = true ;
2632 }
2733 return acc ;
2834 } , { } ) ;
@@ -32,24 +38,41 @@ function getRequestsForContainer({ container, containers, containersPath = [], i
3238 const { contactExtensions, summary, description } = container . containerData [ 0 ] ;
3339
3440 const collections = container . entities . map ( collectionId => JSON . parse ( container . jsonSchema [ collectionId ] ) ) ;
35- const containerData = getRequestData ( { collections, containers, containerId : container . id , containersPath, isPathActivated, specVersion } ) ;
41+ const containerData = getRequestData ( {
42+ collections,
43+ containers,
44+ containerId : container . id ,
45+ containersPath,
46+ isPathActivated,
47+ specVersion,
48+ } ) ;
3649 const additionalContainerData = {
3750 summary,
38- description : description || undefined
51+ description : description || undefined ,
3952 } ;
4053
4154 const containerExtensions = getExtensions ( contactExtensions ) ;
4255
4356 return Object . assign ( { } , containerData , additionalContainerData , containerExtensions ) ;
4457}
4558
46- function getRequestData ( { collections, containers, containerId, containersPath = [ ] , isPathActivated = true , specVersion } ) {
59+ function getRequestData ( {
60+ collections,
61+ containers,
62+ containerId,
63+ containersPath = [ ] ,
64+ isPathActivated = true ,
65+ specVersion,
66+ } ) {
4767 return collections
4868 . filter ( collection => collection . entityType === 'request' )
4969 . map ( data => {
5070 const isRequestActivated = data . isActivated && isPathActivated ;
5171 const requestBodyPropKeyword = getRequestBodyPropKeyword ( data . properties ) ;
52- let request = {
72+ const isRequestBodySupported = getIsRequestBodySupported ( { collectionName : data . collectionName , specVersion } ) ;
73+ const extensions = getExtensions ( data . scopesExtensions ) ;
74+
75+ const request = {
5376 tags : commonHelper . mapArrayFieldByName ( data . tags , 'tag' ) ,
5477 summary : data . summary ,
5578 description : data . description ,
@@ -58,34 +81,28 @@ function getRequestData({ collections, containers, containerId, containersPath =
5881 parameters : mapRequestParameters ( {
5982 parameters : get ( data , 'properties.parameters' ) ,
6083 isParentActivated : isRequestActivated ,
61- specVersion
62- } )
63- } ;
64- const extensions = getExtensions ( data . scopesExtensions ) ;
65-
66- if ( ! [ 'get' , 'delete' ] . includes ( String ( data . collectionName ) . toLowerCase ( ) ) ) {
67- request . requestBody = mapRequestBody ( {
68- data : get ( data . properties , requestBodyPropKeyword ) ,
69- required : get ( data , 'required' , [ ] ) . includes ( requestBodyPropKeyword ) ,
70- isParentActivated : isRequestActivated ,
71- specVersion
72- } ) ;
73- }
74-
75- request = {
76- ...request ,
84+ specVersion,
85+ } ) ,
86+ requestBody : isRequestBodySupported
87+ ? mapRequestBody ( {
88+ data : get ( data . properties , requestBodyPropKeyword ) ,
89+ required : get ( data , 'required' , [ ] ) . includes ( requestBodyPropKeyword ) ,
90+ isParentActivated : isRequestActivated ,
91+ specVersion,
92+ } )
93+ : undefined ,
7794 responses : mapResponses ( {
7895 collections,
7996 collectionId : data . GUID ,
8097 isRequestActivated,
81- specVersion
98+ specVersion,
8299 } ) ,
83100 callbacks : getCallbacks ( {
84101 data : get ( data , 'properties.callbacks' ) ,
85102 containers,
86103 containerId,
87104 containersPath,
88- specVersion
105+ specVersion,
89106 } ) ,
90107 deprecated : data . deprecated ,
91108 security : commonHelper . mapSecurity ( data . security ) ,
@@ -94,19 +111,19 @@ function getRequestData({ collections, containers, containerId, containersPath =
94111 isActivated : data . isActivated ,
95112 } ;
96113
97- return Object . assign ( { } , request , extensions ) ;
114+ return { ... request , ... extensions } ;
98115 } )
99116 . reduce ( ( acc , collection , index ) => {
100117 const { methodName, isActivated } = collection ;
101118 delete collection . methodName ;
102119 delete collection . isActivated ;
103120 const shouldCommentedFlagBeInserted = ! isActivated && isPathActivated ;
104121 if ( shouldCommentedFlagBeInserted ) {
105- acc [ `hackoladeCommentStart${ index } ` ] = true ;
122+ acc [ `hackoladeCommentStart${ index } ` ] = true ;
106123 }
107124 acc [ methodName ] = collection ;
108125 if ( shouldCommentedFlagBeInserted ) {
109- acc [ `hackoladeCommentEnd${ index } ` ] = true ;
126+ acc [ `hackoladeCommentEnd${ index } ` ] = true ;
110127 }
111128 return acc ;
112129 } , { } ) ;
@@ -120,7 +137,7 @@ function mapRequestParameters({ parameters, isParentActivated = false, specVersi
120137 if ( ! Array . isArray ( parametersData ) ) {
121138 parametersData = [ parametersData ] ;
122139 }
123-
140+
124141 return parametersData . map ( item => mapParameter ( { data : item , required : false , isParentActivated, specVersion } ) ) ;
125142}
126143
@@ -135,15 +152,20 @@ function mapResponses({ collections, collectionId, isParentActivated, specVersio
135152 const responseCode = collection . collectionName ;
136153 const shouldResponseBeCommented = ! collection . isActivated && isParentActivated ;
137154 const extensions = getExtensions ( collection . scopesExtensions ) ;
138- const response = mapResponse ( { data : get ( collection , [ 'properties' , Object . keys ( collection . properties ) [ 0 ] ] ) , responseCollectionDescription : collection . description , shouldResponseBeCommented, specVersion } ) ;
155+ const response = mapResponse ( {
156+ data : get ( collection , [ 'properties' , Object . keys ( collection . properties ) [ 0 ] ] ) ,
157+ responseCollectionDescription : collection . description ,
158+ shouldResponseBeCommented,
159+ specVersion,
160+ } ) ;
139161
140162 return { responseCode, response : { ...response , ...extensions } } ;
141163 } )
142164 . reduce ( ( acc , { responseCode, response } ) => {
143165 acc [ responseCode ] = response ;
144166 return acc ;
145167 } , { } ) ;
146-
168+
147169 return responses ;
148170}
149171
@@ -158,7 +180,7 @@ function getCallbacks({ data, containers, containerId, containersPath = [], spec
158180 return ;
159181 }
160182 if ( hasRef ( value ) ) {
161- return { [ key ] : { [ value . callbackExpression ] : getRef ( value , specVersion ) } } ;
183+ return { [ key ] : { [ value . callbackExpression ] : getRef ( value , specVersion ) } } ;
162184 }
163185 const containerForCallback = containers . find ( ( { id } ) => id === value . bucketId && id !== containerId ) ;
164186 if ( ! containerForCallback ) {
@@ -168,12 +190,11 @@ function getCallbacks({ data, containers, containerId, containersPath = [], spec
168190 container : containerForCallback ,
169191 containers,
170192 containersPath : [ ...containersPath , containerId ] ,
171- specVersion
193+ specVersion,
172194 } ) ;
173195 const extensions = getExtensions ( value . scopesExtensions ) ;
174196
175- return { [ key ] : { [ value . callbackExpression ] : callbackData , ...extensions } } ;
176-
197+ return { [ key ] : { [ value . callbackExpression ] : callbackData , ...extensions } } ;
177198 } )
178199 . reduce ( ( acc , item ) => {
179200 acc = Object . assign ( { } , acc , item ) ;
@@ -182,18 +203,18 @@ function getCallbacks({ data, containers, containerId, containersPath = [], spec
182203}
183204
184205function getRequestBodyPropKeyword ( properties = { } ) {
185- const defaultKeyword = 'requestBody' ;
206+ const defaultKeyword = 'requestBody' ;
186207 const restRequestPropNames = [ 'parameters' , 'callbacks' ] ;
187208
188209 if ( get ( properties , defaultKeyword ) ) {
189210 return defaultKeyword ;
190211 }
191212
192213 const requestBodyKey = Object . keys ( properties ) . find ( key => ! restRequestPropNames . includes ( key ) ) ;
193- return requestBodyKey
214+ return requestBodyKey ;
194215}
195216
196217module . exports = {
197218 getPaths,
198- getCallbacks
199- } ;
219+ getCallbacks,
220+ } ;
0 commit comments