kongchen / swagger-maven-plugin

JAX-RS & SpringMVC supported maven build plugin, helps you generate Swagger JSON and API document in build phase.
http://kongchen.github.io/swagger-maven-plugin/
Apache License 2.0
759 stars 450 forks source link

@ApiParam doesn't recognized hidden attribute for spring mvc. #238

Closed ankurpshah closed 8 years ago

ankurpshah commented 8 years ago

Currently in our project we are using swagger-maven-plugin for generating swagger.json file. We are using spring mvc. We are using IncomingRequestFilter method parameter for accepting all the query parameters. I had documented all query parameters using @ApiImplicitParams. Now I want to ignore all method parameters generated swagger.json file. So I am annotating all the method parameter with @ApiParam(hidden = true). Currently generated swagger.json still shows all three method parameters with located in body.

e.g.

"parameters" : [ {
          "in" : "body",
          "name" : "body",
          "required" : false,
          "schema" : {
            "$ref" : "#/definitions/LisUser"
          }
        }, {
          "in" : "body",
          "name" : "body",
          "required" : false,
          "schema" : {
            "$ref" : "#/definitions/PageRequestBuilder"
          }
        }, {
          "in" : "body",
          "name" : "body",
          "required" : false,
          "schema" : {
            "$ref" : "#/definitions/IncomingRequestFilter"
          }
        }, {
          "name" : "page",
          "in" : "query",
          "description" : "Page number",
          "required" : false,
          "type" : "integer",
          "default" : "1",
          "enum" : [ "[1", "infinity]" ]
        }, {
          "name" : "size",
          "in" : "query",
          "description" : "Number of record per page",
          "required" : false,
          "type" : "integer",
          "default" : "50",
          "enum" : [ "[1", "200]" ]
        }, {
          "name" : "orderby",
          "in" : "query",
          "description" : "Sort column, (with hypen then descending otherwise ascending)",
          "required" : false,
          "type" : "string",
          "default" : "id"
        }, {
          "name" : "searchStr",
          "in" : "query",
          "description" : "Search String",
          "required" : false,
          "type" : "string"
        }, {
          "name" : "searchColumns",
          "in" : "query",
          "description" : "Search perform in these columns",
          "required" : false,
          "type" : "array",
          "items" : {
            "type" : "string"
          },
          "collectionFormat" : "csv"
        }, {
          "name" : "status",
          "in" : "query",
          "description" : "Request Status",
          "required" : false,
          "type" : "array",
          "items" : {
            "type" : "string",
            "enum" : [ "NEW", "PENDING", "COMPLETED", "FOLLOWUP", "FORWARDED", "REJECTED", "DELETED", "SPAM" ]
          },
          "collectionFormat" : "csv"
        }, {
          "name" : "claimStatuses",
          "in" : "query",
          "description" : "Claim Status",
          "required" : false,
          "type" : "array",
          "items" : {
            "type" : "string",
            "enum" : [ "CLAIMED", "UN_CLAIMED", "CLAIMED_BY_ME", "CLAIMED_BY_OTHERS" ]
          },
          "collectionFormat" : "csv"
        }, {
          "name" : "verifiedStatuses",
          "in" : "query",
          "description" : "User Status",
          "required" : false,
          "type" : "array",
          "items" : {
            "type" : "string",
            "enum" : [ "VERIFIED", "UNVERIFIED" ]
          },
          "collectionFormat" : "csv"
        }, {
          "name" : "priorities",
          "in" : "query",
          "description" : "Priorities",
          "required" : false,
          "type" : "array",
          "items" : {
            "type" : "string",
            "enum" : [ "EXIGENT", "URGENT", "HIGH", "NORMAL" ]
          },
          "collectionFormat" : "csv"
        }, {
          "name" : "channelNames",
          "in" : "query",
          "description" : "Channel Names",
          "required" : false,
          "type" : "array",
          "items" : {
            "type" : "string"
          },
          "collectionFormat" : "csv"
        }, {
          "name" : "tagNames",
          "in" : "query",
          "description" : "Tag Names",
          "required" : false,
          "type" : "array",
          "items" : {
            "type" : "string"
          },
          "collectionFormat" : "csv"
        }, {
          "name" : "timeZoneOffset",
          "in" : "query",
          "description" : "Time Zone Offset",
          "required" : false,
          "type" : "string"
        } ],

Original java file with Swagger Annotation is below.

