-
Notifications
You must be signed in to change notification settings - Fork 71
THREESCALE-11817: Use json_schemer for policies validation #4069
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
47fa57d
efb651f
51ed054
bfdf2cd
42da4e4
f10c1e0
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,114 @@ | ||
| { | ||
| "$id": "http://apicast.io/policy-v1.1/schema", | ||
| "type": "object", | ||
| "$schema": "http://json-schema.org/draft-07/schema#", | ||
| "definitions": { | ||
| "schema": { | ||
| "$id": "#/definitions/schema", | ||
| "$schema": "http://json-schema.org/draft-07/schema#", | ||
| "default": {} | ||
| }, | ||
| "version": { | ||
| "$id": "#/definitions/version", | ||
| "type": "string", | ||
| "title": "The Policy Version", | ||
| "description": "A semantic version of a policy.", | ||
| "examples": [ | ||
| "1.3.4", | ||
| "0.1" | ||
| ], | ||
| "pattern": "^((\\d+\\.)?(\\d+\\.)?(\\*|\\d+))|builtin$" | ||
| } | ||
| }, | ||
| "properties": { | ||
| "name": { | ||
| "$id": "/properties/name", | ||
| "type": "string", | ||
| "title": "The Policy Name", | ||
| "description": "Name of the policy.", | ||
| "examples": [ | ||
| "Basic Authentication" | ||
| ], | ||
| "minLength": 1 | ||
| }, | ||
| "summary": { | ||
| "$id": "/properties/summary", | ||
| "type": "string", | ||
| "title": "The Policy Summary", | ||
| "description": "Short description of what the policy does", | ||
| "examples": [ | ||
| "Enables CORS (Cross Origin Resource Sharing) request handling." | ||
| ], | ||
| "maxLength": 75 | ||
| }, | ||
| "description": { | ||
| "$id": "/properties/description", | ||
| "oneOf": [ | ||
| { "type": "string", | ||
| "minLength": 1 }, | ||
| { "type": "array", "items": { "type": "string" }, | ||
| "minItems": 1 | ||
| } | ||
| ], | ||
| "title": "The Policy Description", | ||
| "description": "Longer description of what the policy does.", | ||
| "examples": [ | ||
| "Extract authentication credentials from the HTTP Authorization header and pass them to 3scale backend.", | ||
| [ "Redirect request to different upstream: ", " - based on path", "- set different Host header"] | ||
| ] | ||
| }, | ||
| "order": { | ||
| "$id": "/properties/order", | ||
| "type": "object", | ||
| "title": "Order restrictions of the policy", | ||
| "description": "Specifies before or after which policies the policy should be placed in the chain.", | ||
| "properties": { | ||
| "before": { | ||
| "type": "array", | ||
| "items": { | ||
| "type": "object", | ||
| "properties": { | ||
| "name": { | ||
| "type": "string" | ||
| }, | ||
| "version": { | ||
| "type": "string" | ||
| } | ||
| }, | ||
| "required": [ | ||
| "name", | ||
| "version" | ||
| ] | ||
| }, | ||
| "description": "The policy should be placed before these ones in the chain." | ||
| }, | ||
| "after": { | ||
| "type": "array", | ||
| "items": { | ||
| "type": "object", | ||
| "properties": { | ||
| "name": { | ||
| "type": "string" | ||
| }, | ||
| "version": { | ||
| "type": "string" | ||
| } | ||
| }, | ||
| "required": [ | ||
| "name", | ||
| "version" | ||
| ] | ||
| }, | ||
| "description": "The policy should be placed after these ones in the chain." | ||
| } | ||
| } | ||
| }, | ||
| "version": { | ||
| "$ref": "#/definitions/version" | ||
| }, | ||
| "configuration": { | ||
| "$ref": "#/definitions/schema" | ||
| } | ||
| }, | ||
| "required": ["name", "version", "configuration", "summary"] | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,11 @@ | ||
| { | ||
| "$id": "http://apicast.io/policy-v1/schema#manifest", | ||
| "$id": "http://apicast.io/policy-v1/schema", | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, having While it is not prohibited as such in JSON schema, in So, there are relative references in the schema: When they are resolved, the "location" of the reference is defined as The library then goes "backwards" and tries to find corresponding schema to resolve the reference, and takes the base URL which is I guess In general, I think it's better to avoid
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. https://json-schema.org/understanding-json-schema/structuring It looks like the fragment Not having it is probably not a big deal. It is interesting to know whether the fragment is wrong and perhaps was previously just ignored. Or schemer handles that fragment improperly. |
||
| "type": "object", | ||
| "$schema": "http://json-schema.org/draft-07/schema#", | ||
| "definitions": { | ||
| "schema": { | ||
| "$id": "#/definitions/schema", | ||
| "$ref": "http://json-schema.org/draft-07/schema#", | ||
| "$schema": "http://json-schema.org/draft-07/schema#", | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This
I actually don't know whether it is supposed to work, but in fact, I assume that
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But doesn't this file have to match the same file in apicast? Or am I wrong?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, ideally, yes, they should match. I did open a PR to fix inconsistencies, but actually, I missed this specific entry. So, thanks for catching this! |
||
| "default": {} | ||
| }, | ||
| "version": { | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess we can remove this because it's now integrated in |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current version of the apicast policy schema is v1.1: https://github.com/3scale/APIcast/blob/5c33a1b896545a1421dc4162ea8651f389dcaa6d/gateway/src/apicast/policy/manifest-schema.json
Added in 3scale/APIcast@9e1a5c7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this is copied from there?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, copied from there and adjusted
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem then is we have to keep our copy synced with the original. Would it be possible to download and use the original? Is this the same as the
APICAST_REGISTRY_URLvariable? For consistency it would be good to use that variable as a single source of truth. Does this make any sense?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
APICAST_REGISTRY_URLdoesn't expose that manifest, AFAIK.