Swagger-ui: only few api operations are shows in swagger ui

Created on 16 Mar 2016  路  23Comments  路  Source: swagger-api/swagger-ui

while viewing api documentation via swagger ui, only few operations are seen, though controller classes are in the same package for a spring boot application,

Any thoughts why this behaviour

Most helpful comment

If you have multiple operations under the same controller that only separated by query parameters, you may encounter this issue, which is not supported by the current version of the spec. As @fehguy mentioned, without swagger definition itself, it'd be impossible to know for sure, but the first step would be to check that it represents what you have in your code.

All 23 comments

Please share the swagger definition. It's impossible to help without it

If you have multiple operations under the same controller that only separated by query parameters, you may encounter this issue, which is not supported by the current version of the spec. As @fehguy mentioned, without swagger definition itself, it'd be impossible to know for sure, but the first step would be to check that it represents what you have in your code.

screen shot 2016-03-16 at 8 08 04 am

Swagger definition

swaggerdef.txt

I don't see other api controllers that are in the same java package only few of them are picked by swagger ui which is puzzling, I must be doing something incorrect so need help

swagger-ui simply takes the swagger spec you get from your app and renders it. If some controllers are missing, it doesn't necessarily mean there's an issue with swagger-ui but can also be that the generated spec doesn't contain them.

Looking at the swagger spec, do you see those missing controllers? If not, then swagger-ui is not the problem. If you do see them, can you point us to such an operation so we can further investigate?

yes i see a simple Ping-Controller in the output json returned from /v2/api-docs, but do not see it in ui for some reason.

i narrowed it down to a controller that has this piece of code which causes rest of the controller to not load in swagger

@RequestMapping(value = "/commit/github/v3", method = POST,
            consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE)
    public ResponseEntity<String> createGitHubv3(@RequestBody JSONObject request) throws ParseException, HygieiaException {
        String response = commitService.createFromGitHubv3(request);
        return ResponseEntity
                .status(HttpStatus.CREATED)
                .body(response);
    }

It does not like org.json.simple.JSONObject for some reason

Regardless of this bug which shouldn't occur, it looks like there's an issue with Springfox (which I assume you're using to generate it).

It converts JSONObject to

            "schema": {
              "type": "object",
              "additionalProperties": {
                "type": "object"
              }
            }

Which I assume is not what you want. Sounds like it should be:

            "schema": {
              "type": "object",
              "additionalProperties": {
              }
            }

that's correct I am using springfox

Then you may want to check with them about this specific generation.

Is there a solution for multiple operations under the same controller that are only separated by query parameters problem? I have 4 operations get by pageable/sorted/pageable-and-sorted etc.. Exmple :

@RequestMapping(params = { QueryConstants.PAGE, QueryConstants.SIZE }, method = RequestMethod.GET) @Secured(Privileges.CAN_USER_READ) @ApiOperation("find all - Paginated") public List<Resource> findAllPaginated(@RequestParam(value = QueryConstants.PAGE) final int page, @RequestParam(value = QueryConstants.SIZE) final int size, final UriComponentsBuilder uriBuilder, final HttpServletResponse response,Principal principal) { }

Right now swagger2 only generates documentation for one operation (usually randomly chosen).

@brankoiliccc it is not supported by the current version of the spec, so no.

@brankoiliccc I have created a workaround for your issue, where I add a hash fragment to the path of endpoints that contain query parameters (or headers) in the @RequestMapping. I then modified swagger-ui.js to remove this hash fragment. It's not very elegant, but it works.

@amitmawkin what was the cause an th solution at the end? I have the same issue

swagger generates UI elements in the alphabetical order. if there is one issue in the controller all other controller after that won't be displayed.
Ex: i forgot to all @RequestParam annotation to one method in the controller

(@RequestParam(defaultValue = "false") Boolean includeAsset, Boolean includeNested)

Then rest of the controllers are stopped displaying

Any solution yet for multiple operations on the same controller that are separated by query parameters?

@ittaiyam it's not supported by the current version version of the spec, and will not be supported in the upcoming one either.

I would like the feature added where endpoints separated by query parameters show separately as well.

Closing as it doesn't seem to be an issue anymore in 3.X.

This is still an issue in 2.9.2

I have multiple GET methods on the same path that take different params but only one method shows in swagger ui, but is there in the api docs

@Yasgur99 FYI, we're no longer working on or supporting the 2.x series of the UI.

@shockey, is there a 3.x version i can take advantage of?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ilnurshax picture ilnurshax  路  3Comments

ankon picture ankon  路  4Comments

songtianyi picture songtianyi  路  3Comments

MartinMuzatko picture MartinMuzatko  路  4Comments

sgyang picture sgyang  路  4Comments