apigee-127 / swagger-converter

Converts Swagger documents from version 1.2 to 2.0
MIT License
42 stars 24 forks source link

Need more information on 'Usage' section #11

Closed ndhar-1 closed 9 years ago

ndhar-1 commented 9 years ago

The part explaining the usage of Swagger Converter is not very informative. I had troubles figuring out both the installation ways mentioned. For npm, I wasn't sure where to put those javascript statements. Then I realized I need a node to implement that, which I dont have. For the other one, with browser.js, I am still not able to get the desired result. Maybe I am calling the method incorrectly: var convert = SwaggerConverter.convert; ...... I am including this call in index.html of Swagger UI.

prabhatjha commented 9 years ago

Swagger-converter is used in swagger-tools and you can see how to use it at https://github.com/apigee-127/swagger-tools/blob/master/docs/API.md#convertresourcelisting-apideclarations-skipvalidation-callback

ndhar-1 commented 9 years ago

Well this page should be referenced on the page for Swagger-Converter. I read the link you gave, it looks like all examples were for coding in Node.js. Is there an example on how to do it using browser.js ?

mohsen1 commented 9 years ago

You need to have all swagger files in plain-old JavaScript objects and pass the root swagger object as first arguments and an array of objects (which are your other swagger files) as second arguments. Please let me know what error you're getting when you're trying that

ndhar-1 commented 9 years ago

Oh ok. I have Swagger resource files in JSON (spec 1.2) as is required by the Swagger UI. I thought this utility will help generate JSON files which comply with Swagger 2.0 spec given the spec 1.2 JSON files. I think I am mistaken here. Is it ?

mohsen1 commented 9 years ago

First, parse the JSON strings to get the objects out.

Your resources files which you have as JSON should be passed as an array of objects and for the first argument send the main swagger file object.

For example if I want to convert petstore example I need to do the following

Download and parse file at list resources (root file) Define an array Download and parse all resources files and push it to that array pass root object as first argument and the array as second argument. You will get the v2.0 specs out

ylogx commented 9 years ago

Same problem. The description is really not informative at all. We need to do node browser.js to get the string btw. It will be really great if we can get a step by step usage information (which doesn't assume any technical knowledge).

mohsen1 commented 9 years ago

@shubhamchaudhary Your usage here at https://github.com/apigee-127/swagger-converter/issues/15 is correct.

whitlockjc commented 9 years ago

I was able to use swagger-converter in swagger-tools without any issue based on the README. It's a very simple API that is pretty well documented. (The example in the README is spot on and the API arguments are documented there too.) If you're wanting to have a CLI for converting Swagger 1.2 to Swagger 2.0, check out swagger-tools. Otherwise, I don't see how else to make the README any simpler in my opinion.

ndhar-1 commented 9 years ago

Thank for the explanation mohsen1. I understand it. But actually I am working in Java codebase and thought to implement it there. I don't have Node.js. When I saw the following code, I thought I could implement this in the index.html of the Swagger UI and get the UI working with spec 2.0:

Include the browser.js script in your HTML

Use the script

var convert = SwaggerConverter.convert;

mohsen1 commented 9 years ago

I've never used it in browser but there is nothing stopping it working in browser. What error are you getting?