mlabouardy / swaggymnia

Generate Swagger 🌀 documentation for your existing API in Insomnia
MIT License
426 stars 31 forks source link

Failed to Load Spec #3

Closed Saieph closed 6 years ago

Saieph commented 6 years ago

I followed the steps from your tutorial at https://hackernoon.com/generate-beautiful-swagger-api-documentation-from-insomnia-ffaa2b77828e , and I'm using swagger-ui-3.4.4, and the MacOS version of swaggymnia.

I export my Insomnia export to a *.json file, then create a config.json, then run the command line:

swaggymnia generate -i Insomnia_All.json -c config.json -o yaml

...and that generates the swagger.yaml. I drop that into my swagger dist directory, then update the index.html to use my generated yaml like so:

const ui = SwaggerUIBundle({ // url: "http://petstore.swagger.io/v2/swagger.json", url: "swagger.yaml",

In this case, I'm simply commenting out the demo, and adding a line for my swagger.yaml.

HOWEVER, when I launch index.html (and I've tried a couple of different browsers), I always receive the following: screen shot 2017-11-21 at 10 20 19 am

And the error itself is: {"schemaValidationMessages":[{"level":"error","message":"Can't read from file swagger.yaml"}]}

While the url being displayed (in Chrome for this example) is: screen shot 2017-11-21 at 10 22 33 am

mlabouardy commented 6 years ago

try to past the content of generated file into https://editor.swagger.io//#/ and see if it works

Saieph commented 6 years ago

Looks like I'm getting the same error, and I think it's a parse error in the conversion

screen shot 2017-11-25 at 8 58 28 am

That particular line looks like this in the generated file:


description: "successful operation"
  :
    put:
Saieph commented 6 years ago

If I correct that one, I also wind up getting duplicated mapping key errors when I have more than one GET that looks similar to a different call.

mlabouardy commented 6 years ago

@Saieph yeah, at this moment, the tool doesnt support duplicate entities :)

Saieph commented 6 years ago

I thought as much, so I removed the duplicates. Maybe it's me just not understanding something about the way either the Tool, Insomnia, or swagger work, but I'm getting different errors now:

screen shot 2017-11-26 at 11 15 31 am

It looks (to me) like I'm not allowed to use anything other than a host and a path. I know that the string variables in my environment weren't working previously in tool/swagger. But also, query strings aren't allowed? I'm not sure what I'm doing wrong...

rogeriopradoj commented 6 years ago

@Saieph do you mind sharing your files with us?

While you do that, I'll try to guess what happened, because I had similar problems.

Firstly, your "host" in config file probably has slash ("/") on it, it's not ok for swagger spec. So you should move any subfolder path to "bastPath", and let "host" with only host part!

Second, your urls in insomnia besides .json exported workspace probably are repeating entrypoint (host + basepath) in all of resources. It works in insomnia, but is not god for swagger spec again. You should have been using Environment variables at insomnia, at least "base_url" I guess, which you be the same as host + basepath. After that you should change every request to, instead of using hardcoded host and basepath, use only the environment variable you created before.

Example of one environment variable definition in insomnia:

{ "base_url": "http://example.com/complete-path-before-resource-name" }

If you need more information on environment variables for insomnia: https://support.insomnia.rest/article/18-environment-variables

Best, and let us know if you get it done, right?

[]

mlabouardy commented 6 years ago

@Saieph as @rogeriopradoj mentioned the problem is related to swagger specs format not the tool itself :)