Skip to content

Commit 02c730c

Browse files
committed
refactor: move helper methods to utility file
Signed-off-by: Mats Johansson <extern.mats.johansson@digg.se>
1 parent 4cabf48 commit 02c730c

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

src/rulesets/MogRules.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import { DiagnosticSeverity } from '@stoplight/types';
66
import { CustomProperties } from '../ruleinterface/CustomProperties.js';
77
import { BaseRuleset } from './BaseRuleset.js';
8+
import { countEndpoints, endPointsAreValid } from './util/MogRulesUtil.js';
89

910
const moduleName: string = 'MogRules.ts';
1011

@@ -66,20 +67,6 @@ export class Mog02 extends BaseRuleset {
6667
then = [
6768
{
6869
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-
8370
if (countEndpoints(targetVal) < 2 || !endPointsAreValid(targetVal)) {
8471
return [
8572
{

src/rulesets/util/MogRulesUtil.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// SPDX-FileCopyrightText: 2025 diggsweden/rest-api-profil-lint-processor
2+
//
3+
// SPDX-License-Identifier: EUPL-1.2
4+
5+
export const countEndpoints = (apiPaths: Record<string, any>): number => {
6+
return Object.keys(apiPaths).length;
7+
};
8+
9+
export const endPointsAreValid = (apiPaths: Record<string, any>): boolean => {
10+
const validHttpMethods = ['get', 'post', 'put', 'delete', 'patch'];
11+
return Object.values(apiPaths).every((methodsObj) => {
12+
const methodKeys = Object.keys(methodsObj).map((method) => method.toLowerCase());
13+
const hasAtLeastTwoMethods = methodKeys.length >= 2;
14+
const hasValidHttpMethod = methodKeys.some((method) => validHttpMethods.includes(method));
15+
return hasAtLeastTwoMethods && hasValidHttpMethod;
16+
});
17+
};

0 commit comments

Comments
 (0)