@@ -46,6 +46,7 @@ module.exports = {
46
46
extractRequestBody = config . extractRequestBody ,
47
47
defaultResponseType = config . defaultResponseType ,
48
48
unwrapResponseData = config . unwrapResponseData ,
49
+ sortTypes = config . sortTypes ,
49
50
singleHttpClient = config . singleHttpClient ,
50
51
prettier : prettierOptions = getPrettierOptions ( ) ,
51
52
hooks : rawHooks ,
@@ -81,6 +82,7 @@ module.exports = {
81
82
cleanOutput,
82
83
defaultResponseType,
83
84
unwrapResponseData,
85
+ sortTypes,
84
86
singleHttpClient,
85
87
constants,
86
88
silent,
@@ -141,11 +143,41 @@ module.exports = {
141
143
const hasFormDataRoutes = routes . some ( ( route ) => route . hasFormDataParams ) ;
142
144
143
145
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
+ } ;
144
176
145
177
const rawConfiguration = {
146
178
apiConfig : createApiConfig ( usageSchema ) ,
147
179
config,
148
- modelTypes : _ . map ( usageComponentSchemas , prepareModelType ) ,
180
+ modelTypes : _ . map ( sortSchemas ( usageComponentSchemas ) , prepareModelType ) ,
149
181
rawModelTypes : usageComponentSchemas ,
150
182
hasFormDataRoutes,
151
183
hasSecurityRoutes,
0 commit comments