File tree Expand file tree Collapse file tree 2 files changed +152
-6
lines changed
packages/openapi-generator Expand file tree Collapse file tree 2 files changed +152
-6
lines changed Original file line number Diff line number Diff line change @@ -431,11 +431,21 @@ export function convertRoutesToOpenAPI(
431
431
{ } as Record < string , OpenAPIV3 . SchemaObject | OpenAPIV3 . ReferenceObject > ,
432
432
) ;
433
433
434
+ const sortedPaths = Object . keys ( paths )
435
+ . sort ( ( a , b ) => a . localeCompare ( b ) )
436
+ . reduce (
437
+ ( acc , key ) => {
438
+ acc [ key ] = paths [ key ] ! ;
439
+ return acc ;
440
+ } ,
441
+ { } as Record < string , OpenAPIV3 . PathItemObject > ,
442
+ ) ;
443
+
434
444
return {
435
445
openapi : '3.0.3' ,
436
446
info,
437
447
...( servers . length > 0 ? { servers } : { } ) ,
438
- paths,
448
+ paths : sortedPaths ,
439
449
components : {
440
450
schemas : openapiSchemas ,
441
451
} ,
Original file line number Diff line number Diff line change @@ -552,8 +552,8 @@ export const route = h.httpRoute({
552
552
method: 'GET',
553
553
request: h.httpRequest({
554
554
query: {
555
- /**
556
- * This is a foo description.
555
+ /**
556
+ * This is a foo description.
557
557
* @example abc
558
558
* @pattern ^[a-z]+$
559
559
*/
@@ -642,8 +642,8 @@ export const route = h.httpRoute({
642
642
method: 'GET',
643
643
request: h.httpRequest({
644
644
query: {
645
- /**
646
- * This is a foo description.
645
+ /**
646
+ * This is a foo description.
647
647
* @example abc
648
648
* @pattern ^[a-z]+$
649
649
*/
@@ -714,4 +714,140 @@ testCase('route with array union of null and undefined', ROUTE_WITH_ARRAY_UNION_
714
714
components : {
715
715
schemas : { }
716
716
}
717
- } ) ;
717
+ } ) ;
718
+
719
+ const MULTIPLE_ROUTES = `
720
+ import * as t from 'io-ts';
721
+ import * as h from '@api-ts/io-ts-http';
722
+
723
+ // Purposefully out of order to test sorting
724
+ export const route1 = h.httpRoute({
725
+ path: '/foo',
726
+ method: 'GET',
727
+ request: h.httpRequest({
728
+ query: {
729
+ foo: t.string,
730
+ },
731
+ }),
732
+ response: {
733
+ 200: t.string
734
+ },
735
+ });
736
+
737
+ export const route2 = h.httpRoute({
738
+ path: '/bar',
739
+ method: 'GET',
740
+ request: h.httpRequest({
741
+ query: {
742
+ bar: t.string,
743
+ },
744
+ }),
745
+ response: {
746
+ 200: t.string
747
+ },
748
+ });
749
+
750
+ export const route3 = h.httpRoute({
751
+ path: '/baz',
752
+ method: 'GET',
753
+ request: h.httpRequest({
754
+ query: {
755
+ baz: t.string,
756
+ },
757
+ }),
758
+ response: {
759
+ 200: t.string
760
+ },
761
+ });
762
+ ` ;
763
+
764
+ testCase ( 'multiple routes' , MULTIPLE_ROUTES , {
765
+ openapi : '3.0.3' ,
766
+ info : {
767
+ title : 'Test' ,
768
+ version : '1.0.0' ,
769
+ } ,
770
+ paths : {
771
+ '/bar' : {
772
+ get : {
773
+ parameters : [
774
+ {
775
+ in : 'query' ,
776
+ name : 'bar' ,
777
+ required : true ,
778
+ schema : {
779
+ type : 'string' ,
780
+ } ,
781
+ } ,
782
+ ] ,
783
+ responses : {
784
+ 200 : {
785
+ description : 'OK' ,
786
+ content : {
787
+ 'application/json' : {
788
+ schema : {
789
+ type : 'string' ,
790
+ } ,
791
+ } ,
792
+ } ,
793
+ } ,
794
+ } ,
795
+ } ,
796
+ } ,
797
+ '/baz' : {
798
+ get : {
799
+ parameters : [
800
+ {
801
+ in : 'query' ,
802
+ name : 'baz' ,
803
+ required : true ,
804
+ schema : {
805
+ type : 'string' ,
806
+ } ,
807
+ } ,
808
+ ] ,
809
+ responses : {
810
+ 200 : {
811
+ description : 'OK' ,
812
+ content : {
813
+ 'application/json' : {
814
+ schema : {
815
+ type : 'string' ,
816
+ } ,
817
+ } ,
818
+ } ,
819
+ } ,
820
+ } ,
821
+ } ,
822
+ } ,
823
+ '/foo' : {
824
+ get : {
825
+ parameters : [
826
+ {
827
+ in : 'query' ,
828
+ name : 'foo' ,
829
+ required : true ,
830
+ schema : {
831
+ type : 'string' ,
832
+ } ,
833
+ } ,
834
+ ] ,
835
+ responses : {
836
+ 200 : {
837
+ description : 'OK' ,
838
+ content : {
839
+ 'application/json' : {
840
+ schema : {
841
+ type : 'string' ,
842
+ } ,
843
+ } ,
844
+ } ,
845
+ } ,
846
+ } ,
847
+ } ,
848
+ } ,
849
+ } ,
850
+ components : {
851
+ schemas : { } ,
852
+ } ,
853
+ } ) ;
You can’t perform that action at this time.
0 commit comments