OAI / OAI/OpenAPI-Specification
The Response object's `default` field is confusing and inconsistently interpreted
Nessuno ha ancora preso questa issue.
- Lingua principale
- Markdown
- Stelle
- 31.2k
- Fork
- 9.2k
- Merge medio
- 6h 37m
- PR unite (30g)
- 27
Descrizione
According both 3.0 and 3.1, in theResponse object there MUST be at least one response code and it SHOULD be the response for a successful operation call. In addition the default describes “responses other than the ones declared for specific HTTP response codes”.
This means that if we had a 200 response and default, the latter would cover everything except for 200. Many seem to interpret default to mean something like response categories not covered by explicit response codes. Consider this example from the OAI org:
responses:
'200':
description: pet response
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
default:
description: unexpected error
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
https://github.com/OAI/OpenAPI-Specification/blob/main/examples/v3.0/petstore-expanded.yaml
This implies that default covers error types when in fact it covers non-error responses as well. In fact, the consumer wouldn't necessarily know if the API might reply with another success code such as a 204. A more precise example might look like this:
responses:
'200':
description: pet response
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
4xx:
description: unexpected error
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
5xx:
description: unexpected error
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
I would suggest the following actions:
- Update the example to interpret the spec more literally
- Clarify
defaultsince this confusion is not limited to this example, but extends to APIs in the wild - Consider in 3.2 or 4.0 eliminating
default - Consider in 3.2 or 4.0 adding a new named
errorcategory that means "both 4xx and 5xx". This could be used in the way thatdefaultis often misused today
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia esaminando examples/v3.0/petstore-expanded.yaml e le definizioni dell’oggetto Response per OpenAPI 3.0 e 3.1. Confronta il significato documentato di default con la gestione degli errori prevista dall’esempio, quindi individua quale chiarimento o aggiornamento dell’esempio sia attuabile; per completare il lavoro sarebbe necessario concordare una modifica alla specifica o agli esempi.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- openapi
- Ambito
- api, documentation
- Tipo di issue
- Documentazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 28/100