-
Notifications
You must be signed in to change notification settings - Fork 0
fix(ETU-76205): Better error messages for lint issues in x-entur-permissions #120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| module.exports = (targetVal, options, context) => { | ||
| if (typeof targetVal !== "object") { | ||
| return [{message: "\"x-entur-permissions\" must be an object."}] | ||
| } | ||
|
|
||
| const messages = [] | ||
| for (const prop of Object.getOwnPropertyNames(targetVal)) { | ||
| if (!["value", "description"].includes(prop)) { | ||
| messages.push({ message: `Unrecognized property \"${prop}\"`, path: [...context.path, prop] }) | ||
| } | ||
| } | ||
| if (targetVal.description != null && typeof targetVal.description !== "string") { | ||
| messages.push({ message: "\"description\" property must be a string", path: [...context.path, "description"] }) | ||
| } | ||
|
|
||
| messages.push(...xEnturPermissionsValue(targetVal.value, [...context.path, "value"])) | ||
|
|
||
| return messages | ||
| } | ||
|
|
||
| function xEnturPermissionsValue(targetVal, path = []) { | ||
| if (typeof targetVal === "string") { | ||
| const match = targetVal.toLocaleLowerCase().match(/^[0-9a-zæøå][0-9a-zæøå.\\-]{0,99}:(les|opprett|endre|slett)$/) | ||
| if (!match) { | ||
| return [{ message: "Must match format \"permission:(les/opprett/endre/slett)\"", path}] | ||
| } else { | ||
| return [] | ||
| } | ||
| } else if (typeof targetVal === "object") { | ||
| const props = Object.getOwnPropertyNames(targetVal); | ||
|
|
||
| if (props.length != 1 || !["any", "all"].includes(props[0])) { | ||
| return [{ message: "Must be an object with either \"any\" or \"all\"", path}] | ||
| } | ||
|
|
||
| const val = targetVal[props[0]]; | ||
| if (!Array.isArray(val)) { | ||
| return [{ message: "Must be an array", path: [...path, props[0]] }] | ||
| } | ||
|
|
||
| return val.flatMap((x, index) => xEnturPermissionsValue(x, [...path, props[0], index])); | ||
| } else { | ||
| return [{ message: "Must be either an object or a string", path }] | ||
|
|
||
| } | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| { | ||
| "openapi": "3.1.0", | ||
| "info": { | ||
| "title": "Items API", | ||
|
Check warning on line 4 in specs/reference-spec-with-errors.json
|
||
| "version": "1.0.0", | ||
| "description": "A long and descriptive description", | ||
| "termsOfService": "https://developer.entur.org/terms-of-service", | ||
|
|
@@ -10,9 +10,9 @@ | |
| "url": "https://entur.no", | ||
| "email": "support@entur.no" | ||
| }, | ||
| "x-entur-metadata": { | ||
| "owner": "team-Api", | ||
|
Check failure on line 14 in specs/reference-spec-with-errors.json
|
||
| "audience": "public" | ||
|
Check failure on line 15 in specs/reference-spec-with-errors.json
|
||
| } | ||
| }, | ||
|
|
||
|
|
@@ -61,7 +61,7 @@ | |
| "properties": { | ||
| "id": { | ||
| "type": "string", | ||
| "example": 100 | ||
|
Check failure on line 64 in specs/reference-spec-with-errors.json
|
||
| }, | ||
| "name": { | ||
| "type": "string", | ||
|
|
@@ -69,7 +69,7 @@ | |
| } | ||
| }, | ||
| "example": { | ||
| "id": 100, | ||
|
Check failure on line 72 in specs/reference-spec-with-errors.json
|
||
| "name": "Item 100" | ||
| } | ||
| }, | ||
|
|
@@ -160,7 +160,8 @@ | |
| } | ||
| }, | ||
| "x-entur-permissions": { | ||
| "value": "items:les" | ||
| "description": 10, | ||
|
Check failure on line 163 in specs/reference-spec-with-errors.json
|
||
| "value": {"and": ["items:les"]} | ||
|
Check failure on line 164 in specs/reference-spec-with-errors.json
|
||
| } | ||
| }, | ||
| "post": { | ||
|
|
@@ -195,14 +196,15 @@ | |
| } | ||
| }, | ||
| "x-entur-permissions": { | ||
| "bar": "something", | ||
|
Check failure on line 199 in specs/reference-spec-with-errors.json
|
||
| "description": "You need access to read organisations, and create items.", | ||
| "value": { | ||
| "all": [ | ||
| "organisations:les", | ||
| "organisations:le", | ||
|
Check failure on line 203 in specs/reference-spec-with-errors.json
|
||
| { | ||
| "any": [ | ||
| "items:opprett", | ||
| "items-global:opprett" | ||
| "items:oppret", | ||
|
Check failure on line 206 in specs/reference-spec-with-errors.json
|
||
| "items-global:oprett" | ||
| ] | ||
| } | ||
| ] | ||
|
|
@@ -220,7 +222,7 @@ | |
| "tags": [ | ||
| "Items" | ||
| ], | ||
| "deprecated": true, | ||
|
Check notice on line 225 in specs/reference-spec-with-errors.json
|
||
| "summary": "Get an item", | ||
| "description": "Get an item with given id.", | ||
| "operationId": "getItem", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -161,7 +161,7 @@ | |
| } | ||
| }, | ||
| "x-entur-permissions": { | ||
| "value": "items:les" | ||
| "value": "items:LES" | ||
| } | ||
| }, | ||
| "post": { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.