{
"swagger":"2.0",
"info":{
"description":"Network Automation Platform API Documentation, generated by swagger2",
"title":"NAP API Documentation"
},
"host":"localhost:8081",
"basePath":"/api",
"tags":[
{
"name":"auth-rest-controller",
"description":"Authentication"
},
{
"name":"user-group-rest-controller",
"description":"User group"
},
{
"name":"credentials-rest-controller",
"description":"Device credentials"
},
{
"name":"user-rest-controller",
"description":"User operations"
},
{
"name":"device-group-rest-controller",
"description":"Device group operations"
},
{
"name":"role-rest-controller",
"description":"User roles"
},
{
"name":"device-rest-controller",
"description":"Network device operations"
}
],
"paths":{
"/auth":{
"post":{
"tags":[
"auth-rest-controller"
],
"summary":"对登录信息做校验",
"description":"jwt token包含在response header里的Authorization字段里",
"operationId":"loginUsingPOST",
"consumes":[
"application/json"
],
"produces":[
"*/*"
],
"parameters":[
{
"in":"body",
"name":"user",
"description":"user",
"required":true,
"schema":{
"$ref":"#/definitions/User"
}
}
],
"responses":{
"200":{
"description":"OK",
"schema":{
"$ref":"#/definitions/User"
}
}
}
}
},
"/credentials":{
"get":{
"tags":[
"credentials-rest-controller"
],
"summary":"获取凭据列表",
"operationId":"listUsingGET",
"consumes":[
"application/json"
],
"produces":[
"*/*"
],
"parameters":[
{
"name":"Authorization",
"in":"header",
"description":"Authorization",
"required":true,
"type":"string"
}
],
"responses":{
"200":{
"description":"OK",
"schema":{
"type":"array",
"items":{
"$ref":"#/definitions/Credentials"
}
}
}
}
},
"post":{
"tags":[
"credentials-rest-controller"
],
"summary":"添加新的凭据",
"operationId":"addUsingPOST",
"consumes":[
"application/json"
],
"produces":[
"*/*"
],
"parameters":[
{
"in":"body",
"name":"credential",
"description":"credential",
"required":true,
"schema":{
"$ref":"#/definitions/Credentials"
}
},
{
"name":"Authorization",
"in":"header",
"description":"Authorization",
"required":true,
"type":"string"
}
],
"responses":{
"200":{
"description":"OK",
"schema":{
"$ref":"#/definitions/Credentials"
}
}
}
}
},
"/credentials/{id}":{
"get":{
"tags":[
"credentials-rest-controller"
],
"summary":"获取指定的凭据信息",
"operationId":"getUsingGET",
"consumes":[
"application/json"
],
"produces":[
"*/*"
],
"parameters":[
{
"name":"id",
"in":"path",
"description":"id",
"required":true,
"type":"string"
},
{
"name":"Authorization",
"in":"header",
"description":"Authorization",
"required":true,
"type":"string"
}
],
"responses":{
"200":{
"description":"OK",
"schema":{
"$ref":"#/definitions/Credentials"
}
}
}
},
"put":{
"tags":[
"credentials-rest-controller"
],
"summary":"更新指定的凭据",
"operationId":"updateUsingPUT",
"consumes":[
"application/json"
],
"produces":[
"*/*"
],
"parameters":[
{
"in":"body",
"name":"credential",
"description":"credential",
"required":true,
"schema":{
"$ref":"#/definitions/Credentials"
}
},
{
"name":"Authorization",
"in":"header",
"description":"Authorization",
"required":true,
"type":"string"
}
],
"responses":{
"200":{
"description":"OK",
"schema":{
"$ref":"#/definitions/Credentials"
}
}
}
},
"delete":{
"tags":[
"credentials-rest-controller"
],
"summary":"删除指定的凭据",
"operationId":"deleteUsingDELETE",
"consumes":[
"application/json"
],
"produces":[
"*/*"
],
"parameters":[
{
"name":"id",
"in":"path",
"description":"id",
"required":true,
"type":"string"
},
{
"name":"Authorization",
"in":"header",
"description":"Authorization",
"required":true,
"type":"string"
}
],
"responses":{
"200":{
"description":"OK",
"schema":{
"type":"object"
}
}
}
}
},
"/device":{
"get":{
"tags":[
"device-rest-controller"
],
"summary":"获取设备列表",
"operationId":"listUsingGET_2",
"consumes":[
"application/json"
],
"produces":[
"*/*"
],
"parameters":[
{
"name":"Authorization",
"in":"header",
"description":"Authorization",
"required":true,
"type":"string"
}
],
"responses":{
"200":{
"description":"OK",
"schema":{
"type":"array",
"items":{
"$ref":"#/definitions/Device"
}
}
}
}
},
"post":{
"tags":[
"device-rest-controller"
],
"summary":"添加新的设备",
"operationId":"addUsingPOST_2",
"consumes":[
"application/json"
],
"produces":[
"*/*"
],
"parameters":[
{
"in":"body",
"name":"device",
"description":"device",
"required":true,
"schema":{
"$ref":"#/definitions/Device"
}
},
{
"name":"Authorization",
"in":"header",
"description":"Authorization",
"required":true,
"type":"string"
}
],
"responses":{
"200":{
"description":"OK",
"schema":{
"$ref":"#/definitions/Device"
}
}
}
}
},
"/device/group":{
"get":{
"tags":[
"device-group-rest-controller"
],
"summary":"获取设备组列表",
"operationId":"listUsingGET_1",
"consumes":[
"application/json"
],
"produces":[
"*/*"
],
"parameters":[
{
"name":"Authorization",
"in":"header",
"description":"Authorization",
"required":true,
"type":"string"
}
],
"responses":{
"200":{
"description":"OK",
"schema":{
"type":"array",
"items":{
"$ref":"#/definitions/Group"
}
}
}
}
},
"post":{
"tags":[
"device-group-rest-controller"
],
"summary":"添加新的设备组",
"operationId":"addUsingPOST_1",
"consumes":[
"application/json"
],
"produces":[
"*/*"
],
"parameters":[
{
"in":"body",
"name":"group",
"description":"group",
"required":true,
"schema":{
"$ref":"#/definitions/Group"
}
},
{
"name":"Authorization",
"in":"header",
"description":"Authorization",
"required":true,
"type":"string"
}
],
"responses":{
"200":{
"description":"OK",
"schema":{
"$ref":"#/definitions/Group"
}
}
}
}
},
"/device/group/{id}":{
"get":{
"tags":[
"device-group-rest-controller"
],
"summary":"获取指定的设备组信息",
"operationId":"getUsingGET_1",
"consumes":[
"application/json"
],
"produces":[
"*/*"
],
"parameters":[
{
"name":"id",
"in":"path",
"description":"id",
"required":true,
"type":"integer",
"format":"int64"
},
{
"name":"Authorization",
"in":"header",
"description":"Authorization",
"required":true,
"type":"string"
}
],
"responses":{
"200":{
"description":"OK",
"schema":{
"$ref":"#/definitions/Group"
}
}
}
},
"put":{
"tags":[
"device-group-rest-controller"
],
"summary":"更新指定的设备组",
"operationId":"updateUsingPUT_1",
"consumes":[
"application/json"
],
"produces":[
"*/*"
],
"parameters":[
{
"in":"body",
"name":"group",
"description":"group",
"required":true,
"schema":{
"$ref":"#/definitions/Group"
}
},
{
"name":"Authorization",
"in":"header",
"description":"Authorization",
"required":true,
"type":"string"
}
],
"responses":{
"200":{
"description":"OK",
"schema":{
"$ref":"#/definitions/Group"
}
}
}
},
"delete":{
"tags":[
"device-group-rest-controller"
],
"summary":"删除指定的设备组",
"operationId":"deleteUsingDELETE_1",
"consumes":[
"application/json"
],
"produces":[
"*/*"
],
"parameters":[
{
"name":"id",
"in":"path",
"description":"id",
"required":true,
"type":"integer",
"format":"int64"
},
{
"name":"Authorization",
"in":"header",
"description":"Authorization",
"required":true,
"type":"string"
}
],
"responses":{
"200":{
"description":"OK",
"schema":{
"type":"object"
}
}
}
}
},
"/device/{id}":{
"get":{
"tags":[
"device-rest-controller"
],
"summary":"获取指定的设备信息",
"operationId":"getUsingGET_2",
"consumes":[
"application/json"
],
"produces":[
"*/*"
],
"parameters":[
{
"name":"id",
"in":"path",
"description":"id",
"required":true,
"type":"string"
},
{
"name":"Authorization",
"in":"header",
"description":"Authorization",
"required":true,
"type":"string"
}
],
"responses":{
"200":{
"description":"OK",
"schema":{
"$ref":"#/definitions/Device"
}
}
}
},
"put":{
"tags":[
"device-rest-controller"
],
"summary":"更新指定的设备信息",
"operationId":"updateUsingPUT_2",
"consumes":[
"application/json"
],
"produces":[
"*/*"
],
"parameters":[
{
"in":"body",
"name":"device",
"description":"device",
"required":true,
"schema":{
"$ref":"#/definitions/Device"
}
},
{
"name":"Authorization",
"in":"header",
"description":"Authorization",
"required":true,
"type":"string"
}
],
"responses":{
"200":{
"description":"OK",
"schema":{
"$ref":"#/definitions/Device"
}
}
}
},
"delete":{
"tags":[
"device-rest-controller"
],
"summary":"删除指定的设备",
"operationId":"deleteUsingDELETE_2",
"consumes":[
"application/json"
],
"produces":[
"*/*"
],
"parameters":[
{
"name":"id",
"in":"path",
"description":"id",
"required":true,
"type":"string"
},
{
"name":"Authorization",
"in":"header",
"description":"Authorization",
"required":true,
"type":"string"
}
],
"responses":{
"200":{
"description":"OK",
"schema":{
"$ref":"#/definitions/Device"
}
}
}
}
},
"/role":{
"get":{
"tags":[
"role-rest-controller"
],
"summary":"获取角色列表",
"operationId":"listUsingGET_3",
"consumes":[
"application/json"
],
"produces":[
"*/*"
],
"parameters":[
{
"name":"Authorization",
"in":"header",
"description":"Authorization",
"required":true,
"type":"string"
}
],
"responses":{
"200":{
"description":"OK",
"schema":{
"type":"array",
"items":{
"$ref":"#/definitions/Role"
}
}
}
}
},
"post":{
"tags":[
"role-rest-controller"
],
"summary":"触发角色自动添加",
"operationId":"addUsingPOST_3",
"consumes":[
"application/json"
],
"produces":[
"*/*"
],
"parameters":[
{
"name":"Authorization",
"in":"header",
"description":"Authorization",
"required":true,
"type":"string"
}
],
"responses":{
"200":{
"description":"OK",
"schema":{
"type":"object"
}
}
}
}
},
"/role/{id}":{
"get":{
"tags":[
"role-rest-controller"
],
"summary":"获取指定的角色信息",
"operationId":"getUsingGET_3",
"consumes":[
"application/json"
],
"produces":[
"*/*"
],
"parameters":[
{
"name":"id",
"in":"path",
"description":"id",
"required":true,
"type":"integer",
"format":"int64"
},
{
"name":"Authorization",
"in":"header",
"description":"Authorization",
"required":true,
"type":"string"
}
],
"responses":{
"200":{
"description":"OK",
"schema":{
"$ref":"#/definitions/Role"
}
}
}
},
"delete":{
"tags":[
"role-rest-controller"
],
"summary":"删除指定的角色",
"operationId":"deleteUsingDELETE_3",
"consumes":[
"application/json"
],
"produces":[
"*/*"
],
"parameters":[
{
"name":"id",
"in":"path",
"description":"id",
"required":true,
"type":"integer",
"format":"int64"
},
{
"name":"Authorization",
"in":"header",
"description":"Authorization",
"required":true,
"type":"string"
}
],
"responses":{
"200":{
"description":"OK",
"schema":{
"type":"object"
}
}
}
}
},
"/user":{
"get":{
"tags":[
"user-rest-controller"
],
"summary":"获取用户列表",
"operationId":"listUsingGET_5",
"consumes":[
"application/json"
],
"produces":[
"*/*"
],
"parameters":[
{
"name":"Authorization",
"in":"header",
"description":"Authorization",
"required":true,
"type":"string"
}
],
"responses":{
"200":{
"description":"OK",
"schema":{
"type":"array",
"items":{
"$ref":"#/definitions/User"
}
}
}
}
},
"post":{
"tags":[
"user-rest-controller"
],
"summary":"添加新的用户",
"operationId":"addUsingPOST_5",
"consumes":[
"application/json"
],
"produces":[
"*/*"
],
"parameters":[
{
"in":"body",
"name":"user",
"description":"user",
"required":true,
"schema":{
"$ref":"#/definitions/User"
}
},
{
"name":"Authorization",
"in":"header",
"description":"Authorization",
"required":true,
"type":"string"
}
],
"responses":{
"200":{
"description":"OK",
"schema":{
"type":"object"
}
}
}
}
},
"/user/group":{
"get":{
"tags":[
"user-group-rest-controller"
],
"summary":"获取用户组列表",
"operationId":"listUsingGET_4",
"consumes":[
"application/json"
],
"produces":[
"*/*"
],
"parameters":[
{
"name":"Authorization",
"in":"header",
"description":"Authorization",
"required":true,
"type":"string"
}
],
"responses":{
"200":{
"description":"OK",
"schema":{
"type":"array",
"items":{
"$ref":"#/definitions/Group"
}
}
}
}
},
"post":{
"tags":[
"user-group-rest-controller"
],
"summary":"添加新的用户组",
"operationId":"addUsingPOST_4",
"consumes":[
"application/json"
],
"produces":[
"*/*"
],
"parameters":[
{
"in":"body",
"name":"group",
"description":"group",
"required":true,
"schema":{
"$ref":"#/definitions/Group"
}
},
{
"name":"Authorization",
"in":"header",
"description":"Authorization",
"required":true,
"type":"string"
}
],
"responses":{
"200":{
"description":"OK",
"schema":{
"$ref":"#/definitions/Group"
}
}
}
}
},
"/user/group/{id}":{
"get":{
"tags":[
"user-group-rest-controller"
],
"summary":"获取指定的用户组",
"operationId":"getUsingGET_4",
"consumes":[
"application/json"
],
"produces":[
"*/*"
],
"parameters":[
{
"name":"id",
"in":"path",
"description":"id",
"required":true,
"type":"integer",
"format":"int64"
},
{
"name":"Authorization",
"in":"header",
"description":"Authorization",
"required":true,
"type":"string"
}
],
"responses":{
"200":{
"description":"OK",
"schema":{
"$ref":"#/definitions/Group"
}
}
}
},
"put":{
"tags":[
"user-group-rest-controller"
],
"summary":"更新指定的用户组信息",
"operationId":"updateUsingPUT_3",
"consumes":[
"application/json"
],
"produces":[
"*/*"
],
"parameters":[
{
"in":"body",
"name":"group",
"description":"group",
"required":true,
"schema":{
"$ref":"#/definitions/Group"
}
},
{
"name":"Authorization",
"in":"header",
"description":"Authorization",
"required":true,
"type":"string"
}
],
"responses":{
"200":{
"description":"OK",
"schema":{
"$ref":"#/definitions/Group"
}
}
}
},
"delete":{
"tags":[
"user-group-rest-controller"
],
"summary":"删除指定的用户组",
"operationId":"deleteUsingDELETE_4",
"consumes":[
"application/json"
],
"produces":[
"*/*"
],
"parameters":[
{
"name":"id",
"in":"path",
"description":"id",
"required":true,
"type":"integer",
"format":"int64"
},
{
"name":"Authorization",
"in":"header",
"description":"Authorization",
"required":true,
"type":"string"
}
],
"responses":{
"200":{
"description":"OK",
"schema":{
"type":"object"
}
}
}
}
},
"/user/{id}":{
"get":{
"tags":[
"user-rest-controller"
],
"summary":"获取指定用户的信息",
"operationId":"getUsingGET_5",
"consumes":[
"application/json"
],
"produces":[
"*/*"
],
"parameters":[
{
"name":"id",
"in":"path",
"description":"id",
"required":true,
"type":"string"
},
{
"name":"Authorization",
"in":"header",
"description":"Authorization",
"required":true,
"type":"string"
}
],
"responses":{
"200":{
"description":"OK",
"schema":{
"$ref":"#/definitions/User"
}
}
}
},
"put":{
"tags":[
"user-rest-controller"
],
"summary":"更新指定的用户",
"operationId":"updateUsingPUT_4",
"consumes":[
"application/json"
],
"produces":[
"*/*"
],
"parameters":[
{
"name":"id",
"in":"path",
"description":"id",
"required":true,
"type":"string"
},
{
"in":"body",
"name":"user",
"description":"user",
"required":true,
"schema":{
"$ref":"#/definitions/User"
}
},
{
"name":"Authorization",
"in":"header",
"description":"Authorization",
"required":true,
"type":"string"
}
],
"responses":{
"200":{
"description":"OK",
"schema":{
"type":"object"
}
}
}
},
"delete":{
"tags":[
"user-rest-controller"
],
"summary":"删除指定的用户",
"operationId":"deleteUsingDELETE_5",
"consumes":[
"application/json"
],
"produces":[
"*/*"
],
"parameters":[
{
"name":"id",
"in":"path",
"description":"id",
"required":true,
"type":"string"
},
{
"name":"Authorization",
"in":"header",
"description":"Authorization",
"required":true,
"type":"string"
}
],
"responses":{
"200":{
"description":"OK",
"schema":{
"type":"object"
}
}
}
}
}
},
"definitions":{
"Role":{
"type":"object",
"required":[
"name"
],
"properties":{
"id":{
"type":"integer",
"format":"int64"
},
"name":{
"type":"string",
"description":"角色名称",
"enum":[
"ROLE_ADMIN",
"ROLE_USER"
]
}
}
},
"Group":{
"type":"object",
"required":[
"name"
],
"properties":{
"id":{
"type":"integer",
"format":"int64"
},
"name":{
"type":"string",
"description":"用户组名称"
}
}
},
"User":{
"type":"object",
"required":[
"password",
"username"
],
"properties":{
"createdAt":{
"type":"string",
"format":"date-time"
},
"description":{
"type":"string"
},
"displayName":{
"type":"string"
},
"email":{
"type":"string"
},
"groups":{
"type":"array",
"items":{
"$ref":"#/definitions/Group"
}
},
"id":{
"type":"string",
"description":"用户ID"
},
"password":{
"type":"string",
"description":"用户登录密码"
},
"roles":{
"type":"array",
"items":{
"$ref":"#/definitions/Role"
}
},
"updatedAt":{
"type":"string",
"format":"date-time"
},
"username":{
"type":"string",
"description":"用户登录名"
}
}
},
"Device":{
"type":"object",
"required":[
"endpoint",
"model",
"name",
"type",
"vendor",
"version"
],
"properties":{
"credentials":{
"type":"array",
"items":{
"$ref":"#/definitions/Credentials"
}
},
"endpoint":{
"type":"string",
"description":"设备目录"
},
"groups":{
"type":"array",
"items":{
"$ref":"#/definitions/Group"
}
},
"id":{
"type":"string"
},
"model":{
"type":"string",
"description":"设备型号"
},
"name":{
"type":"string",
"description":"设备名称"
},
"type":{
"type":"string",
"description":"设备类型",
"enum":[
"FIREWALL",
"ROUTER"
]
},
"vendor":{
"type":"string",
"description":"设备厂商"
},
"version":{
"type":"string",
"description":"设备版本"
}
}
},
"Credentials":{
"type":"object",
"required":[
"name",
"type"
],
"properties":{
"id":{
"type":"string"
},
"name":{
"type":"string",
"description":"凭据名"
},
"password":{
"type":"string"
},
"type":{
"type":"string",
"description":"凭据类型",
"enum":[
"PASSWORD"
]
},
"username":{
"type":"string"
}
}
}
}
}
I can see the headers in chrome web dev tools, but swagger-ui just didn't show it out!!
Which headers specifically?
@webron
web tools show
Access-Control-Allow-Credentials:true
Access-Control-Allow-Origin:http://localhost:3000
Authorization:Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiI5NGJhZjRhYS05MjgyLTQxZTctODE1Zi0zYjgwOTBiYWM3MzYiLCJhdWQiOiJ3ZWIiLCJpc3MiOiJza3ktY2xvdWQubmV0IiwiZXhwIjoxNDk5MzQyMjkwLCJpYXQiOjE0OTkzMDYyOTAxNTd9.mbtvWdFEXO2AeQx5UVS-l7agT8GMfrFrh5e-BUYGkWbUlzMoxh-ORIiJHMTkjajd7EB9-yt3_K8WIGPD47gAXA
Cache-Control:no-cache, no-store, max-age=0, must-revalidate
Content-Type:application/json;charset=UTF-8
Date:Thu, 06 Jul 2017 01:58:10 GMT
Expires:0
Pragma:no-cache
Transfer-Encoding:chunked
Vary:Origin
X-Application-Context:application:dev:8081
X-Content-Type-Options:nosniff
X-Frame-Options:DENY
X-Session-Id:df479cb5-c254-47f0-aad0-14e56349b04b
X-XSS-Protection:1; mode=block
swagger show
cache-control: no-cache, no-store, max-age=0, must-revalidate
content-type: application/json;charset=UTF-8
expires: 0
pragma: no-cache
For me, the Authorization and X-Session-Id headers are what i want.
It seems this is working as intended. Swagger UI is displaying all of the headers that are returned to it.
The headers that JS is allowed to access are determined by the response type, as can be read here: https://developers.google.com/web/updates/2015/03/introduction-to-fetch#response_types
If Swagger is running on the same origin as the API, you'll be able to access all of the returned headers, see screenshot where I access an endpoint running on the same origin as my Swagger UI instance:

In order to see the headers you want to see (Authorization and X-Session-Id), you'll want to have your API server return the Access-Control-Expose-Headers header (https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS#Access-Control-Expose-Headers) with the list of headers you want accessible.
Most helpful comment
It seems this is working as intended. Swagger UI is displaying all of the headers that are returned to it.
The headers that JS is allowed to access are determined by the response type, as can be read here: https://developers.google.com/web/updates/2015/03/introduction-to-fetch#response_types
If Swagger is running on the same origin as the API, you'll be able to access all of the returned headers, see screenshot where I access an endpoint running on the same origin as my Swagger UI instance:
In order to see the headers you want to see (Authorization and X-Session-Id), you'll want to have your API server return the Access-Control-Expose-Headers header (https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS#Access-Control-Expose-Headers) with the list of headers you want accessible.