Skip to content
Closed
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 changes: 1 addition & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2025 diggsweden/rest-api-profil-lint-processor
# SPDX-FileCopyrightText: 2025 Digg - Agency for Digital Government
#
# SPDX-License-Identifier: CC0-1.0

Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ Avstaemning_REST_API_profil_generated*.xlsx
megalinter-reports
tests/generated
openapitools.json
dist
dist
2 changes: 1 addition & 1 deletion .npmrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
@diggsweden:registry=https://npm.pkg.github.com

# must use for correct package-lock.json
registry=https://registry.npmjs.org/
registry=https://registry.npmjs.org/
2 changes: 2 additions & 0 deletions Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ COPY --from=build /app/package*.json ./
COPY --from=build /app/document ./document
COPY --from=build /app/README.md ./README.md
COPY --from=build /app/GUIDELINES.md ./GUIDELINES.md
COPY --from=build /app/openapi.yaml ./openapi.yaml
COPY --from=build /app/urlValidationConfig.cjs ./urlValidationConfig.cjs

RUN chown -R node:node /app
USER node
Expand Down
131 changes: 123 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,40 @@ npm start -- -f openapi.yaml

> Notera: Att alla kommandon lokalt körs med `npm start --`.

### Server

Verktyget kan även köras som en lokal HTTP-server genom att ange [API-läge](#api-application-programming-interface). I detta läge kan funktionaliteten anropas via HTTP i stället för CLI-flaggor.

Starta servern:

```bash
npm start -- -m api
```

Validera en fil via terminalen:

```bash
curl -X POST http://localhost:3000/api/v1/validation/validate \
-H "Content-Type: application/json" \
-d "{\"yaml\": \"$(base64 -w 0 openapi.yaml)\"}"
```

Det går också att validera via en url istället för en fil men då behöver API-läget startas med en extra flagga för att låsa upp möjligheten att nyttja endpointen:

```bash
npm start -- -m api --enableUrlValidation
```

Validera en fil från en url via terminalen:

```bash
curl -sS -X POST http://localhost:3000/api/v1/validation/url \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-d '{"url":"https://testurl.com/q/openapi"}' \
| jq
```

## Versioner

Main-branchen, feature-brancher, pre-release- och testversioner används med reservation för att de kan innehålla funktionalitet som inte är garanterad att den är testad på samma sätt som en stabil version.
Expand Down Expand Up @@ -163,14 +197,14 @@ Här beskrivs vilka användningsområden verktyget har med diverse flaggor som k

### Tillgängliga flaggor

| Flagga | Beskrivning | Typ | Standard | Obligatorisk |
| --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- | ------------------- | ------------ |
| `-f, --file` | Sökväg till OpenAPI-specifikation (YAML/JSON). | string | – | Ja |
| `-c, --categories` | Regelkategorier separerade med kommatecken. Tillgängliga: `UfnRules, SakRules, VerRules, FnsRules, ArqRules, DokRules, AmeRules, ForRules, DotRules, FelRules, MogRules`. | string | – | Nej |
| `-l, --logError` | Sökväg till fil för felloggning från RAP-LP. Om inte angiven skrivs loggen till stdout. | string | stdout (om ej satt) | Nej |
| `-a, --append` | Append—utökar loggen i befintlig felloggningsfil (om `--logError` används). | boolean | `false` | Nej |
| `-d, --logDiagnostic` | Sökväg till fil för diagnostiseringsinformation från RAP-LP i JSON-format. | string | – | Nej |
| `--dex` | Sökväg till fil för diagnostiseringsinformation från RAP-LP i Excel-format. | string | – | Nej |
| Flagga | Beskrivning | Typ | Standard | Obligatorisk |
| --------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- | ------------------- | ------------ |
| `-f, --file` | Sökväg till OpenAPI-specifikation (YAML/JSON). | string | – | Ja |
| `-c, --categories` | Regelkategorier separerade med kommatecken. Tillgängliga: `UfnRules, SakRules, VerRules, FnsRules, ArqRules, DokRules, AmeRules, ForRules, DotRules, FelRules`. | string | – | Nej |
| `-l, --logError` | Sökväg till fil för felloggning från RAP-LP. Om inte angiven skrivs loggen till stdout. | string | stdout (om ej satt) | Nej |
| `-a, --append` | Append—utökar loggen i befintlig felloggningsfil (om `--logError` används). | boolean | `false` | Nej |
| `-d, --logDiagnostic` | Sökväg till fil för diagnostiseringsinformation från RAP-LP i JSON-format. | string | – | Nej |
| `--dex` | Sökväg till fil för diagnostiseringsinformation från RAP-LP i Excel-format. | string | – | Nej |

> Notera: Att `raplp` i alla kommandon nedan ersätts med respektive miljös sätt att köra verktyget (npm, docker eller podman).

Expand Down Expand Up @@ -269,6 +303,87 @@ raplp --version
raplp --help
```

### API-läge

Verktyget kan även köras som en lokal HTTP-server, via API (Applikation Programming Interface). I detta läge kan funktionaliteten anropas via HTTP i stället för CLI-flaggor.

För att starta servern, kör:

```bash
npm start -- -m api
```

Validera mot en endpoint:

```bash
POST http://localhost:3000/api/v1/validation/validate
```

Request body - application/json`

```bash
{
"yaml": "<base64encoded file>",
"categories": [
"CATEGORY1",
"CATEGORY2"
]
}
```

Använd detta kommando för att validera en yaml-fil via terminalen, här kan du även validera mot specifika [kategorier](#tillgängliga-kategorier-med-regler):

```bash
curl -X POST http://localhost:3000/api/v1/validation/validate \
-H "Content-Type: application/json" \
-d "{\"yaml\": \"$(base64 -w 0 Path_to_the_YAML_file)\", \"categories\": [\"CATEGORY1\", \"CATEGORY2\"]}"
```

Exempel

```bash
curl -X POST http://localhost:3000/api/v1/validation/validate \
-H "Content-Type: application/json" \
-d "{\"yaml\": \"$(base64 -w 0 openapi.yaml)\", \"categories\": [\"DokRules\", \"UfnRules\"]}"
```

Det går också att validera via en url istället för en fil men då behöver API-läget startas med en extra flagga för att låsa upp möjligheten att nyttja endpointen:

```bash
npm start -- -m api --enableUrlValidation
```

Använd detta kommando för att validera en yaml-fil baserat på en url via terminalen, även här kan man skicka med kategorier för valideringen. Se tidigare kommando:

```bash
curl -sS -X POST http://localhost:3000/api/v1/validation/url \
-H "Content-Type: application/json" \
-d '{"url":"<URL_TO_YAML_FILE>"}' | jq
```

Exempel:

```bash
curl -sS -X POST http://localhost:3000/api/v1/validation/url \
-H "Content-Type: application/json" \
-d '{"url":"https://testurl.com/q/openapi.yaml"}' | jq
```

#### Ladda ned information om regelutfall som en Excel-fil via api-läge

För att spara information om regelutfall från diagnostiseringen till en avstämningsfil i Excel, använd resultatet från tidigare validering som "result" nedan:

```bash
curl -X POST http://localhost:5173/api/validation/generate-report \
-H "Content-Type: application/json" \
-o avstamningsfil.xlsx \
-d '{
"result": [],
"categories": []
}'

```

### Riktlinjer och förklaringar

Vill du veta mer om de specifika reglerna som verktyget tillämpar, se avsnittet [GUIDELINES](GUIDELINES.md) för detaljer.
Expand Down
2 changes: 1 addition & 1 deletion REUSE.toml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ SPDX-License-Identifier = "CC0-1.0"

# documents etc
[[annotations]]
path = ["document/Avstaemning_REST_API_profil_v_1_2_0_0.xlsx"]
path = ["document/Avstaemning_REST_API_profil_v_1_2_0_0.xlsx", "document/Avstaemning_REST_API_profil_v_1_1_0_0.xlsx", "openapi.yaml"]
precedence = "aggregate"
SPDX-FileCopyrightText = "2025 Digg - Agency for Digital Government"
SPDX-License-Identifier = "CC0-1.0"
35 changes: 17 additions & 18 deletions apis/for-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
#
# SPDX-License-Identifier: EUPL-1.2

openapi: "3.0.0"
openapi: '3.0.0'
info:
version: 1.2.0
title: RAP-LP
description: OpenAPI Specification example to handle Rules for the category []Hypermedia] in the Swedish REST API-profil https://dev.dataportal.se/rest-api-profil
license:
name: EUPL-1.2 license
name: EUPL-1.2 license
servers:
- url: http://petstore.swagger.io/v1
paths:
Expand All @@ -31,7 +31,7 @@ paths:
content:
'application/json':
schema:
$ref: '#/components/schemas/Pets'
$ref: '#/components/schemas/Pets'
responses:
'200':
description: A paged array of pets
Expand All @@ -41,15 +41,15 @@ paths:
schema:
type: string
content:
application/json:
application/json:
schema:
$ref: "#/components/schemas/Pets"
$ref: '#/components/schemas/Pets'
default:
description: unexpected error
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
$ref: '#/components/schemas/Error'
post:
summary: Create a pet
operationId: createPets
Expand All @@ -63,7 +63,7 @@ paths:
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
$ref: '#/components/schemas/Error'
/pets/{petId}:
get:
summary: Info for a specific pet
Expand All @@ -81,20 +81,19 @@ paths:
content:
'application/json':
schema:
$ref: '#/components/schemas/Pet'
$ref: '#/components/schemas/Pet'
responses:
'200':
description: Expected response to a valid request
content:
application/json:
schema:
$ref: "#/components/schemas/Pet"
$ref: '#/components/schemas/Pet'
default:
description: unexpected error
content:
application/json:mor e
schema:
$ref: "#/components/schemas/Error"
content: application/json:more
schema:
$ref: '#/components/schemas/Error'
/pets/petsagain/{petId}:
get:
summary: Info for a specific pet
Expand All @@ -112,20 +111,20 @@ paths:
content:
'application/json':
schema:
$ref: '#/components/schemas/Pet'
$ref: '#/components/schemas/Pet'
responses:
'200':
description: Expected response to a valid request
content:
application/json:
schema:
$ref: "#/components/schemas/Pet"
$ref: '#/components/schemas/Pet'
default:
description: unexpected error
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
$ref: '#/components/schemas/Error'
components:
schemas:
Pet:
Expand All @@ -145,7 +144,7 @@ components:
type: array
maxItems: 100
items:
$ref: "#/components/schemas/Pet"
$ref: '#/components/schemas/Pet'
Error:
type: object
required:
Expand All @@ -156,4 +155,4 @@ components:
type: integer
format: int32
message:
type: string
type: string
Loading