How can I use my own annotation for Swagger?
How can I use my own annotation to create swagger ui page. For example, I have defined an annotation and use it:
@PUT
@MyOwnAnnotationForAdditionalPropInSwagger(value = "Some text")
@Path( "/{carId}" )
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(
value = "Updates car info"
)
public Response patchItem(@ApiParam(value = "Fields to update") Car item) {
/*some code*/
}
After that, I should probably extend the class from swagger-core
and specify to scan my annotation ( @MyOwnAnnotationForAdditionalPropInSwagger
).
As a result, I want to see an extra column in the swagger ui with my text.
How can I figure this out? Which class do I need to extend?
source to share
Swagger 2.0 supports custom fields, a Pull Request was requested in 2013 ( https://github.com/swagger-api/swagger-node/pull/47 ).
Apparently it's easy to add custom fields, since they are not present in the Swagger 2.0 spec, Swagger-UI will not render them by default.
To do this, you have to change a couple of things.
- Add the required annotation to the parser implementation (i.e.
swagger-core
orswagger-php
) if it doesn't exist. - Clone and modify
swagger-ui
to render your custom field however you wish.
Note that doing so will actually break the jag jag schema ( https://github.com/swagger-api/swagger-spec/blob/master/schemas/v2.0/schema.json ) and any third party validators you can not be used.
source to share