E96 / swagger2slate

Convert swagger api documentation (http://swagger.io) to slate static html page (https://github.com/tripit/slate)
93 stars 25 forks source link

Can't generate index.md when "paramaters" field exists #8

Open magdiel01 opened 8 years ago

magdiel01 commented 8 years ago

"swagger2slate.phar/vendor/twig/twig/lib/Twig/Extension/Core.php on line 927"

nix-swagger2slate-docs_ _-bash_ _88x76 { "swagger": "2.0", "info": { "title": "My First API", "version": "0.1" }, "paths": { "/api/resource.json": { "get": { "parameters": [ { "name": "body", "description": "Measure value object that needs to be added.", "required": true, "type": "array", "items": {}, "paramType": "body" } ], "responses": { "200": { "description": "An example resource" } } } } }, "definitions": {} }

saikrishnaradarapu commented 8 years ago

Hi, How are using this project?? Can you elaborate me, because I am new to php.

saikrishnaradarapu commented 8 years ago

$ ./swagger2slate.phar convert ../swagger.json -o source/index.md

giving me the following

PHP Warning: file_get_contents(../swagger.json): failed to open stream: No such file or directory in phar:///home/Desktop/swagger2slate.phar/index.php on line 15 swagger version must be 2.0

MikeRalphson commented 8 years ago

@magdiel01 your Swagger definition fails validation, maybe that's it? Try

{
"swagger": "2.0",
"info": {
"title": "My First API",
"version": "0.1"
},
"paths": {
"/api/resource.json": {
"get": {
"parameters": [
{
"name": "body",
"description": "Measure value object that needs to be added.",
"required": true,
"schema": {
  "type": "array",
  "items": {}
},
"in": "body"
}
],
"responses": {
"200": {
"description": "An example resource"
}
}
}
}
},
"definitions": {}
}

Another (maintained) solution for converting Swagger (OpenAPI) to Slate is https://github.com/mermade/widdershins

magdiel01 commented 8 years ago

@MikeRalphson It fails because when I pasted the text into this thread it loses the indentation, thanks for the recommended solution.

MikeRalphson commented 8 years ago

@magdiel01 no problem. It isn't just the indentation though (that's optional for JSON / Swagger) - I've changed

"name": "body",
"description": "Measure value object that needs to be added.",
"required": true,
"type": "array",
"items": {},
"paramType": "body"

to

"name": "body",
"description": "Measure value object that needs to be added.",
"required": true,
"schema": {
  "type": "array",
  "items": {}
},
"in": "body"

You can check a Swagger definition is a valid at http://bigstickcarpet.com/swagger-parser/www/index.html