Skip to content

uri() fails RFC3986 4.2 relative reference URIs #815

@garthk

Description

@garthk
> require('joi').string().uri().validate('/foo')
{ error: 
   { [ValidationError: "value" must be a valid uri]
…

A relative relative reference takes advantage of the hierarchical syntax(Section 1.2.3) to express a URI reference relative to the name space of another hierarchical URI
– RFC 3986 Section 4.2

If you insist on a URL being locatable, you should a) add a new method url to so insist, and b) consider what you're going to do about this case:

> require('joi').string().uri().validate('http:/')
{ error: null, value: 'http:/' }

Scenario: I'd like to issue relative paths to other documents from an API while keeping the option open to make them absolute. It feels wrong to document them as plain strings. I'd like the result, run through joi-to-json-schema, to wear the format uri.

Metadata

Metadata

Assignees

Labels

bugBug or defectfeatureNew functionality or improvement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions