@@ -42,73 +42,73 @@ private static void CompareOpenApiInfo(string version, IList<Model> openApiInfoM
4242 {
4343 File . WriteAllText ( errorPath , string . Empty ) ;
4444 }
45- if ( openApiPath != null )
45+ if ( openApiPath != null )
4646 {
47- //Go through list of openapi files
48- foreach ( var file in Directory . GetFiles ( openApiPath ) )
49- {
50- using ( var sr = new StreamReader ( file ) )
47+ //Go through list of openapi files
48+ foreach ( var file in Directory . GetFiles ( openApiPath ) )
5149 {
52- var fileName = Path . GetFileNameWithoutExtension ( file ) ;
53- var openApiDoc = new OpenApiStreamReader ( ) . Read ( sr . BaseStream , out var diagnostic ) ;
54- if ( diagnostic . Errors . Count > 0 )
55- {
56- throw new Exception ( $ "Error reading openapi file { file } ") ;
57- }
58- //Go through each path in the openapi file
59- foreach ( var path in openApiDoc . Paths )
50+ using ( var sr = new StreamReader ( file ) )
6051 {
61- var model = new Model ( ) ;
62- var pathInfo = new PathInfo ( ) ;
63- //Get the path key
64- var apiPath = path . Key ;
65- pathInfo . Path = apiPath ;
66- pathInfo . Module = fileName ;
67- model . PathInfo = pathInfo ;
68- //Go through each operation in the path
69- foreach ( var operation in path . Value . Operations )
52+ var fileName = Path . GetFileNameWithoutExtension ( file ) ;
53+ var openApiDoc = new OpenApiStreamReader ( ) . Read ( sr . BaseStream , out var diagnostic ) ;
54+ if ( diagnostic . Errors . Count > 0 )
7055 {
71- var methodInfo = new MethodInfo ( ) ;
72- //Get the operationId
73- var operationId = operation . Value . OperationId ;
74- methodInfo . OperationId = operationId ;
75- //Get the method
76- var method = operation . Key . ToString ( ) ;
77- methodInfo . Method = method ;
78- //Get the parameters
79- var parameters = new List < Parameters > ( ) ;
80- foreach ( var parameter in operation . Value . Parameters )
81- {
82- var param = new Parameters ( ) ;
83- param . Name = parameter . Name ;
84- param . Location = parameter . In . ToString ( ) ?? "NA" ;
85- parameters . Add ( param ) ;
86- }
87- methodInfo . Parameters = parameters ;
88- model . MethodInfo = methodInfo ;
89- var originalPathDetails = PathDetails ( openApiInfoMetadata , operationId , apiPath , method , fileName ) ;
90- if ( originalPathDetails == null || originalPathDetails . PathInfo == null )
91- {
92- newPathsAdded . Add ( $ "{ fileName } ,{ apiPath } ,{ method } ") ;
93- continue ;
94- }
95- if ( originalPathDetails . MethodInfo != null && originalPathDetails . MethodInfo . Parameters != null && originalPathDetails . MethodInfo . Parameters . Count > methodInfo . Parameters . Count )
56+ throw new Exception ( $ "Error reading openapi file { file } ") ;
57+ }
58+ //Go through each path in the openapi file
59+ foreach ( var path in openApiDoc . Paths )
60+ {
61+ var model = new Model ( ) ;
62+ var pathInfo = new PathInfo ( ) ;
63+ //Get the path key
64+ var apiPath = path . Key ;
65+ pathInfo . Path = apiPath ;
66+ pathInfo . Module = fileName ;
67+ model . PathInfo = pathInfo ;
68+ //Go through each operation in the path
69+ foreach ( var operation in path . Value . Operations )
9670 {
97- openApiErrors . Add ( $ "{ fileName } ,{ apiPath } , { method } ,Parameter Count: { methodInfo . Parameters . Count } , Parameter Count: { originalPathDetails . MethodInfo . Parameters . Count } ") ;
98- }
71+ var methodInfo = new MethodInfo ( ) ;
72+ //Get the operationId
73+ var operationId = operation . Value . OperationId ;
74+ methodInfo . OperationId = operationId ;
75+ //Get the method
76+ var method = operation . Key . ToString ( ) ;
77+ methodInfo . Method = method ;
78+ //Get the parameters
79+ var parameters = new List < Parameters > ( ) ;
80+ foreach ( var parameter in operation . Value . Parameters )
81+ {
82+ var param = new Parameters ( ) ;
83+ param . Name = parameter . Name ;
84+ param . Location = parameter . In . ToString ( ) ?? "NA" ;
85+ parameters . Add ( param ) ;
86+ }
87+ methodInfo . Parameters = parameters ;
88+ model . MethodInfo = methodInfo ;
89+ var originalPathDetails = PathDetails ( openApiInfoMetadata , operationId , apiPath , method , fileName ) ;
90+ if ( originalPathDetails == null || originalPathDetails . PathInfo == null )
91+ {
92+ newPathsAdded . Add ( $ "{ fileName } ,{ apiPath } ,{ method } ") ;
93+ continue ;
94+ }
95+ if ( originalPathDetails . MethodInfo != null && originalPathDetails . MethodInfo . Parameters != null && originalPathDetails . MethodInfo . Parameters . Count > methodInfo . Parameters . Count )
96+ {
97+ openApiErrors . Add ( $ "{ fileName } ,{ apiPath } , { method } ,Parameter Count: { methodInfo . Parameters . Count } , Parameter Count: { originalPathDetails . MethodInfo . Parameters . Count } ") ;
98+ }
9999
100- if ( originalPathDetails . MethodInfo != null && originalPathDetails . MethodInfo . OperationId != methodInfo . OperationId )
101- {
102- openApiErrors . Add ( $ "{ fileName } ,{ apiPath } , { method } ,OperationId changed from: { originalPathDetails . MethodInfo . OperationId } , OperationId changed to: { methodInfo . OperationId } ") ;
103- }
100+ if ( originalPathDetails . MethodInfo != null && originalPathDetails . MethodInfo . OperationId != methodInfo . OperationId )
101+ {
102+ openApiErrors . Add ( $ "{ fileName } ,{ apiPath } , { method } ,OperationId changed from: { originalPathDetails . MethodInfo . OperationId } , OperationId changed to: { methodInfo . OperationId } ") ;
103+ }
104104
105105
106+ }
107+ models . Add ( model ) ;
106108 }
107- models . Add ( model ) ;
108109 }
109110 }
110111 }
111- }
112112 //convert list to json and add it to file
113113 if ( newPathsAdded . Count > 1 )
114114 {
0 commit comments