-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Description
Problem statement
swagger flatten --with-flatten=remove-unused
does not remove models that were only referenced by models that were just removed.
That is, if I have model Book
which uses model Author
, if both of them are not used, and I run swagger flatten --with-flatten=remove-unused
then it will only remove Book
model, but will keep Author
as it was considered as used, but it's not really used anymore.
Steps to reproduce
- Let's say you have this simple schema.json
{
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"schemes": [
"http",
"https"
],
"swagger": "2.0",
"info": {
"title": "Sample API.",
"version": "1.0.0"
},
"paths": {
"/hello": {
"get": {
"description": "Hello",
"operationId": "hello",
"responses": {
"200": {
"description": "success"
}
}
}
}
},
"definitions": {
"Author": {
"type": "object",
"properties": {
"name": {
"type": "string"
}
}
},
"Book": {
"type": "object",
"properties": {
"author": {
"$ref": "#/definitions/Author"
}
}
}
}
}
as you can see Author
and Book
are not referenced by any route, however Book
references Author
.
- run
swagger flatten --with-flatten=remove-unused -o=schema.json schema.json
The updateschema.json
does not haveBook
anymore as expected, but still has theAuthor
, which is not really being used as well. SoAuthor
should have been removed as well but it was not.
Temporary Solution
You can run swagger flatten --with-flatten=remove-unused -o=schema.json schema.json
one more time and Author
will be removed, but ideally this tool should be able to remove all unused definitions in one single execution.
Environment
swagger version: 0.26.1
go version: 1.17
OS: macOS