common annotations for all requests

230 views
Skip to first unread message

Mortier Andries

unread,
Mar 26, 2015, 3:54:56 AM3/26/15
to swagger-sw...@googlegroups.com
hello, i have a quick question,
 
Is there a way to set some custom overall common annotations so i can specify
the returned error codes only once, or the set the header parameters only once?
 
so if they change i don't need to change all my rest documentation annotations
but i only change it  on one place?
 
tx
 

Ron Ratovsky

unread,
Mar 26, 2015, 4:03:56 AM3/26/15
to swagger-sw...@googlegroups.com
You left IRC too quickly for me to respond there.

Assuming you use the latest version of swagger-core, you should be able to create a custom annotation annotated with our annotations, and use that across your application.
Then you could change only that and it would affect the output wherever you use it.

--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
-----------------------------------------
http://swagger.io
https://twitter.com/SwaggerApi
-----------------------------------------

Mortier Andries

unread,
Mar 26, 2015, 4:18:22 AM3/26/15
to swagger-sw...@googlegroups.com
great ! thanks, would you have an example of such an annotation?
   i tought nobody was alive on the chat :) 
 

Ron Ratovsky

unread,
Mar 26, 2015, 4:22:27 AM3/26/15
to swagger-sw...@googlegroups.com
I don't have an example off hand, unfortunately.

--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Mortier Andries

unread,
Mar 26, 2015, 5:09:17 AM3/26/15
to swagger-sw...@googlegroups.com
Hello Ron,
 
I'm not that familiar with annotations so could you show me how to achieve this?
 
tx
 

Ron Ratovsky

unread,
Mar 26, 2015, 5:13:02 AM3/26/15
to swagger-sw...@googlegroups.com
Provide me with a sample code you're looking to replace and I'll do my best.

--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Mortier Andries

unread,
Mar 26, 2015, 6:29:24 AM3/26/15
to swagger-sw...@googlegroups.com


@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface SwaggerDefaults {
}

-------------------------------------------------

public class SwaggerDef {
   
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "a", value = "a", required = true, dataType = "string", paramType = "header", defaultValue = "aaaaa"),
            @ApiImplicitParam(name = "b", value = "b", required = true, dataType = "string", paramType = "header", defaultValue = "bbbbb"),
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "The request returned a valid response."),
            @ApiResponse(code = 4000, message = "Bad request"),
            @ApiResponse(code = 204, message = "No content or data found"),
            @ApiResponse(code = 400, message = "Bad request"),
            @ApiResponse(code = 500, message = "Internal server error")})
   
    @Inject
 @SwaggerDefaults
    public void defaults() {

    }

}

--------------------------------------------------

 @GET
    @LogPerformance
    @Produces (value = {MediaType.APPLICATION_JSON})
    @ApiOperation (value = "aaaa")
---->  @SwaggerDefaults
    @Path("/index/{aaa}")
    public Object myRestEndPoint() throws Throwable {
   ............
    }

Ron Ratovsky

unread,
Mar 26, 2015, 6:31:38 AM3/26/15
to swagger-sw...@googlegroups.com
Which version of swagger-core do you use?

--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Mortier Andries

unread,
Mar 26, 2015, 6:40:46 AM3/26/15
to swagger-sw...@googlegroups.com
well.. i'm just thingking. i'm exporting them to json with this plugin, ..  
so probably the annotation workaroud won't work..
 
<groupId>com.github.kongchen</groupId>
<artifactId>swagger-maven-plugin</artifactId>
 

Mortier Andries

unread,
Mar 26, 2015, 6:42:28 AM3/26/15
to swagger-sw...@googlegroups.com
<swagger-annotations.version>1.3.2</swagger-annotations.version>
<swagger.core.version>1.3.2</swagger.core.version>
<swagger.maven.plugin.version>2.3</swagger.maven.plugin.version>

Ron Ratovsky

unread,
Mar 26, 2015, 6:43:58 AM3/26/15
to swagger-sw...@googlegroups.com
I can't tell you whether the swagger-maven-plugin will be able to process these annotations - so you'd have to ask that in its github repository.

I can tell you the annotation inheritance will not work unless you use swagger-core 1.3.10 or above.


--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Mortier Andries

unread,
Mar 26, 2015, 6:47:34 AM3/26/15
to swagger-sw...@googlegroups.com
ok, well i can always upgrade the version
 

Ron Ratovsky

unread,
Mar 26, 2015, 6:49:39 AM3/26/15
to swagger-sw...@googlegroups.com
You can, but if you rely on the swagger-maven-plugin, I may not matter. That project is a community contribution and I'm not sure how it works.

On Thu, Mar 26, 2015 at 12:47 PM, Mortier Andries <mortier...@gmail.com> wrote:
ok, well i can always upgrade the version
 

--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Mortier Andries

unread,
Mar 26, 2015, 7:46:15 AM3/26/15
to swagger-sw...@googlegroups.com
so i would like to have something like this..  
then you annotate your @Get with this
@SwaggerDefaults(headers = true, responses = true)

@Qualifier
@Inherited
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD) //can use in method only.
public @interface SwaggerDefaults {

    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "a", value = "a", required = true, dataType = "string", paramType = "header", defaultValue = "a"),
            @ApiImplicitParam(name = "a", value = "a", required = true, dataType = "string", paramType = "header", defaultValue = "a"),
            @ApiImplicitParam(name = "a", value = "a", required = true, dataType = "string", paramType = "header", defaultValue = "a"),
    })
    boolean headers() default false;

    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "The request returned a valid response."),

            @ApiResponse(code = 204, message = "No content or data found"),
            @ApiResponse(code = 400, message = "Bad request"),
            @ApiResponse(code = 500, message = "Internal server error")})

    boolean responses() default false;

}

Ron Ratovsky

unread,
Mar 26, 2015, 9:04:19 AM3/26/15
to swagger-sw...@googlegroups.com
The previous answers stay the same. You didn't add any information here.

Keep in mind that Swagger 1.5.X allows for more elaborate and pluggable annotation processing, but again, it will not work with the swagger-maven-plugin.

--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Mortier Andries

unread,
Mar 26, 2015, 9:23:36 AM3/26/15
to swagger-sw...@googlegroups.com
Hey Ron,
 
ok i've posted an issue on their github; tx
Reply all
Reply to author
Forward
0 new messages