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