How to use swagger for my own REST API's
please help me understand how do I use the swagger to document my own REST API's. I am completely clueless though I just read many things about swagger. I got swagger downloaded from github too. Thanks in advance and waiting for a quick response.
Do you have a swagger documentation of your API ready?
Hi, No, can you send me any document which I can refer to make the same
The pet store sample which swagger-ui automatically loads is such a document (http://petstore.swagger.wordnik.com/api/api-docs/). Do you have an existing API? If so, which language/framework do you use?
I have developed a REST web service using Data virtualization tool which I want to document using Swagger. Its a GET service with inputs as query string and a specified URL to hit the same. Response is XML and I am awared of that structure so how should I initiate making the swagger documentation of my API. Thanks
Please bare with me as I am completely new to this. Thanks
I don't follow. Do you have a working API? Which development language do you use?
Yes , I do have a working API and I am using a Data virtualization tool i.e built on java to make API.
I'm not familiar with the tool you're talking about. Can you give me a link to that tool so I can see what it's about? If it's built using Java, do you know if it's based on JAX-RS or some other REST framework?
Tool name is Denodo. and I have API's URL's ready, so how can I use the same??
I'm not really familiar with the tool, and I'm trying to see if you can use a library or if you'll need to manually document your API.
Do you have a sample REST endpoint code you can share?
Hi , actually code is being written in VQL(virtual query language) so as of now I cant find any way of using any library to generate API doc. But I have manually documented for one of the API, looks like this:
{
"swagger": "2.0",
"info": {
"description": "This is XYZ",
"version": "1.0.0",
"title": "Swagger DDSW",
"termsOfService": "http:\/\/helloreverb.com\/terms\/",
"contact": {
"name": "[email protected]"
},
"license": {
"name": "Apache 2.0",
"url": "http:\/\/www.apache.org\/licenses\/LICENSE-2.0.html"
}
},
"host": "arldatavd01.ecorp.cat.com:9090\/server",
"basePath": "\/ddsw",
"schemes": [
"http"
],
"paths": {
"\/ddsw_authenticate": {
"get": {
"tags": [
"ddsw_authenticate"
],
"summary": "Authenticate a Dealer",
"description": "Authorized cws id along witht a valid dealercode can be passed to authenticate it against a dealercode",
"operationId": "ddswAuthenticateDealer",
"produces": [
"application\/json",
"application\/xml"
],
"parameters": [
{
"in": "query",
"name": "cws_id",
"description": "Authorized cws id",
"required": true,
"type": "string"
},
{
"in": "query",
"name": "Dealer_code",
"description": "Valid Dealer code",
"required": true,
"type": "string"
}
],
"responses": {
"404": {
"description": "Unauthorized dealer"
},
"200": {
"description": "successful operation",
"schema": {
"$ref": "#\/definitions\/ddsw_authenticate"
}
}
}
}
}
},
"definitions": {
"ddsw_authenticate": {
"required": [
"cwsid",
"dealer_code"
],
"properties": {
"cwsid": {
"type": "String",
"xml": {
"name": "cwsid"
}
},
"dealer_code": {
"type": "string",
"xml": {
"name": "dealer_code"
}
}
},
"xml": {
"name": "User"
}
}
}
}
so please help me now how to proceed further, just wanted to get it tested for this particular API
In the index.html, create a javascript variable with the value of the spec. Something like,
var spec = { .... };
Then, add the spec to the SwaggerUi declaration:
window.swaggerUi = new SwaggerUi({
url: url,
spec: spec,
dom_id: "swagger-ui-container",
supportedSubmitMethods: ['get', 'post', 'put', 'delete'],
onComplete: function(swaggerApi, swaggerUi){
log("Loaded SwaggerUI");
if(typeof initOAuth == "function") {
/*
initOAuth({
clientId: "your-client-id",
realm: "your-realms",
appName: "your-app-name"
});
*/
}
$('pre code').each(function(i, e) {
hljs.highlightBlock(e)
});
},
onFailure: function(data) {
log("Unable to Load SwaggerUI");
},
docExpansion: "none",
sorter : "alpha"
});
Open the index.html in your browser and you should see your spec.
what should be the value of spec, considering swagger documentation that I wrote and mentioned in above comment
because for petstore sample app available on swagger UI demo is not carrying any spec value in index.html
The value should be exactly the spec you pasted.
The pet store sample uses a hosted/generated spec. The solution I gave you is just easier to test locally without hosting it.
okay, Got it. Thanks. will try and acknowledge
Hi, Its working.Thanks for that, but I am not able to get response though if I run that resposne generated URL from my browser, it works. Attaching the screenshot. Will it be a firewall issue?

Your application needs to have CORS support enabled for the UI to work.
how do I do that?
That depends on the tool you use. A 'regular' Java Web application would use a filter like the one in all the samples we have, but I don't know how your application is running. Another option is to use a proxy server that enables CORS support, I'm sure Google will offer various options there.