APIcast icon indicating copy to clipboard operation
APIcast copied to clipboard

Add "format" to the policy configuration definition to allow validation

Open mayorova opened this issue 7 years ago • 5 comments

Adding "format" to the JSON schema of the policies would be useful to allow validation.

So, for example, if there is a "url" required in a policy, the UI for configuring this policy can validate the user input.

Reference: http://json-schema.org/latest/json-schema-validation.html#format

mayorova avatar May 07 '18 17:05 mayorova

@mayorova to which policies?

Policy configuration is defined by JSON schema: https://github.com/3scale/apicast/blob/master/gateway/src/apicast/policy/manifest-schema.json

And individual policies have own JSON schema for the config: https://github.com/3scale/apicast/blob/master/gateway/src/apicast/policy/url_rewriting/apicast-policy.json

mikz avatar May 09 '18 07:05 mikz

@mikz Any policy really, the idea is to have this included into the policy configuration JSON schema, then any policy can use it.

For example, the url config parameter for the upstream policy – I think a validation for the values of this parameter would be nice.

mayorova avatar May 09 '18 08:05 mayorova

@mayorova Then you can add "format": "uri" there and close this issue?

mikz avatar May 09 '18 08:05 mikz

@mikz but then it also needs to be added to https://github.com/3scale/apicast/blob/master/gateway/src/apicast/policy/manifest-schema.json, right?

Btw, specifically in case of upsteam policy "format": "uri" is not exactly correct. The policy expects https?://host:port, and uri also can have path and queryparams...

mayorova avatar May 09 '18 08:05 mayorova

@mayorova no. That one just says every policy has to have valid JSON schema for configuration.

And upstream policy can totally work with full URI: https://github.com/3scale/apicast/blob/6cf9b4a75026faab48b0a799c86d41616d232819/gateway/src/apicast/policy/upstream/upstream.lua#L17-L26 It will override path if you include it in the URI. If you want to spend time doing valid regex that covers all the cases and maintain it then go ahead. Validations do not have to be so strict, because then they can require a lot of maintenance cost for edge cases.

mikz avatar May 09 '18 08:05 mikz