OpenAPITools / OpenAPITools/openapi-diff
False positive when adding optional property
Nessuno ha ancora preso questa issue.
- Lingua principale
- Java
- Stelle
- 1.1k
- Fork
- 190
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
When comparing these 2 schemas:
test/old.json
{
"openapi": "3.0.0",
"servers": [{ "url": "https://myserver.com" }],
"info": { "title": "My API", "description": "Description", "version": "0.2.0" },
"paths": {
"/v1/entity/{id}": {
"put": {
"operationId": "myOperation",
"description": "Some description",
"requestBody": { "$ref": "#/components/requestBodies/updateBody" }
}
}
},
"components": {
"schemas": {},
"responses": {},
"requestBodies": {
"updateBody": {
"description": "Update description",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"url": { "type": "string", "description": "Some URL" }
},
"title": "updateBody",
"additionalProperties": false
}
}
}
}
},
"parameters": {}
}
}
test/new.json
{
"openapi": "3.0.0",
"servers": [{ "url": "https://myserver.com" }],
"info": { "title": "My API", "description": "Description", "version": "0.2.0" },
"paths": {
"/v1/entity/{id}": {
"put": {
"operationId": "myOperation",
"description": "Some description",
"requestBody": { "$ref": "#/components/requestBodies/updateBody" }
}
}
},
"components": {
"schemas": {},
"responses": {},
"requestBodies": {
"updateBody": {
"description": "Update description",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"url": { "type": "string", "description": "Some URL" },
"url2": { "type": "string", "description": "Some URL" }
},
"title": "updateBody",
"additionalProperties": false
}
}
}
}
},
"parameters": {}
}
}
I get a broken compatibility message:
docker run --rm -t -v $(pwd)/test/:/specs:ro openapitools/openapi-diff:latest --fail-on-incompatible /specs/old.json /specs/new.json
==========================================================================
== API CHANGE LOG ==
==========================================================================
My API
--------------------------------------------------------------------------
-- What's Changed --
--------------------------------------------------------------------------
- PUT /v1/entity/{id}
Request:
- Changed application/json
Schema: Broken compatibility
--------------------------------------------------------------------------
-- Result --
--------------------------------------------------------------------------
API changes broke backward compatibility
--------------------------------------------------------------------------
Note that the only change is the addition of the url2 optional property:
diff -u test/old.json test/new.json
--- test/old.json 2023-03-14 17:06:02
+++ test/new.json 2023-03-14 17:06:33
@@ -22,7 +22,8 @@
"schema": {
"type": "object",
"properties": {
- "url": { "type": "string", "description": "Some URL" }
+ "url": { "type": "string", "description": "Some URL" },
+ "url2": { "type": "string", "description": "Some URL" }
},
"title": "updateBody",
"additionalProperties": false
Since the required field is absent, I would expect the addition of url2 to not create a broken compatibility error.
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 con i fixture forniti test/old.json e test/new.json e riproduci il risultato usando il comando Docker riportato nel report. Traccia il controllo di compatibilità dello schema del corpo della richiesta per una proprietà aggiunta senza un campo obbligatorio, quindi aggiungi un test di regressione e conferma che il confronto non segnali più una modifica incompatibile con le versioni precedenti.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- java
- Ambito
- api
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 42/100