swagger-api / swagger-api/swagger-codegen

Swagger codegen for jax-rs 2.0 using mustache template doesn't work properly.

Open
#11,298 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

We are using JAX-RS 2.0 which doesn't support PATCH, so we wrote a Custom PATCH which allows the generation but unable to support merge and patch json seperately.

Swagger-codegen version

gradle-swagger-generator-plugin-2.18.1-SNAPSHOT

Swagger declaration file content or url

'/{{classname}}/{id}':
patch:
operationId: merge{{classname}}
summary: Update a {{classname}}
description:
tags:
- Resource/{{classname}}
parameters:
- required: true
name: id
schema:
type: string
in: path
description:
- $ref: '#/components/parameters/fields'
- $ref: '#/components/parameters/depth'
- $ref: '#/components/parameters/expand'
requestBody:
description: .
required: true
content:
application/merge-patch+json:
schema:
$ref: '#/components/schemas/LogicalDeviceAccount'
application/json-patch+json:
schema:
$ref: '#/components/schemas/PatchRequest'
responses:
'200':
description:
content:
application/json:
schema:
$ref: '#'

Mustache template:

Generated code:
@PATCH
@Path("/{id}")
@Consumes({ "application/merge-patch+json", "application/json-patch+json" })
@Produces({ "application/json" })
...................

Suggest a fix/enhancement

As per our requirement we need to have two different consumers, as mentioned below.
@PATCH
@Path("/{id}")
@Consumes({ "application/json-patch+json" })
@Produces({ "application/json" })
@io.swagger.annotations.ApiOperation("")
@io.swagger.annotations.ApiResponses(value = { < 200...500 > })
public Response mergeMethod(@ApiParam(value = "The logical device to be updated." ,required=true) List body, @PathParam("id") String id, @QueryParam("fields") String fields, @Min(0) @Max(10) @QueryParam("depth") Integer depth, @QueryParam("expand") String expand,@Context SecurityContext securityContext)
/throws NotFoundException/ {
return service.<method(parameters)>;
}

@PATCH
@Path("/{id}")
@Consumes({ "application/merge-patch+json" })
@Produces({ "application/json" })
@io.swagger.annotations.ApiOperation"")
@io.swagger.annotations.ApiResponses(value = {< 200..500 > })
public Response mergeMethod(@ApiParam(value = "The logical device to be updated." ,required=true) LogicalDeviceType body, @PathParam("id") String id,  @QueryParam("fields") String fields, @Min(0) @Max(10)  @QueryParam("depth") Integer depth,  @QueryParam("expand") String expand,@Context SecurityContext securityContext)
/*throws NotFoundException*/ {
    return service. return service.<method(parameters)>;

Please help us on this as we are unable to generate the PATCH - httpmethod for both consumers using mustache seperately.

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

The issue names no source file or test; start by reproducing the JAX-RS 2.0 generation with the supplied OpenAPI declaration and Mustache template. Compare the generated PATCH methods with the requested output, and consider the work done when merge-patch and json-patch media types produce separate consumers and request signatures.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.