Comments (8)
Thanks, I will have a look
from ajv.
There are two issues here.
- The string isn't a valid resource address (e.g. http://example.com) according to JSON-schema standard, that is a bit contradictory about what a valid URI is, but the test suite they supply mandates the presence of '//' (you can check formats file). For your kind of URN/URI you can either add a custom format or redefine URI format with
ajv.addFormat('uri', /some_pattern/)
. ajv.errorsText()
without parameters will return errors as a string only if you usedajv.validate()
rather than a compiled function (see examples in readme). Using compiled function is recommended as it is a bit faster. In this case you can access errors either viavalid.errors
(an array) or viaajv.errorsText(valid.errors)
(a string).
from ajv.
@nichtich with the latest change from @johanlelan URIs need to have at lease a single "/" character (was two slashes). Please feel free to reopen if my suggestions above are not working for you. Thanks
from ajv.
Thanks for pointing to the sources and the second issue. My original bug report, however remains:
json-schema-validation spec. section 7.3.6. defines validation of the uri
format as following:
A string instance is valid against this attribute if it is a valid URI, according to RFC3986
RFC 3986 lists some examples of URIs, several of them not containing a /
. The specification contains a detailed grammar. Any regular expression for testing URI should allow at least this formal language. Sure ajv does not need to implemented all of its complexity but use a simplified regular expression.
from ajv.
👍 It would be really great if you could suggest changes to the regular expressions ajv uses (in PR or just here).
from ajv.
I found this regular expression for generics URI on Regular Expression Cookbook (https://github.com/shihyu/Regular_Expressions/blob/master/O'Reilly-Regular%20Expressions%20Cookbook(2nd%20Edition).pdf)
^([a-z][a-z0-9+\-.]*:(\/\/([a-z0-9\-._~%!$&'()*+,;=]+@)?([a-z0-9\-._~%]+|\[[a-f0-9:.]+\]|\[v[a-f0-9][a-z0-9\-._~%!$&'()*+,;=:]+\])(:[0-9]+)?(\/[a-z0-9\-._~%!$&'()*+,;=:@]+)*\/?|(\/?[a-z0-9\-._~%!$&'()*+,;=:@]+(\/[a-z0-9\-._~%!$&'()*+,;=:@]+)*\/?)?)|([a-z0-9\-._~%!$&'()*+,;=@]+(\/[a-z0-9\-._~%!$&'()*+,;=:@]+)*\/?|(\/[a-z0-9\-._~%!$&'()*+,;=:@]+)+\/?))(\?[a-z0-9\-._~%!$&'()*+,;=:@\/?]*)?(#[a-zA-Z0-9\-._~%!$&'()*+,;=:@\/?]*)?$
It validates your urn @nichtich !
It validates the relatives URLs !
And of course, classics URLs :)
There is just one improvement to think about: case sensitive URIs.
For me URI are case insensitive but in real life, it depends on web server implementation.
So if you want to manage case sensitive URIs, juste replace a-z by a-zA-Z in all occurences.
Hope that helps!
from ajv.
Cool, thanks!. Can be just /.../i
from ajv.
The problem with that regex is that it also validates URI fragments (like 'abc'), and it shouldn't... It will fail the test. I'll see how it can be changed so URI fragments don't match.
from ajv.
Related Issues (20)
- Ref within def does not act consistently
- JSONSchemaType $ref doesn't work in array type. HOT 5
- oneOf returns unwanted errors HOT 1
- Description key set as boolean returns error that it must be string HOT 2
- Validate and infer JSON Schema validated data type: introducing type providers HOT 3
- JTD schema parser errors on empty properties field HOT 1
- Implement x-inOrder subschema for in order or sequential processing HOT 3
- additionalProperties shouldn't affect TypeScript types from JTDDataType HOT 2
- option compile from addKeyword doesn't change on a remove and then add again
- OneOf validation issue HOT 1
- Cannot find module 'ajv/dist/compile/codegen' HOT 2
- How can I make a property value depend on the value of another property? HOT 1
- Error using multipleOf with decimals HOT 1
- Using if/then/else fails validation HOT 1
- compileParser does not appear to support properties with type `field?: Record<string, unknown>` via `JTDSchemaType`. HOT 2
- Integers as Discriminators HOT 7
- How can I access `definitions` in schema-store using `$ref`?
- DeprecationWarning: The punycode module is deprecated #96 HOT 2
- `maxLength` constraint checking seems to not code (Hindi) unicode characters properly HOT 7
- ajv 8.13.0 upgrade doesn't work with ajv-formats 3.0.1 with TypeScript HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ajv.