swagger-api / swagger-api/swagger-codegen

[Jaxrs-spec] Improvements for Jaxrs-spec

Open
#4,509 7 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Enhancement: General help wanted Server: Java
Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description
  • the api is generated as class, but IMHO this should be an interface!?
  • javax.ws.rs.core.Response is used instead of the real response data type
  • @ApiResponse uses wrong response type (the return type, not the response type of the contract)
  • src/gen/java is not added to the build path
  • "Attachment" is used for attachments, but no import is added for this (I think org.apache.cxf.jaxrs.ext.multipart.Attachment is referenced, but this is CXF-specific)
    (see also #4327)
Swagger-codegen version

2.2.2-SNAPSHOT

Related issues

#4327

Suggest a Fix
  • generate api as interface (which then can be easily implemented)

changed in api.mustache, added new apiServiceImpl.mustache for implementation class

  • use real response data types instead of javax.ws.rs.core.Response (x)

should be changed separately see #4713

  • fix * @ApiResponse data types

fixed in AbstractJavaJAXRSServerCodegen by adding a check for void for api-response:

// set vendorExtensions.x-java-is-response-void to true as dataType is set to "void"
						if ( resp.dataType == null ) {
							resp.vendorExtensions.put("x-java-is-response-void", true);
						}

and in api.mustache by adding the check for void and by using the baseType instead of returnType of @ApiReponse.

@ApiResponse(code = {{{code}}}, message = "{{{message}}}"{{^vendorExtensions.x-java-is-response-void}}, response = {{{baseType}}}.class{{/vendorExtensions.x-java-is-response-void}}
  • add src/gen/java to the buildpath
  • look for alternatives for JAXRS-compliant alternatives to org.apache.cxf.jaxrs.ext.multipart.Attachment or comment it out

as there is currently no standardized way for supporting multipart/form-data (see https://java.net/jira/browse/JAX_RS_SPEC-413), I changed formParams.mustache to

@FormParam(value = "{{paramName}}") InputStream {{paramName}}InputStream

This should be a sufficient standard hint, although it will have to be adapted for CXF/Jersey/Resteasy then.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Review api.mustache, apiServiceImpl.mustache, AbstractJavaJAXRSServerCodegen, and formParams.mustache, along with the listed generated-source build-path change. Regenerate JAX-RS output and verify the checklist: interfaces and implementations are separated, @ApiResponse uses the contract response type, generated sources build, and multipart parameters avoid an unimported CXF Attachment.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.