Skip to content

Commit 143e149

Browse files
committed
feat: extend rule dok.19 to also check summary in path operations
Signed-off-by: Mirelle Falstad <extern.mirelle.falstad@digg.se>
1 parent 7991039 commit 143e149

File tree

4 files changed

+21
-6
lines changed

4 files changed

+21
-6
lines changed

GUIDELINES.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,15 @@ Detta dokument specificerar reglerna som verktyget tillämpar.
104104

105105
```
106106
$
107-
```
107+
```> npx jest tests/dok.test.ts
108+
No tests found, exiting with code 1
109+
Run with `--passWithNoTests` to exit with code 0
110+
In /home/mirellefalstad/workspaces/rap-lp/rest-api-profil-lint-processor
111+
112 files checked.
112+
testMatch: **/tests/unit/**/*.test.ts - 13 matches
113+
testPathIgnorePatterns: /node_modules/ - 112 matches
114+
testRegex: - 0 matches
115+
Pattern: tests/dok.test.ts - 0 matches
108116
109117
**Förklaring:**
110118
@@ -370,13 +378,13 @@ $.paths[*][*]
370378
```
371379
372380
**Förklaring:**
373-
Regeln förutsätter att det finns en förekomst av objektet `Paths`. Regeln undersöker vidare om det finns förekomster av fältet `description` oavsett om det är en GET, POST, PUT, PATCH eller en DELETE operation.
381+
Regeln förutsätter att objektet `paths` förekommer. Den kontrollerar att fälten `description` och `summary` finns för varje GET-, POST-, PUT-, PATCH- eller DELETE-operation.
374382
375383
**Exempel:**
376384
377-
![alt text](images/dok19.png)
385+
![Exempel på en OpenAPI-specifikation där varje operation under olika endpoints (GET, POST, PUT, DELETE) har markerats med röd ram kring fälten summary och description. Bilden illustrerar vilka delar av API-specifikationen som regeln DOK.19 validerar.](images/dok19.png)
378386
379-
I exemplet ovan, så exemplifieras regeln med en två get samt en post operation, där regeln undersöker om det finns en förekomst av fältet description.
387+
_I exemplet ovan illustreras regeln med flera operationer, där DOK.19 kontrollerar att fälten description och summary är ifyllda._
380388
381389
---
382390

images/dok19.png

8.21 KB
Loading

src/rulesets/DokRules.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,11 @@ export class Dok19 extends BaseRuleset {
398398
message =
399399
'Ett API:s resurser och de möjliga operationer som kan utföras på resursen SKALL beskrivas så utförligt och tydligt som möjligt';
400400
then = [
401-
{
401+
{
402+
field: 'summary',
403+
function: truthy,
404+
},
405+
{
402406
field: 'description',
403407
function: truthy,
404408
},
@@ -422,6 +426,7 @@ export class Dok19 extends BaseRuleset {
422426
}
423427
severity = DiagnosticSeverity.Error;
424428
}
429+
425430
export class Dok01 extends BaseRuleset {
426431
static customProperties: CustomProperties = {
427432
område: 'Dokumentation',

tests/unit/dok.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,7 @@ testRule('Dok17', [
455455
],
456456
},
457457
]);
458+
458459
testRule('Dok19', [
459460
{
460461
name: 'giltigt testfall',
@@ -466,6 +467,7 @@ testRule('Dok19', [
466467
'/thiscase': {
467468
operation: {
468469
description: 'description field test',
470+
summary: 'summary field test',
469471
responses: {
470472
'200': {
471473
description: 'test',
@@ -487,7 +489,7 @@ testRule('Dok19', [
487489
'/thiscase': {
488490
operation: {
489491
//description: "dfadfa",
490-
//summery: "",
492+
//summary: "",
491493
responses: {
492494
'200': {
493495
description: '',

0 commit comments

Comments
 (0)