


SWAGGER EDITOR AUTHORIZATION WITH CUSTOM HEADERS CODE
Exception: There was anĮrror during code generation when trying to add a client for the RESTĪPI Generating client code and adding to project failed Adding RESTĪPI client for failed post = new Operation 'post' operation of '/authenticate' path. OperationId is required for all operations.

I just want to add something to the accepted answer that when autorest is used for client generation, the accepted answer is not complete for it misses the some properties. These OperationFilters can do a whole lot and enable us to customize the swagger document created which is what drives the fields and info on the UI. What we have to do now is add an OperationFilter to our swagger generation. Of course in the Authoization field, you need to add: Running this gives us our basic swagger at /swagger: Adding Custom Headers. Public void Apply(Operation operation, SchemaRegistry schemaRegistry, ApiDescription apiDescription)Īnd in the SwaggerConfig class in the register method, add this action c.OperationFilter() Public class AddAuthorizationHeaderParameterOperationFilter : IOperationFilter / The class to add the authorization header. To add the authorization token in the request header: ("/token", new PathItemĪnd in the SwaggerConfig class in the register method, add this action c.DocumentFilter() Public void Apply(SwaggerDocument swaggerDoc, SchemaRegistry schemaRegistry, IApiExplorer apiExplorer) The solution is of 2 steps, first one is to request a token and the next step, is to add the token into the header request.Ĭustomize the frontend to enable post request for requesting a token:Īdd a AuthTokenOperation class to enable which inherits the IDcoumentFilter interface and implements the Apply method: public class AuthTokenOperation : IDocumentFilter I would like to share it in case anybody is facing the same problem.