@ApiOperation(value = "", httpMethod = "GET", produces = "application/json",
        consumes = "application/json", response = IncomingRequestListTO.class,
        responseContainer = "List",
        authorizations = {@Authorization(
            value = "MANAGE_COTS_REQUESTS", scopes = {@AuthorizationScope(
            scope = "list:incoming-request", description = "allows to list all incoming "
            + "request")})})
    @ApiResponses(value = {@ApiResponse(code = 400, message = "Invalid value supplied"),
        @ApiResponse(code = 404, message = "Incoming request not found"),
        @ApiResponse(code = 403, message = "Not authorized to retrieve incoming-request")})
    @ApiImplicitParams({@ApiImplicitParam(name = "page", value = "Page number", required = false,
        defaultValue = "1", allowableValues = "[1, infinity]", paramType = "query",
        dataType = "integer", allowMultiple = false),
        @ApiImplicitParam(name = "size", value = "Number of record per page", required = false,
            defaultValue = "50", allowableValues = "[1, 200]", paramType = "query",
            dataType = "integer", allowMultiple = false),
        @ApiImplicitParam(name = "orderby", value = "Sort column, (with hypen then "
            + "descending otherwise ascending)", required = false, defaultValue = "id",
            paramType = "query", dataType = "string", allowMultiple = false),
        @ApiImplicitParam(name = "searchStr", value = "Search String", required = false,
            defaultValue = "", paramType = "query", dataType = "string", allowMultiple = false),
        @ApiImplicitParam(name = "searchColumns", value = "Search perform in these columns",
            required = false, paramType = "query", dataType = "string", allowMultiple = true),
        @ApiImplicitParam(name = "status", value = "Request Status", required = false,
            allowableValues = "NEW, PENDING, COMPLETED, FOLLOWUP, FORWARDED, REJECTED, DELETED, "
                + "SPAM", paramType = "query", dataType = "string", allowMultiple = true),
        @ApiImplicitParam(name = "claimStatuses", value = "Claim Status", required = false,
            allowableValues = "CLAIMED, UN_CLAIMED, CLAIMED_BY_ME, CLAIMED_BY_OTHERS",
            paramType = "query", dataType = "string", allowMultiple = true),
        @ApiImplicitParam(name = "verifiedStatuses", value = "User Status", required = false,
            allowableValues = "VERIFIED, UNVERIFIED", paramType = "query", dataType = "string",
            allowMultiple = true),
        @ApiImplicitParam(name = "priorities", value = "Priorities", required = false,
            allowableValues = "EXIGENT, URGENT, HIGH, NORMAL", paramType = "query",
            dataType = "string", allowMultiple = true),
        @ApiImplicitParam(name = "channelNames", value = "Channel Names",
            required = false, paramType = "query", dataType = "string", allowMultiple = true),
        @ApiImplicitParam(name = "tagNames", value = "Tag Names",
            required = false, paramType = "query", dataType = "string", allowMultiple = true),
        @ApiImplicitParam(name = "timeZoneOffset", value = "Time Zone Offset",
            required = false, paramType = "query", dataType = "string", allowMultiple = false)})
    public ResponseEntity<Collection<IncomingRequestListTO>> getAll(
        @ApiParam(hidden = true) @CurrentUser LisUser lisUser,
        @ApiParam(hidden = true) PageRequestBuilder pageRequestBuilder,
        @ApiParam(hidden = true) IncomingRequestFilter incomingRequestFilter)
        throws URISyntaxException {
        IncomingRequestFilterBuilder filterBuilder = new IncomingRequestFilterBuilder(lisUser, incomingRequestFilter);
        Page<IncomingRequest> page = incomingRequestService.getAll(filterBuilder.build(), pageRequestBuilder.build());
        HttpHeaders headers = Pagination.generateHttpHeaders(page);
        final List<IncomingRequestListTO> results = incomingRequestListMapper.convertIncomingListToIncomingTOList(page.getContent());
        return new ResponseEntity<>(results, headers, HttpStatus.OK);
    }

So how can I hide method parameter from generated swagger.json and why current framework is ignoring hidden attribute of @ApiParam for spring mvc based project ? Please guide me. This is blocker in my project.

who commented 8 years ago

Hi @ankurpshah , which version of swagger-maven-plugin are you using? Support for @ApiParam#hidden was added in swagger-maven-plugin 3.1.1-SNAPSHOT.

ankurpshah commented 8 years ago

Currently we are using 3.1.0. Does 3.1.1-SNAPSHOT out ?

who commented 8 years ago

To use 3.1.1-SNAPSHOT, you'll have to add this to your pom.xml :

<pluginRepositories>
  <pluginRepository>
    <id>sonatype-snapshot</id>
    <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
    <releases>
      <enabled>false</enabled>
    </releases>
    <snapshots>
      <enabled>true</enabled>
    </snapshots>
  </pluginRepository>
</pluginRepositories>