Skip to content

Commit 4af465b

Browse files
feat: add rule DOK.11
Signed-off-by: Mirelle Falstad <extern.mirelle.falstad@digg.se>
1 parent b351630 commit 4af465b

File tree

6 files changed

+133
-1
lines changed

6 files changed

+133
-1
lines changed

GUIDELINES.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ Detta dokument specificerar reglerna som verktyget tillämpar.
3636
- [ID: DOK.07](#id-dok07)
3737
- [ID: DOK.08](#id-dok08)
3838
- [ID: DOK.09](#id-dok09)
39+
- [ID: DOK.11](#id-dok11)
3940
- [ID: DOK.15](#id-dok15)
4041
- [ID: DOK.17](#id-dok17)
4142
- [ID: DOK.19](#id-dok19)
@@ -88,7 +89,7 @@ Detta dokument specificerar reglerna som verktyget tillämpar.
8889

8990
## Område: Dokumentation
9091

91-
**Täckningsgrad: 33%**
92+
**Täckningsgrad: 46%**
9293

9394
### ID: DOK.01
9495

@@ -267,6 +268,30 @@ _Ett av objekten räcker för att uppfylla regeln, men "limit", "begränsning" e
267268

268269
---
269270

271+
### ID: DOK.11
272+
273+
**Krav:** Avsikten och beteendet hos API:et SKALL beskrivas så utförligt och tydligt som möjligt.
274+
275+
**Typ:** SKALL
276+
277+
**JSON Path Plus-uttryck:**
278+
279+
```
280+
$.info
281+
```
282+
283+
**Förklaring:**
284+
Regeln förutsätter att det finns en förekomst av fältet `description` under objektet `info`.
285+
Beskrivningen måste finnas och får endast vara en icke-tom textsträng som inte enbart består av blanksteg.
286+
287+
**Exempel:**
288+
289+
![Exempelbild på hur en korrekt description kan se ut](images/dok11.png)
290+
291+
_Exemplet ovan är giltigt då description finns, och innehåller en textsträng som inte enbart består av blanksteg._
292+
293+
---
294+
270295
### ID: DOK.15
271296

272297
**Krav:** I dokumentationen av API:et SKALL exempel på API:ets fråga (en:request) och svar (en:reply) finnas i sin helhet.

REUSE.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ path = [
3636
"images/dok7.png",
3737
"images/dok8.png",
3838
"images/dok9.png",
39+
"images/dok11.png",
3940
"images/dot1-2.png",
4041
"images/dot1.png",
4142
"images/dot4.png",

images/dok11.png

70.7 KB
Loading

rulesets/DokRules.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,51 @@ export class Dok09 extends BaseRuleset {
344344
}
345345
severity = DiagnosticSeverity.Error;
346346
}
347+
348+
export class Dok11 extends BaseRuleset {
349+
static customProperties: CustomProperties = {
350+
område: 'Dokumentation',
351+
id: 'DOK.11',
352+
};
353+
given = '$.info';
354+
message = 'Avsikten och beteendet hos API:et SKALL beskrivas så utförligt och tydligt som möjligt.';
355+
then = [
356+
{
357+
function: (targetVal: any, _opts: string, paths: string[]) => {
358+
const description = targetVal.description;
359+
if (!description || typeof description !== 'string' || description.trim() === '') {
360+
return [
361+
{
362+
message: this.message,
363+
severity: this.severity,
364+
paths: paths,
365+
},
366+
];
367+
}
368+
return [];
369+
},
370+
},
371+
{
372+
function: (targetVal: string, _opts: string, paths: string[]) => {
373+
this.trackRuleExecutionHandler(
374+
JSON.stringify(targetVal, null, 2),
375+
_opts,
376+
paths,
377+
this.severity,
378+
this.constructor.name,
379+
moduleName,
380+
Dok11.customProperties,
381+
);
382+
},
383+
},
384+
];
385+
constructor() {
386+
super();
387+
super.initializeFormats(['OAS2', 'OAS3']);
388+
}
389+
severity = DiagnosticSeverity.Error;
390+
}
391+
347392
export class Dok19 extends BaseRuleset {
348393
static customProperties: CustomProperties = {
349394
område: 'Dokumentation',

tests/dok.test.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,66 @@ testRule('Dok09', [
371371
],
372372
},
373373
]);
374+
375+
testRule('Dok11', [
376+
{
377+
name: 'giltigt testfall',
378+
document: {
379+
openapi: '3.1.0',
380+
info: {
381+
version: '1.0',
382+
description: 'When the documentation consists of multiple paragraphs, the greater-than operator can be used.',
383+
},
384+
},
385+
errors: [],
386+
},
387+
{
388+
name: 'ogiltigt testfall - description saknas',
389+
document: {
390+
openapi: '3.1.0',
391+
info: { version: '1.0' },
392+
},
393+
errors: [
394+
{
395+
message: 'Avsikten och beteendet hos API:et SKALL beskrivas så utförligt och tydligt som möjligt.',
396+
severity: DiagnosticSeverity.Error,
397+
},
398+
],
399+
},
400+
{
401+
name: 'ogiltigt testfall - description finns, men innehåller endast blanksteg',
402+
document: {
403+
openapi: '3.1.0',
404+
info: {
405+
version: '1.0',
406+
description: ' ',
407+
},
408+
},
409+
errors: [
410+
{
411+
message: 'Avsikten och beteendet hos API:et SKALL beskrivas så utförligt och tydligt som möjligt.',
412+
severity: DiagnosticSeverity.Error,
413+
},
414+
],
415+
},
416+
{
417+
name: 'ogiltigt testfall - description finns, men är tom',
418+
document: {
419+
openapi: '3.1.0',
420+
info: {
421+
version: '1.0',
422+
description: '',
423+
},
424+
},
425+
errors: [
426+
{
427+
message: 'Avsikten och beteendet hos API:et SKALL beskrivas så utförligt och tydligt som möjligt.',
428+
severity: DiagnosticSeverity.Error,
429+
},
430+
],
431+
},
432+
]);
433+
374434
testRule('Dok17', [
375435
{
376436
name: 'giltigt testfall',

tests/util/rulesetTest.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ const ruleTypes = [
7272
DotRules.Dot04,
7373
DokRules.Dok19,
7474
DokRules.Dok01,
75+
DokRules.Dok11,
7576
DokRules.Dok17,
7677
DokRules.Dok03Info,
7778
DokRules.Dok03ContactName,

0 commit comments

Comments
 (0)