pavel_kazlou
pavel_kazlou

Reputation: 2046

modify swagger api listing

I'm using Jersey 2 as JAX-RS implementation for my REST API.

Also I've successfully configured swagger to enable generation of API listing. I'm using static swagger-ui project to render the page with description.

My maven pom looks like this:

    <dependency>
            <groupId>org.glassfish.jersey.core</groupId>
            <artifactId>jersey-server</artifactId>
            <version>2.5.1</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.containers</groupId>
        <artifactId>jersey-container-servlet-core</artifactId>
        <version>2.5.1</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.ext</groupId>
        <artifactId>jersey-spring3</artifactId>
        <version>2.5.1</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.media</groupId>
        <artifactId>jersey-media-json-jackson</artifactId>
        <version>2.5.1</version>
    </dependency>
    <dependency>
        <groupId>com.wordnik</groupId>
        <artifactId>swagger-jersey2-jaxrs_2.10</artifactId>
        <version>1.3.2</version>
    </dependency>

However when describing some of my methods and parameters in java resources I found it too verbose to be mixed with code.

So I decided to use some external mechanism to supply descriptions. I can imagine some file, where I will enter the name of method and parameter with accompanying description. When generating resulting API listing JSON file, I want to merge information from my java resource files with the information from external file.

Based on googling and reading materials I can see that API listing is not stored in file, but rather generated on the fly. So I need to find the way to hack into the process of generating API listing to add my custom descriptions.

I tried using ContainerResponseFilter for this purpose and I can intercept response entity with generated API listing object, but this object is scala read-only object. So I can't override description property.

Is there any way I can modify my API listing with my custom info?

Upvotes: 2

Views: 506

Answers (2)

Giovanni Botta
Giovanni Botta

Reputation: 9816

I think using a filter is the best idea. You don't need to modify the Scala object, just create a new one from it with the new descriptions. Just look at the way Swagger creates the object and mimic that.

Upvotes: 1

Tom
Tom

Reputation: 3166

It's been a while since I looked at swagger but can you just create dedicated interface that contains your swagger markup and then implement that interface? It's not exactly what you're looking for but at least it would keep the verbosity out of your concrete classes.

Upvotes: 0

Related Questions