@@ -56,4 +56,61 @@ export class Mog01 extends BaseRuleset {
5656 }
5757}
5858
59- export default { Mog01 } ;
59+ export class Mog02 extends BaseRuleset {
60+ static customProperties : CustomProperties = {
61+ område : 'Mognad' ,
62+ id : 'MOG.02' ,
63+ } ;
64+ message = 'Alla API:er BÖR samtidigt designas för att uppnå nivå 3 enligt Richardson Maturity Model. ' ;
65+ given = '$.paths' ;
66+ then = [
67+ {
68+ function : ( targetVal : any , _opts : string , paths : string [ ] ) => {
69+ const countEndpoints = ( apiPaths : Record < string , any > ) : number => {
70+ return Object . keys ( apiPaths ) . length ;
71+ } ;
72+
73+ const endPointsAreValid = ( apiPaths : Record < string , any > ) : boolean => {
74+ const validHttpMethods = [ 'get' , 'post' , 'put' , 'delete' , 'patch' ] ;
75+ return Object . values ( apiPaths ) . every ( ( methodsObj ) => {
76+ const methodKeys = Object . keys ( methodsObj ) . map ( ( method ) => method . toLowerCase ( ) ) ;
77+ const hasAtLeastTwoMethods = methodKeys . length >= 2 ;
78+ const hasValidHttpMethod = methodKeys . some ( ( method ) => validHttpMethods . includes ( method ) ) ;
79+ return hasAtLeastTwoMethods && hasValidHttpMethod ;
80+ } ) ;
81+ } ;
82+
83+ if ( countEndpoints ( targetVal ) < 2 || ! endPointsAreValid ( targetVal ) ) {
84+ return [
85+ {
86+ message : this . message ,
87+ severity : this . severity ,
88+ paths : paths ,
89+ } ,
90+ ] ;
91+ }
92+ return [ ] ;
93+ } ,
94+ } ,
95+ {
96+ function : ( targetVal : string , _opts : string , paths : string [ ] ) => {
97+ this . trackRuleExecutionHandler (
98+ JSON . stringify ( targetVal , null , 2 ) ,
99+ _opts ,
100+ paths ,
101+ this . severity ,
102+ this . constructor . name ,
103+ moduleName ,
104+ Mog02 . customProperties ,
105+ ) ;
106+ } ,
107+ } ,
108+ ] ;
109+ severity = DiagnosticSeverity . Warning ;
110+ constructor ( ) {
111+ super ( ) ;
112+ super . initializeFormats ( [ 'OAS3' ] ) ;
113+ }
114+ }
115+
116+ export default { Mog01, Mog02 } ;
0 commit comments