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.

authorization,Access-Control-Allow-Origin,Content-Type

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.

api_templates_complex_resource.xml
api_templates_complex_resource_with_jwt.xml
api_templates_resource.xml
api_templates_resource_with_jwt.xml

<outSequence>
        <property name="Access-Control-Allow-Headers" scope="transport" value="authorization,Access-Control-Allow-Origin,Content-Type,Action"></property>
        <send></send>
</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.

ex:

                     {
                            "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.




Comments

  1. Please have a look at this question : http://stackoverflow.com/questions/22913463/wso2-api-manager-swagger-integration-model-schema

    ReplyDelete

Post a Comment

Popular posts from this blog

PHP-SOAP web service with out a WSDL

Boomi Mapping - Removing special chars from an input

How to add Maven dependency from a relative path referencing a local jar