33class DocumentationParts {
44 constructor ( openAPI ) {
55 this . openAPI = openAPI ;
6+ this . newModelNames = { } ;
7+ this . oldModelNames = { } ;
68 }
79
810 parse ( ) {
911 let parts = [ ] ;
1012 const apiPart = this . __createAPIPart ( ) ;
1113 parts . push ( apiPart ) ;
1214
15+ const modelParts = this . __manipulateModels ( ) ;
16+ parts = parts . concat ( modelParts ) ;
17+
1318 const resourceParts = this . __createPathParts ( ) ;
1419 parts = parts . concat ( resourceParts ) ;
15- // parts = [...resourceParts, ...apiPart];
20+
1621 return parts ;
1722 }
1823
@@ -23,7 +28,7 @@ class DocumentationParts {
2328 type : "API" ,
2429 } ,
2530 properties : {
26- ... info ,
31+ info,
2732 } ,
2833 } ;
2934 return part ;
@@ -66,8 +71,13 @@ class DocumentationParts {
6671 for ( const method of Object . keys ( this . pathValue ) ) {
6772 const description = this . pathValue [ method ] ?. description ;
6873 const summary = this . pathValue [ method ] ?. summary ;
74+
6975 parts . push ( {
70- location : { type : "METHOD" , path : this . pathName , method : method } ,
76+ location : {
77+ type : "METHOD" ,
78+ path : this . pathName ,
79+ method : method ,
80+ } ,
7181 properties : {
7282 ...( description && { description : description } ) ,
7383 ...( summary && { summary : summary } ) ,
@@ -160,6 +170,44 @@ class DocumentationParts {
160170
161171 return parts ;
162172 }
173+
174+ __manipulateModels ( ) {
175+ const parts = [ ] ;
176+ if ( this . openAPI ?. components ?. schemas ) {
177+ for ( const [ key , model ] of Object . entries (
178+ this . openAPI . components . schemas
179+ ) ) {
180+ const newKey = key . replace ( / [ \W _ ] + / g, "" ) ;
181+ Object . assign ( this . oldModelNames , { [ key ] : newKey } ) ;
182+ Object . assign ( this . newModelNames , { [ newKey ] : key } ) ;
183+
184+ Object . assign ( this . openAPI . components . schemas , {
185+ [ newKey ] : this . openAPI . components . schemas [ key ] ,
186+ } ) ;
187+
188+ if ( newKey !== key ) delete this . openAPI . components . schemas [ key ] ;
189+
190+ const part = this . __createMODELPart ( model , newKey ) ;
191+
192+ parts . push ( part ) ;
193+ }
194+ }
195+
196+ return parts ;
197+ }
198+
199+ __createMODELPart ( model , key ) {
200+ const part = {
201+ location : {
202+ type : "MODEL" ,
203+ name : key ,
204+ } ,
205+ properties : {
206+ schema : model ,
207+ } ,
208+ } ;
209+ return part ;
210+ }
163211}
164212
165213module . exports = DocumentationParts ;
0 commit comments