1
votes

I'm starting out with Swagger for my REST APIs. The primary goal is to generate server files for Nancy endpoints from Swagger definition. I downloaded the sources and modified the generated files for Nancy to my needs using api.moustache file.

Everything works fine but for one thing: some of the endpoints are protected, while some are not. In docu for swagger format I found that one can provide authentication information per endpoint. Now I want to access this info and if authentication is needed generate in my Nancy module RequireAuthentication()-line.

I located the moustache file and the java file for Nancy generator, but I cannot figure out where and how can I access the authentication info from swagger definition?

1
Per endpoint the information is on authMethods, this API client template in perl works as an example github.com/swagger-api/swagger-codegen/blob/… plus here you can find a way to see all the tags that can be used on the template for both the operations and models in the language you are generating github.com/swagger-api/swagger-codegen/wiki/… it's really useful when you don't know where the information is - moondaisy

1 Answers

0
votes

After more searching and exploring, I found out the way to edit moustache.api:

{{#operations}}{{#operation}}

{{#hasAuthMethods}}this.RequireAuthentication();{{/hasAuthMethods}}

{{/operation}}{{/operations}}