API2swagger is not generating request and response schema automatically for backend API which is not exposed via apigee

@Anil Sagar Hi,

We have backend api which uses POST method and has request and response json payloads.

When we tried to generate Open API for this API through api2swagger tool, it is not generating schema for request and response payloads ( similar to how it does in the example provided @ https://community.apigee.com/articles/15397/api2swagger-open-api-swagger-20-spec-generator-fro.html

Could you please let us know how to generate request & response json schemas for Open API using api2swagger tool.

Thanks,SE

Solved Solved
0 6 493
1 ACCEPTED SOLUTION

I got it fixed. removed single quotations and appended with \ for quotations and removed the spaces. Though below url says that data should be surrounded by single quotes, api2swagger is reading the single quote as is and throwing JSON parse error. Also, we need to use \ for escaping double quotes.

If there are spaces, then api2swagger is not able to read the complete payload. need to sure there are no spaces in the json string.

View solution in original post

6 REPLIES 6

@soujanyaedunuri ,

Any error you see ? Can you please more details about same ?

It does not throw any error. It created swagger json. But json does not contain schema information. Backend API uses POST method and takes 3 fields in the json format. Both request & response are in json format.

Does api2swagger works only for GET method?

@Anil Sagar Now, I tried providing header and data information while executing apiswagger command as below and getting indexOf error as below.

api2swagger -e "<<apiurl>>" -o C:/profile.json -X POST -H "Authorization:Bearer 123" -d "{"name":test}"

*****

? A verbose explanation of the operation behavior. ? API Method Description

? A short summary of what the operation does. ? Short Summary of API Method

? Additional external documentation for this operation. ? http://docs.example.com/management/apis/get/entities

? Unique string used to identify the operation. ? uniqueId

? A list of tags for API documentation control. ? api2swagger

Making an API Call & fetching more details...Please stay tuned.. Api2swagger needs details related to Header : Authorization

? Name of Header Param ? Authorization

? Description of URL Param ? token field

? Type of query param ? string

Please provide more details regarding request payload..

readline.js:1016 throw err;

TypeError: Cannot read property 'indexOf' of undefined at getBodyInfo (C:\Users\xyz\AppData\Roaming\npm\node_modules\api2swagger\lib\execute\api.js:409:42) at bodyInfo (C:\Users\xyz\AppData\Roaming\npm\node_modules\api2swagger\lib\execute\api.js:145:11) at C:\Users\xyz\AppData\Roaming\npm\node_modules\api2swagger\node_modules\async\lib\async.js:718:13 at iterate (C:\Users\xyz\AppData\Roaming\npm\node_modules\api2swagger\node_modules\async\lib\async.js:262:13) at C:\Users\xyz\AppData\Roaming\npm\node_modules\api2swagger\node_modules\async\lib\async.js:274:29 at C:\Users\xyz\AppData\Roaming\npm\node_modules\api2swagger\node_modules\async\lib\async.js:44:16 at C:\Users\xyz\AppData\Roaming\npm\node_modules\api2swagger\node_modules\async\lib\async.js:723:17 at C:\Users\xyz\AppData\Roaming\npm\node_modules\api2swagger\node_modules\async\lib\async.js:167:37 at done (C:\Users\xyz\AppData\Roaming\npm\node_modules\api2swagger\lib\execute\api.js:379:7) at C:\Users\xyz\AppData\Roaming\npm\node_modules\api2swagger\node_modules\async\lib\async.js:52:16

I tried providing data with in single quotes and escaping the double quote characters as i ran the command in the windows machine.

api2swagger -e "<<apiurl>>" -o C:/profile.json -X POST -H "Authorization:Bearer 123" -d '{/"name/":/"test/"}'.

Followed the notes @ https://www.npmjs.com/package/api2swagger

I got it fixed. removed single quotations and appended with \ for quotations and removed the spaces. Though below url says that data should be surrounded by single quotes, api2swagger is reading the single quote as is and throwing JSON parse error. Also, we need to use \ for escaping double quotes.

If there are spaces, then api2swagger is not able to read the complete payload. need to sure there are no spaces in the json string.

Nice, Thank you for posting same. +1