Search code examples
restgrailsswagger-2.0spring-security-restgrails3.2.0

Grails 3 - documenting spring security rest's login api in swagger


I am developing demo REST Demo using Grails 3 with service Spring Security REST and Swagger Documentation. Following are the dependencies for spring security rest

org.grails.plugins:spring-security-rest:2.0.0.M2

org.grails.plugins:spring-security-rest-gorm:2.0.0.M2

where user has to login in order to to perform certain subset of operations. After adding Swagger Doc using following plugin and configuring to access all the expoosed APIs I am able to access all API's swagger doc with "localhost://applicationPath/api"

org.grails.plugins:swaggydoc-grails3:0.28.0

Unfortunately I don't have login endpoints listed among them. If I add my LoginController along with the apis endpoints controller than it is listing all the login apis but than access url becomes

APPLICATIONURL/api/v1/api/login

Which does not works well.

The problem is that part of that operations cannot be performed via Swagger UI built-in form (I find it really nice feature and would like make it work), because user is not logged in. Is there any solution to that problem? Can I define manually some endpoints in Swagger?

This is my sample code for registring any API with Swagger

@Api(
        value = 'Sample',
        description = 'Sample APIs.',
        position = 0,
        produces = 'application/json',
        consumes = 'application/json',
        basePath = 'v1',
        protocols = 'http, https',
        hidden = false
)
@Controller()
class SampleController {
@ApiOperation(
            value = 'Sample API',
            notes = '',
            response = Sample,
            responseContainer = 'Array',
            position = 0,
            httpMethod = 'GET',
            produces = 'application/json',
            consumes = 'application/json',
            protocols = 'http, https',
            hidden = false
    )
    @ApiImplicitParams([
            @ApiImplicitParam(name = 'max', value = 'Max records to return', defaultValue = '10', paramType = 'query', dataType = 'int', required = false, allowMultiple = false)
    ])
    @ApiResponses([
            @ApiResponse(code = 200, message = "", response = Sample),
    ])
    def sampleAPI() {
    }
}

If Anybody can help on it, it would be great help.


Solution

  • I created an API which calls "api/login" to have authentication