Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,104 changes: 880 additions & 1,224 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/cli-mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,13 @@ export async function execCLI<T extends CliArgs>(argv: T) {
}
};
const formatLintingResult = (result: any) => {
return `allvarlighetsgrad: ${colorizeSeverity(result.allvarlighetsgrad)} \nid: ${result.id} \nkrav: ${
return `\nallvarlighetsgrad: ${colorizeSeverity(result.allvarlighetsgrad)} \nid: ${result.id} \nkrav: ${
result.krav
} \nområde: ${result.område} \nsökväg:[${result.sökväg}] \nomfattning:${JSON.stringify(
result.omfattning,
null,
2,
)} `;
)}\ndesignregel: ${result.helpUrl} `;
};
//Check specified option from yargs input

Expand Down
5 changes: 5 additions & 0 deletions src/model/SpecValidationRequestDto.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@

// SPDX-FileCopyrightText: 2025 Digg - Agency for Digital Government
//
// SPDX-License-Identifier: EUPL-1.2

export class SpecValidationRequestDto {
/** Base 64 encoded OpenAPI spec (YAML or JSON) */
spec!: string;
Expand Down
4 changes: 4 additions & 0 deletions src/model/ValidationResponse.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// SPDX-FileCopyrightText: 2025 Digg - Agency for Digital Government
//
// SPDX-License-Identifier: EUPL-1.2

import { ValidationResponseDto } from './ValidationResponseDto.js';
import { Issue } from '../util/Issue.js';

Expand Down
21 changes: 21 additions & 0 deletions src/rulesets/util/rules-doc.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// SPDX-FileCopyrightText: 2025 Digg - Agency for Digital Government
//
// SPDX-License-Identifier: EUPL-1.2

const RULES_DOC_REPO =
'https://github.com/diggsweden/rest-api-profil-lint-processor';


/**
* Constructs a helper Url together with correct Rule
* @param ruleId ( Rule identifier)
* @returns Normalized help url
*/
export function buildRuleHelpUrl(ruleId: string): string {
const ref = process.env.RULES_DOC_REF || 'main';
const normalizedId = ruleId
.toLowerCase()
.replace('.', '');

return `${RULES_DOC_REPO}/blob/${ref}/GUIDELINES.md#id-${normalizedId}`;
}
4 changes: 4 additions & 0 deletions src/util/Issue.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// SPDX-FileCopyrightText: 2025 Digg - Agency for Digital Government
//
// SPDX-License-Identifier: EUPL-1.2

/**
* Issue type to use from client to validate parsing
*/
Expand Down
6 changes: 5 additions & 1 deletion src/util/RapLPCustomSpectral.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { ISpectralDiagnostic } from '@stoplight/spectral-core';
import spectralCore from '@stoplight/spectral-core';
const { Spectral, Document } = spectralCore;
import { RapLPCustomSpectralDiagnostic } from './RapLPCustomSpectralDiagnostic.js';
import { buildRuleHelpUrl } from '../rulesets/util/rules-doc.config.js';

class RapLPCustomSpectral {
private spectral: SpectralCore.Spectral;
Expand Down Expand Up @@ -49,9 +50,12 @@ class RapLPCustomSpectral {
if (ruleClass && typeof ruleClass.getCustomProperties === 'function') {
// Check for existance
const customProperties = ruleClass.getCustomProperties;
const ruleId = ruleClass.customProperties.id;

const customResult: RapLPCustomSpectralDiagnostic = {
id: ruleClass.customProperties.id,
id: ruleId,
område: ruleClass.customProperties.område,
helpUrl: ruleId ? buildRuleHelpUrl(ruleId) : undefined,
...customProperties, // For more copy
...this.mapResultToCustom(result),
};
Expand Down
3 changes: 3 additions & 0 deletions src/util/RapLPCustomSpectralDiagnostic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ export interface RapLPCustomSpectralDiagnostic
allvarlighetsgrad?: string;
sökväg?: any;
omfattning?: any;

/**Helper Url for guidelines */
helpUrl?: string;
}


Expand Down
4 changes: 4 additions & 0 deletions tests/unit/api/endpointValidation.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// SPDX-FileCopyrightText: 2025 Digg - Agency for Digital Government
//
// SPDX-License-Identifier: EUPL-1.2

/**
* CONTRACT TESTS for /api/v1/validation/validatespec
* - NOTE:
Expand Down
47 changes: 47 additions & 0 deletions tests/unit/buildRuleHelpUrl.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// SPDX-FileCopyrightText: 2025 Digg - Agency for Digital Government
//
// SPDX-License-Identifier: EUPL-1.2

import { buildRuleHelpUrl } from '../../src/rulesets/util/rules-doc.config.js';

describe('buildRuleHelpUrl', () => {
const ORIGINAL_ENV = process.env;

beforeEach(() => {
process.env = { ...ORIGINAL_ENV };
});

afterAll(() => {
process.env = ORIGINAL_ENV;
});

it('bygger korrekt GitHub-länk för regel-ID med punkt (SAK.16)', () => {
process.env.RULES_DOC_REF = 'main';

const url = buildRuleHelpUrl('SAK.16');

expect(url).toBe(
'https://github.com/diggsweden/rest-api-profil-lint-processor/blob/main/GUIDELINES.md#id-sak16'
);
});

it('faller tillbaka till main om RULES_DOC_REF saknas', () => {
delete process.env.RULES_DOC_REF;

const url = buildRuleHelpUrl('FOR.02');

expect(url).toBe(
'https://github.com/diggsweden/rest-api-profil-lint-processor/blob/main/GUIDELINES.md#id-for02'
);
});

it('hanterar redan normaliserade ID:n korrekt', () => {
process.env.RULES_DOC_REF = 'feature/test';

const url = buildRuleHelpUrl('sak16');

expect(url).toBe(
'https://github.com/diggsweden/rest-api-profil-lint-processor/blob/feature/test/GUIDELINES.md#id-sak16'
);
});
});
1 change: 0 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"compilerOptions": {
"types": ["node"],
"module": "NodeNext",
"moduleResolution": "NodeNext",
"target": "ES2020",
Expand Down