Wednesday, October 2, 2013

How to add additional headers to WSO2 API Manager Swagger Console

WSO2 API Manager has integrated Swagger to allow API consumers to explore APIs through a interactive console.

When integrating Swagger with WSO2 API Manager we had to support CORS between API Store and the API Gateway. So in order to send any headers from Swagger, we need to add those required headers to the response coming from the API Gateway as 'Access-Control-Allow-Headers' . By default below set of headers are allowed to be send from swagger.


So if you need to add any additional headers to Swagger UI, then we should add that header to list of 'Access-Control-Allow-Headers'.

There are 2 options to modify 'Access-Control-Allow-Headers'.

1. Modify the Synapse configuration of APIs and add modified set of headers to OutSequence.

If you choose this method, you have to modify API configuration of each API and add the 'Access-Control-Allow-Headers'. For that go to Management Console of API Manager and then Go to Source View. Then modify the OutSequence with Access-Control-Allow-Headers property setting required headers as the value.

For example let's say the additional header wee need to add is 'Action', then outSequence should be modified as below.

2. Modify API templates.

Inside API Manager distribution you can find templates for APIs from APIM_HOME/repository/resources/api_templates. By modifying outSequences of below template files in there, all the APIs created thereafter will get the modified outSequence.



Once you have followed one of the above approaches, then you will be able to send those headers through swagger UI. So only thing left to do is adding the header parameter to API definition. For that go to API Publisher and select required API. Go to 'Docs' tab and click 'Edit Content' for API definition.

Then add required header parameter to available parameter list of the required operation/s.


                            "name": "Action",
                            "description": "SoapAction",
                            "paramType": "header",
                            "required": false,
                            "allowMultiple": false,
                            "dataType": "String"

Once you saved this, you will be able to see the added header parameter in the Swagger UI.