swagger-api / swagger-api/swagger-codegen
[Java] Generating response object
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
This is probably an error on my part, but I cannot seem to find any documentation on this.
If I generate a swagger.yaml file from a method that returns a javax.ws.rs.core.Response object it doesn't generate the response object in my swagger, but if I use a concrete class such as VersionInfo it does with a schema ref (see examples below). Most of the examples on the web, like pet store, return a Response object so what am I missing?
For example:
@Path("/v1")
@Api(value = "v1")
public class ApiGwTestRestController {
@GET
@Path ("/versionInfo")
@ApiOperation(value="Retuns the Version of the API GW Test Suite")
@Consumes (MediaType.APPLICATION_JSON)
@Produces (MediaType.APPLICATION_JSON)
public Response getApiGwTestSuiteVersion(){
return Response.ok()
.entity(new VersionInfo())
.type(MediaType.APPLICATION_JSON).build();
Generates:
swagger: "2.0"
info:
description: "API Gateway Regression Suite"
version: "1.0"
title: "API GW Test Suite"
host: "localhost:8080"
basePath: "/apiGwTestSuite"
tags:
- name: "v1"
schemes: - "http"
paths:
/v1/versionInfo:
get:
tags:
- "v1"
summary: "Retuns the Version of the API GW Test Suite"
description: ""
operationId: "getApiGwTestSuiteVersion"
consumes:
- "application/json"
produces:
- "application/json"
parameters: []
responses:
default:
description: "successful operation"
Now if I use the code below it does generate a response object:
@GET
@Path ("/versionInfo")
@ApiOperation(value="Retuns the Version of the API GW Test Suite")
@Consumes (MediaType.APPLICATION_JSON)
@Produces (MediaType.APPLICATION_JSON)
//public Response getApiGwTestSuiteVersion(){
public VersionInfo getApiGwTestSuiteVersion(){
return new VersionInfo();
Generates with a VersionInfo definition.
swagger: "2.0"
info:
description: "API Gateway Regression Suite"
version: "1.0"
title: "API GW Test Suite"
host: "localhost:8080"
basePath: "/apiGwTestSuite"
tags:
- name: "v1"
schemes: - "http"
paths:
/v1/versionInfo:
get:
tags:
- "v1"
summary: "Retuns the Version of the API GW Test Suite"
description: ""
operationId: "getApiGwTestSuiteVersion"
consumes:
- "application/json"
produces:
- "application/json"
parameters: []
responses:
200:
description: "successful operation"
schema:
$ref: "#/definitions/VersionInfo"
definitions:
VersionInfo:
type: "object"
properties:
name:
type: "string"
version:
type: "number"
format: "double"
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing how a Java method returning javax.ws.rs.core.Response is represented during Swagger generation, then compare that path with the VersionInfo return case shown in the issue. Done means the generated Swagger output documents the successful response and its response schema when the endpoint returns Response.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi
- Domain
- api
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100