@@ -10,20 +10,28 @@ const { hasRef, getRef } = require('./typeHelper');
1010function getPaths ( containers , containersIdsForCallbacks = [ ] ) {
1111 return containers
1212 . filter ( ( { id } ) => ! containersIdsForCallbacks . includes ( id ) )
13- . reduce ( ( acc , container ) => {
14- const { name } = container . containerData [ 0 ] ;
15- const containerData = getRequestsForContainer ( container , containers ) ;
13+ . reduce ( ( acc , container , index ) => {
14+ const { name, isActivated } = container . containerData [ 0 ] ;
15+ const containerData = getRequestsForContainer ( container , containers , [ ] , isActivated ) ;
16+
17+ if ( ! isActivated ) {
18+ acc [ `hackoladeCommentStart${ index } ` ] = true ;
19+ }
1620
1721 acc [ name ] = containerData ;
22+
23+ if ( ! isActivated ) {
24+ acc [ `hackoladeCommentEnd${ index } ` ] = true ;
25+ }
1826 return acc ;
1927 } , { } ) ;
2028}
2129
22- function getRequestsForContainer ( container , containers , containersPath = [ ] ) {
30+ function getRequestsForContainer ( container , containers , containersPath = [ ] , isPathActivated = true ) {
2331 const { contactExtensions, summary, description } = container . containerData [ 0 ] ;
2432
2533 const collections = container . entities . map ( collectionId => JSON . parse ( container . jsonSchema [ collectionId ] ) ) ;
26- const containerData = getRequestData ( collections , containers , container . id , containersPath ) ;
34+ const containerData = getRequestData ( collections , containers , container . id , containersPath , isPathActivated ) ;
2735 const additionalContainerData = {
2836 summary,
2937 description : description || undefined
@@ -34,7 +42,7 @@ function getRequestsForContainer(container, containers, containersPath = []) {
3442 return Object . assign ( { } , containerData , additionalContainerData , containerExtensions ) ;
3543}
3644
37- function getRequestData ( collections , containers , containerId , containersPath = [ ] ) {
45+ function getRequestData ( collections , containers , containerId , containersPath = [ ] , isPathActivated = true ) {
3846 return collections
3947 . filter ( collection => collection . entityType === 'request' )
4048 . map ( data => {
@@ -46,21 +54,30 @@ function getRequestData(collections, containers, containerId, containersPath = [
4654 operationId : data . operationId ,
4755 parameters : mapRequestParameters ( get ( data , 'properties.parameters' ) ) ,
4856 requestBody : mapRequestBody ( get ( data , 'properties.requestBody' ) , get ( data , 'required' , [ ] ) . includes ( 'requestBody' ) ) ,
49- responses : mapResponses ( collections , data . GUID ) ,
57+ responses : mapResponses ( collections , data . GUID , isPathActivated && data . isActivated ) ,
5058 callbacks : getCallbacks ( get ( data , 'properties.callbacks' ) , containers , containerId , containersPath ) ,
5159 deprecated : data . deprecated ,
5260 security : commonHelper . mapSecurity ( data . security ) ,
5361 servers : getServers ( data . servers ) ,
54- methodName : data . collectionName
62+ methodName : data . collectionName ,
63+ isActivated : data . isActivated
5564 } ;
5665 const extensions = getExtensions ( data . operationExtensions ) ;
5766
5867 return Object . assign ( { } , request , extensions ) ;
5968 } )
60- . reduce ( ( acc , collection ) => {
61- const { methodName } = collection ;
69+ . reduce ( ( acc , collection , index ) => {
70+ const { methodName, isActivated } = collection ;
6271 delete collection . methodName ;
72+ delete collection . isActivated ;
73+ const shouldCommentedFlagBeInserted = ! isActivated && isPathActivated ;
74+ if ( shouldCommentedFlagBeInserted ) {
75+ acc [ `hackoladeCommentStart${ index } ` ] = true ;
76+ }
6377 acc [ methodName ] = collection ;
78+ if ( shouldCommentedFlagBeInserted ) {
79+ acc [ `hackoladeCommentEnd${ index } ` ] = true ;
80+ }
6481 return acc ;
6582 } , { } ) ;
6683}
@@ -76,7 +93,7 @@ function mapRequestParameters(parameters) {
7693 return [ mapParameter ( parameters . items ) ] ;
7794}
7895
79- function mapResponses ( collections , collectionId ) {
96+ function mapResponses ( collections , collectionId , isParentActivated ) {
8097 if ( ! collections || ! collectionId ) {
8198 return ;
8299 }
@@ -85,13 +102,13 @@ function mapResponses(collections, collectionId) {
85102 . filter ( collection => collection . entityType === 'response' && collection . parentCollection === collectionId )
86103 . map ( collection => {
87104 const responseCode = collection . collectionName ;
88- const response = mapResponse ( get ( collection , 'properties.response' ) , collection . description ) ;
105+ const shouldResponseBeCommented = ! collection . isActivated && isParentActivated ;
106+ const response = mapResponse ( get ( collection , 'properties.response' ) , collection . description , shouldResponseBeCommented ) ;
89107
90108 return { responseCode, response } ;
91109 } )
92110 . reduce ( ( acc , { responseCode, response } ) => {
93111 acc [ responseCode ] = response ;
94-
95112 return acc ;
96113 } , { } ) ;
97114
0 commit comments