Closed bfitzpat closed 5 years ago
Zoran suggested an example here - this is what we will try and remove from the incoming swagger.
Example swagger:
{
"swagger": "2.0",
"info": {
"title": "Todo App API",
"description": "Example Todo Application API",
"version": "1.0.0",
"license": {
"name": "Apache 2.0",
"url": "http://www.apache.org/licenses/LICENSE-2.0.html"
}
},
"host": "todo-syndesis-staging.b6ff.rh-idev.openshiftapps.com",
"basePath": "/api",
"schemes": [
"http",
"https"
],
"paths": {
"/": {
"get": {
"tags": [
"tasks",
"fetching"
],
"summary": "List all tasks",
"description": "Fetches all tasks from the database",
"produces": [
"application/json"
],
"responses": {
"200": {
"description": "All is good",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/Task"
}
}
}
}
},
"post": {
"tags": [
"tasks",
"creating"
],
"summary": "Create new task",
"description": "Stores new task in the database",
"produces": [
"application/json"
],
"consumes": [
"application/json"
],
"parameters": [
{
"in": "body",
"name": "body",
"description": "Task to create",
"required": true,
"schema": {
"$ref": "#/definitions/Task"
}
}
],
"responses": {
"201": {
"description": "All is good",
"schema": {
"$ref": "#/definitions/Task"
}
}
}
}
},
"/{id}": {
"get": {
"tags": [
"tasks",
"fetching"
],
"summary": "Fetch task",
"description": "Fetches task by given identifier",
"produces": [
"application/json"
],
"parameters": [
{
"in": "path",
"name": "id",
"type": "integer",
"format": "int64",
"description": "Task identifier",
"required": true
}
],
"responses": {
"200": {
"description": "All is good",
"schema": {
"$ref": "#/definitions/Task"
}
},
"404": {
"description": "No task with provided identifier found"
}
}
},
"put": {
"tags": [
"tasks",
"updating"
],
"summary": "Update task",
"description": "Updates task by given identifier",
"produces": [
"application/json"
],
"consumes": [
"application/json"
],
"parameters": [
{
"in": "path",
"name": "id",
"type": "integer",
"format": "int64",
"description": "Task identifier",
"required": true
},
{
"in": "body",
"name": "body",
"description": "Task with updates",
"required": true,
"schema": {
"$ref": "#/definitions/Task"
}
}
],
"responses": {
"200": {
"description": "All is good",
"schema": {
"$ref": "#/definitions/Task"
}
}
}
},
"delete": {
"tags": [
"tasks",
"destruction"
],
"summary": "Delete task",
"description": "Deletes task by given identifier",
"parameters": [
{
"in": "path",
"name": "id",
"type": "integer",
"format": "int64",
"description": "Task identifier to delete",
"required": true
}
],
"responses": {
"204": {
"description": "Task deleted"
}
}
}
}
},
"securityDefinitions": {
"username_password": {
"type": "basic"
}
},
"definitions": {
"Task": {
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64",
"title": "Task ID",
"description": "Unique task identifier"
},
"task": {
"type": "string",
"title": "The task",
"description": "Task line"
},
"completed": {
"type": "integer",
"title": "Task completition status",
"description": "0 - ongoing, 1 - completed",
"minimum": 0,
"maximum": 1
}
}
}
}
}
With some hacking, I have it reducing to this (host and scheme are still there, but empty). @zregvart is that sufficient or do they need to be completely removed from the exported openapi json?
{
"swagger" : "2.0",
"info" : {
"description" : "Example Todo Application API",
"version" : "1.0.0",
"title" : "Todo App API",
"license" : {
"name" : "Apache 2.0",
"url" : "http://www.apache.org/licenses/LICENSE-2.0.html"
}
},
"host" : "",
"basePath" : "/api",
"schemes" : [ ],
"paths" : {
"/" : {
"get" : {
"tags" : [ "tasks", "fetching" ],
"summary" : "List all tasks",
"description" : "Fetches all tasks from the database",
"produces" : [ "application/json" ],
"parameters" : [ ],
"responses" : {
"200" : {
"description" : "All is good",
"schema" : {
"type" : "array",
"items" : {
"$ref" : "#/definitions/Task"
}
}
}
}
},
"post" : {
"tags" : [ "tasks", "creating" ],
"summary" : "Create new task",
"description" : "Stores new task in the database",
"consumes" : [ "application/json" ],
"produces" : [ "application/json" ],
"parameters" : [ {
"in" : "body",
"name" : "body",
"description" : "Task to create",
"required" : true,
"schema" : {
"$ref" : "#/definitions/Task"
}
} ],
"responses" : {
"201" : {
"description" : "All is good",
"schema" : {
"$ref" : "#/definitions/Task"
}
}
}
}
},
"/{id}" : {
"get" : {
"tags" : [ "tasks", "fetching" ],
"summary" : "Fetch task",
"description" : "Fetches task by given identifier",
"produces" : [ "application/json" ],
"parameters" : [ {
"name" : "id",
"in" : "path",
"description" : "Task identifier",
"required" : true,
"type" : "integer",
"format" : "int64"
} ],
"responses" : {
"200" : {
"description" : "All is good",
"schema" : {
"$ref" : "#/definitions/Task"
}
},
"404" : {
"description" : "No task with provided identifier found"
}
}
},
"put" : {
"tags" : [ "tasks", "updating" ],
"summary" : "Update task",
"description" : "Updates task by given identifier",
"consumes" : [ "application/json" ],
"produces" : [ "application/json" ],
"parameters" : [ {
"name" : "id",
"in" : "path",
"description" : "Task identifier",
"required" : true,
"type" : "integer",
"format" : "int64"
}, {
"in" : "body",
"name" : "body",
"description" : "Task with updates",
"required" : true,
"schema" : {
"$ref" : "#/definitions/Task"
}
} ],
"responses" : {
"200" : {
"description" : "All is good",
"schema" : {
"$ref" : "#/definitions/Task"
}
}
}
},
"delete" : {
"tags" : [ "tasks", "destruction" ],
"summary" : "Delete task",
"description" : "Deletes task by given identifier",
"parameters" : [ {
"name" : "id",
"in" : "path",
"description" : "Task identifier to delete",
"required" : true,
"type" : "integer",
"format" : "int64"
} ],
"responses" : {
"204" : {
"description" : "Task deleted"
}
}
}
}
},
"securityDefinitions" : {
"username_password" : {
"type" : "basic"
}
},
"definitions" : {
"Task" : {
"type" : "object",
"properties" : {
"id" : {
"type" : "integer",
"format" : "int64",
"description" : "Unique task identifier",
"title" : "Task ID"
},
"task" : {
"type" : "string",
"description" : "Task line",
"title" : "The task"
},
"completed" : {
"type" : "integer",
"description" : "0 - ongoing, 1 - completed",
"title" : "Task completition status",
"minimum" : 0,
"maximum" : 1
}
}
}
}
}
@zregvart suggested nulling out the host and schemes, so the resulting openapi file is a bit cleaner:
{
"swagger" : "2.0",
"info" : {
"description" : "Example Todo Application API",
"version" : "1.0.0",
"title" : "Todo App API",
"license" : {
"name" : "Apache 2.0",
"url" : "http://www.apache.org/licenses/LICENSE-2.0.html"
}
},
"basePath" : "/api",
"paths" : {
"/" : {
"get" : {
"tags" : [ "tasks", "fetching" ],
"summary" : "List all tasks",
"description" : "Fetches all tasks from the database",
"produces" : [ "application/json" ],
"parameters" : [ ],
"responses" : {
"200" : {
"description" : "All is good",
"schema" : {
"type" : "array",
"items" : {
"$ref" : "#/definitions/Task"
}
}
}
}
},
"post" : {
"tags" : [ "tasks", "creating" ],
"summary" : "Create new task",
"description" : "Stores new task in the database",
"consumes" : [ "application/json" ],
"produces" : [ "application/json" ],
"parameters" : [ {
"in" : "body",
"name" : "body",
"description" : "Task to create",
"required" : true,
"schema" : {
"$ref" : "#/definitions/Task"
}
} ],
"responses" : {
"201" : {
"description" : "All is good",
"schema" : {
"$ref" : "#/definitions/Task"
}
}
}
}
},
"/{id}" : {
"get" : {
"tags" : [ "tasks", "fetching" ],
"summary" : "Fetch task",
"description" : "Fetches task by given identifier",
"produces" : [ "application/json" ],
"parameters" : [ {
"name" : "id",
"in" : "path",
"description" : "Task identifier",
"required" : true,
"type" : "integer",
"format" : "int64"
} ],
"responses" : {
"200" : {
"description" : "All is good",
"schema" : {
"$ref" : "#/definitions/Task"
}
},
"404" : {
"description" : "No task with provided identifier found"
}
}
},
"put" : {
"tags" : [ "tasks", "updating" ],
"summary" : "Update task",
"description" : "Updates task by given identifier",
"consumes" : [ "application/json" ],
"produces" : [ "application/json" ],
"parameters" : [ {
"name" : "id",
"in" : "path",
"description" : "Task identifier",
"required" : true,
"type" : "integer",
"format" : "int64"
}, {
"in" : "body",
"name" : "body",
"description" : "Task with updates",
"required" : true,
"schema" : {
"$ref" : "#/definitions/Task"
}
} ],
"responses" : {
"200" : {
"description" : "All is good",
"schema" : {
"$ref" : "#/definitions/Task"
}
}
}
},
"delete" : {
"tags" : [ "tasks", "destruction" ],
"summary" : "Delete task",
"description" : "Deletes task by given identifier",
"parameters" : [ {
"name" : "id",
"in" : "path",
"description" : "Task identifier to delete",
"required" : true,
"type" : "integer",
"format" : "int64"
} ],
"responses" : {
"204" : {
"description" : "Task deleted"
}
}
}
}
},
"securityDefinitions" : {
"username_password" : {
"type" : "basic"
}
},
"definitions" : {
"Task" : {
"type" : "object",
"properties" : {
"id" : {
"type" : "integer",
"format" : "int64",
"description" : "Unique task identifier",
"title" : "Task ID"
},
"task" : {
"type" : "string",
"description" : "Task line",
"title" : "The task"
},
"completed" : {
"type" : "integer",
"description" : "0 - ongoing, 1 - completed",
"title" : "Task completition status",
"minimum" : 0,
"maximum" : 1
}
}
}
}
}
Merged https://github.com/jboss-fuse/fuse-apicurito-generator/pull/21
@tsedmik can you verify this when you get a chance?
verified with master branch + I covered this issue with automated test see: https://github.com/tsedmik/fuse-apicurito-generator-tests/blob/master/src/test/resources/com/github/tsedmik/fuse_apicurito_generator_tests/open_api_file.feature
When Apicurito generates an OpenAPI specification (swagger/json file) and hands it to the fuse project generator, that specification sometimes includes the "host" and "schemes" sections. @zregvart and @chirino have asked that we strip those sections out of the json for the file that we stash in the project.
As Hiram said in the e-mail stream that spawned this issue: