@@ -46,6 +46,7 @@ module.exports = {
4646 extractRequestBody = config . extractRequestBody ,
4747 defaultResponseType = config . defaultResponseType ,
4848 unwrapResponseData = config . unwrapResponseData ,
49+ sortTypes = config . sortTypes ,
4950 singleHttpClient = config . singleHttpClient ,
5051 prettier : prettierOptions = getPrettierOptions ( ) ,
5152 hooks : rawHooks ,
@@ -81,6 +82,7 @@ module.exports = {
8182 cleanOutput,
8283 defaultResponseType,
8384 unwrapResponseData,
85+ sortTypes,
8486 singleHttpClient,
8587 constants,
8688 silent,
@@ -141,11 +143,41 @@ module.exports = {
141143 const hasFormDataRoutes = routes . some ( ( route ) => route . hasFormDataParams ) ;
142144
143145 const usageComponentSchemas = filterComponentsMap ( componentsMap , "schemas" ) ;
146+ const sortByProperty = ( o1 , o2 , propertyName ) => {
147+ if ( o1 [ propertyName ] > o2 [ propertyName ] ) {
148+ return 1 ;
149+ }
150+ if ( o1 [ propertyName ] < o2 [ propertyName ] ) {
151+ return - 1 ;
152+ }
153+ return 0 ;
154+ }
155+ const sortByTypeName = ( o1 , o2 ) => sortByProperty ( o1 , o2 , 'typeName' ) ;
156+
157+ const sortByName = ( o1 , o2 ) => sortByProperty ( o1 , o2 , 'name' ) ;
158+
159+ const sortSchemas = ( schemas ) => {
160+ if ( config . sortTypes ) {
161+ return schemas . sort ( sortByTypeName ) . map ( ( schema ) => {
162+ if ( schema . rawTypeData ?. properties ) {
163+ return {
164+ ...schema ,
165+ rawTypeData : {
166+ ...schema . rawTypeData ,
167+ '$parsed' : { ...schema . rawTypeData [ '$parsed' ] , content : schema . rawTypeData [ '$parsed' ] . content . sort ( sortByName ) }
168+ }
169+ }
170+ }
171+ return schema ;
172+ } ) ;
173+ }
174+ return schemas ;
175+ } ;
144176
145177 const rawConfiguration = {
146178 apiConfig : createApiConfig ( usageSchema ) ,
147179 config,
148- modelTypes : _ . map ( usageComponentSchemas , prepareModelType ) ,
180+ modelTypes : _ . map ( sortSchemas ( usageComponentSchemas ) , prepareModelType ) ,
149181 rawModelTypes : usageComponentSchemas ,
150182 hasFormDataRoutes,
151183 hasSecurityRoutes,
0 commit comments