Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swagger Is not able to produce documentation for HTTP "PATCH"

I Have followed the below
blog entry: http://kingsfleet.blogspot.co.uk/2014/02/transparent-patch-support-in-jax-rs-20.html
https://github.com/jersey/jersey/tree/2.6/examples/http-patch
To create end point to support HTTP "PATCH" method in Jersey 2.6 Dependency Versions:

-Jersey: 2.6
-swagger-jersey2-jaxrs_2.10: 1.3.12

Question? Why Patch end point is not getting listed as part of the swagger ui documentation?

Analysis:

If I am annotating with this annotation, then documentation for that end point getting generated, but no interaction .

@com.wordnik.swagger.jaxrs.PATCH

Configurations

JerssyApplicationInitializer

packages(true, "com.test.account.endpoint", "com.wordnik.swagger.jaxrs.json");
        //Swagger Configuration
        register(new ApiListingResourceJSON(), 10);
        register(JerseyApiDeclarationProvider.class);
        register(JerseyResourceListingProvider.class);

        //Genson Converter
        register(GensonJsonConverter.class, 1);
        register(createMoxyJsonResolver());

I am not sure, if I am missing something, any help or guide will be helpful.

Patch method doscumets:

 public static final String PATCH_MEDIA_TYPE = "application/json-patch+json";
    @PATCH
        //@com.wordnik.swagger.jaxrs.PATCH
        @PreAuthorize(userAuthenticationRequire=true)
        @Consumes(PATCH_MEDIA_TYPE)
        @Path("{id: .\\d+}")
        @ApiOperation(value = "Update Client Details in UIM System."
                    , response = State.class
                    , notes="Requesting User, should be the owner of the Client."
                    , consumes = PATCH_MEDIA_TYPE)
        @ApiResponses({
            @ApiResponse(code = _401, message = "If the access token is invalid.", response = String.class),
            @ApiResponse(code = _498, message = "If the access token is expired.", response = String.class),
            @ApiResponse(code = _420, message = "If Provided Input is not valid according to requirment specification."),
            @ApiResponse(code = _404, message = "If no client/app Found."),
            @ApiResponse(code = _200, message = "If Client Account has been Updated successfully. ", response=String.class)
        })
        public State updateClientDetails(@ApiParam(value="Client Id to be Updated.", required=true) @PathParam(CLIENT_ID) String clientId
                , @ApiParam(value = "Updated field and Value.", required = true) final State newState){
            //LOG.info("[ENTRY]- Received requst for updating Client {} from System.", clientId);
            System.out.println("----->" + someBean.test());
            //LOG.info("[EXIT]- Client Id {} Updation has been completed.", clientId);
            Test t = new Test();
            t.name = "Hello Test";
            System.out.println(t.name);
            return newState;
        }
like image 448
Jayaram Avatar asked Feb 18 '15 14:02

Jayaram


People also ask

Which functionality of Swagger should be used to display in the documentation?

Swagger is a set of open-source tools built around the OpenAPI Specification that can help you design, build, document and consume REST APIs. The major Swagger tools include: Swagger Editor – browser-based editor where you can write OpenAPI specs. Swagger UI – renders OpenAPI specs as interactive API documentation.

How do I create a Swagger document?

Head over to Swagger Inspector, and insert the end point of the resource you want to have documented. You can then navigate to the right panel from the History section of Swagger Inspector, and click "Create API definition" to create the OAS definition.


1 Answers

Take a look at your index.html. That controls which HTTP operations are interactive--by changing it to this:

  window.swaggerUi = new SwaggerUi({
    url: url,
    dom_id: "swagger-ui-container",
    supportedSubmitMethods: ['get', 'post', 'put', 'delete', 'patch'],

You will have interaction on the PATCH method:

enter image description here

like image 176
fehguy Avatar answered Oct 25 '22 11:10

fehguy