Monday, June 22, 2015

Swagger Definition is not getting added when Creating an API with Publisher APIs in WSO2 API Manager 1.8

When creating a API with Publisher APIs the swagger definition may not get added, actually this is a known issue in Api Manager 1.8 and this is being fixed in Api Manager 1.9 release with the added capabilities of Swagger 2.0.

So How can you get this fixed. Actually its not straight forward to fix this issue, We can follow a workaround instead. The workaround is, after creating the API with Publisher APIs, you can add the Swagger definition separately.  Please follow the following commands to achieve this.

First Lets Create the API

curl -k -X POST -b cookies https://localhost:9443/publisher/site/blocks/item-add/ajax/add.jag -d 'action=addAPI&name=MyNewAPI6&visibility=public&version=1.0&description=My New API created and published by curl&endpointType=secured&http_checked=&https_checked=https&wsdl=&tags=automated published&tier=Gold&thumbUrl=https://pbs.twimg.com/profile_images/493735622587064320/z7qZUG0E_bigger.png&context=/apicurl6&tiersCollection=Gold,Silver,Bronze,Unlimited&resourceCount=5&resourceMethod-0=GET&resourceMethodAuthType-0=Application,Application User&resourceMethodThrottlingTier-0=Unlimited&uriTemplate-0=/assignments&resourceMethod-1=OPTIONS&resourceMethodAuthType-1=None&resourceMethodThrottlingTier-1=Unlimited&uriTemplate-1=/assignments&resourceMethod-2=GET&resourceMethodAuthType-2=Application,Application User&resourceMethodThrottlingTier-2=Unlimited&uriTemplate-2=/journeys&resourceMethod-3=OPTIONS&resourceMethodAuthType-3=None&resourceMethodThrottlingTier-3=Unlimited&uriTemplate-3=/journeys&resourceMethod-4=GET&resourceMethodAuthType-4=Application,Application User&resourceMethodThrottlingTier-4=Unlimited&uriTemplate-4=/info&resourceMethod-5=OPTIONS&resourceMethodAuthType-5=None&resourceMethodThrottlingTier-5=Unlimited&uriTemplate-5=/info' -d 'endpoint_config={"production_endpoints":{"url":"https://internal-mysampleapi.com:9443","config":null}, "sandbox_endpoints": {"url":"https://internal-mysampleapi.com:9443/mock","config":null},"endpoint_type":"http"}'

Now Lets add the Swagger Definition


curl -F name="MyNewAPI6" -F version="1.0" -F provider="admin" -F action="manage" -F swagger='{"apiVersion":"1.0","swaggerVersion":"1.2","authorizations":{"oauth2":{"scopes":[],"type":"oauth2"}},"apis":[{"index":0,"file":{"apiVersion":"1.0","basePath":"http://10.100.5.112:8280/newapi2/1.0","swaggerVersion":"1.2","resourcePath":"/assignments","apis":[{"index":0,"path":"/assignments","operations":[{"nickname":"get_assignments","method":"GET","parameters":[{"dataType":"String","description":"AccessToken","name":"Authorization","allowMultiple":false,"required":true,"paramType":"header"},{"description":"RequestBody","name":"body","allowMultiple":false,"required":true,"type":"string","paramType":"body"}]},{"nickname":"options_assignments","method":"OPTIONS","parameters":[{"dataType":"String","description":"Access Token","name":"Authorization","allowMultiple":false,"required":true,"paramType":"header"},{"description":"RequestBody","name":"body","allowMultiple":false,"required":true,"type":"string","paramType":"body"}]}]}]},"description":"","path":"/assignments"},{"index":1,"file":{"apiVersion":"1.0","basePath":"http://10.100.5.112:8280/newapi2/1.0","swaggerVersion":"1.2","resourcePath":"/info","apis":[{"index":0,"path":"/info","operations":[{"nickname":"get_info","method":"GET","parameters":[{"dataType":"String","description":"AccessToken","name":"Authorization","allowMultiple":false,"required":true,"paramType":"header"},{"description":"Request Body","name":"body","allowMultiple":false,"required":true,"type":"string","paramType":"body"}]},{"nickname":"options_info","method":"OPTIONS","parameters":[{"dataType":"String","description":"AccessToken","name":"Authorization","allowMultiple":false,"required":true,"paramType":"header"},{"description":"Request Body","name":"body","allowMultiple":false,"required":true,"type":"string","paramType":"body"}]}]}]},"description":"","path":"/info"},{"index":2,"file":{"apiVersion":"1.0","basePath":"http://10.100.5.112:8280/newapi2/1.0","swaggerVersion":"1.2","resourcePath":"/journeys","apis":[{"index":0,"path":"/journeys","operations":[{"nickname":"get_journeys","method":"GET","parameters":[{"dataType":"String","description":"AccessToken","name":"Authorization","allowMultiple":false,"required":true,"paramType":"header"},{"description":"Request Body","name":"body","allowMultiple":false,"required":true,"type":"string","paramType":"body"}]},{"nickname":"options_journeys","method":"OPTIONS","parameters":[{"dataType":"String","description":"AccessToken","name":"Authorization","allowMultiple":false,"required":true,"paramType":"header"},{"description":"Request Body","name":"body","allowMultiple":false,"required":true,"type":"string","paramType":"body"}]}]}]},"description":"","path":"/journeys"}],"info":{"title":"MyNewAPI6","termsOfServiceUrl":"","description":"","license":"","contact":"","licenseUrl":""}}' -k -X POST -b cookies https://localhost:9443/publisher/site/blocks/item-design/ajax/add.jag

Here you will have to create the swagger definition manually and parse the object according to the above format, this will add the swagger definition successfully

Another workaround is to create the API with normal Api creation EP. You can follow this log to read about this.