Open ThomasKoppensteiner opened 3 years ago
Just adding another example here:
openapi: 3.1.0
info:
title: URI Reference Test Case
version: '1.0'
servers:
- url: 'http://localhost:3000'
paths:
/thing:
parameters: []
get:
summary: ''
operationId: get-thing
responses:
'200':
description: OK
content:
application/json:
schema:
type: object
properties:
uri-broken:
type: string
format: uri-reference
readOnly: true
uri-working:
type: string
format: uri-reference
readOnly: true
examples:
example-1:
value:
uri-broken: 'https://example.com/some/endpoint?page[cursor]=123'
uri-working: 'https://example.com/some/endpoint?page%5Bcursor%5D=123'
components:
schemas: {}
This results in a oas3-valid-media-example
error in Stoplight UI and Spectral lint for the uri-broken
field. This means that for APIs based on JSON:API, for example, which uses square brackets extensively, API designers have to constantly encode square brackets even though they're valid characters in a URI.
Another point of reference: https://jsonschemalint.com/#!/version/draft-07/markup/json#%2Fversion%2Fdraft-04%2Fmarkup%2Fjson . Using this schema:
{
"type": "object",
"properties": {
"test": {
"type": "string",
"format": "uri-reference"
}
}
}
validates correctly for this doc:
{
"test": "https://example.com/some/endpoint?page[cursor]=123"
}
User story. As an API designer, I can use square brackets in URI strings so that the validation is still valid.
Is your feature request related to a problem? I would like to use square brackets in paginations links (for convenience and readability reasons), without the need to url-encoded them.
Describe the solution you'd like Squared brackets are automatically url-encoded before the validation in case
string <uri>
orstring <uri-reference>
is used.Additional context Error message
"next" property must match format "uri-reference"