skrusty / dotswaggen

DotSwagGen is a command line code generator for the swagger specification written in C#
MIT License
14 stars 5 forks source link

Compatibility with Swagger 2.0 #2

Closed luisrudge closed 9 years ago

luisrudge commented 9 years ago

I'm not sure this is compatible with 2.0. I'm having this error:

C:\git\oss\dotswaggen\dotswaggen\bin\Debug (master)
? dotswaggen.exe -s doc.json -n test -o ./result
Could not find member 'swagger' on object of type 'ApiDeclaration'. Path 'swagger', line 2, position 15.
Could not find member 'swagger' on object of type 'ApiDeclaration'. Path 'swagger', line 2, position 15.
Newtonsoft.Json.JsonSerializationException: Could not find member 'swagger' on object of type 'ApiDeclaration'. Path 'swagger', line 2, position 15.
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
   at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
   at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
   at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)
   at dotswaggen.Program.LoadSwagger(String json) in c:\git\oss\dotswaggen\dotswaggen\Program.cs:line 105
   at dotswaggen.Program.LoadConverter(String json, Type type) in c:\git\oss\dotswaggen\dotswaggen\Program.cs:line 84
   at dotswaggen.Program.ProcessFile(String inputFile) in c:\git\oss\dotswaggen\dotswaggen\Program.cs:line 49

this is the json file:

{
    "swagger": "2.0",
    "info": {
        "version": "v1",
        "title": "WebApplication3"
    },
    "host": "localhost:63267",
    "schemes": ["http"],
    "paths": {
        "/api/Values": {
            "get": {
                "tags": ["Values"],
                "summary": "retorna valores",
                "operationId": "Values_Get",
                "consumes": [],
                "produces": ["application/json", "text/json", "application/xml", "text/xml"],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "array",
                            "items": {
                                "type": "string"
                            }
                        }
                    }
                },
                "deprecated": false
            },
            "post": {
                "tags": ["Values"],
                "operationId": "Values_Post",
                "consumes": ["application/json", "text/json", "application/xml", "text/xml", "application/x-www-form-urlencoded"],
                "produces": [],
                "parameters": [{
                    "name": "value",
                    "in": "body",
                    "required": true,
                    "schema": {
                        "type": "string"
                    }
                }],
                "responses": {
                    "204": {
                        "description": "No Content"
                    }
                },
                "deprecated": false
            }
        },
        "/api/Values/{id}": {
            "get": {
                "tags": ["Values"],
                "summary": "Retorna valor",
                "operationId": "Values_Get",
                "consumes": [],
                "produces": ["application/json", "text/json", "application/xml", "text/xml"],
                "parameters": [{
                    "name": "id",
                    "in": "path",
                    "description": "parametro",
                    "required": true,
                    "type": "integer",
                    "format": "int32"
                }],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "string"
                        }
                    }
                },
                "deprecated": false
            },
            "put": {
                "tags": ["Values"],
                "operationId": "Values_Put",
                "consumes": ["application/json", "text/json", "application/xml", "text/xml", "application/x-www-form-urlencoded"],
                "produces": [],
                "parameters": [{
                    "name": "id",
                    "in": "path",
                    "required": true,
                    "type": "integer",
                    "format": "int32"
                }, {
                    "name": "value",
                    "in": "body",
                    "required": true,
                    "schema": {
                        "type": "string"
                    }
                }],
                "responses": {
                    "204": {
                        "description": "No Content"
                    }
                },
                "deprecated": false
            },
            "delete": {
                "tags": ["Values"],
                "operationId": "Values_Delete",
                "consumes": [],
                "produces": [],
                "parameters": [{
                    "name": "id",
                    "in": "path",
                    "required": true,
                    "type": "integer",
                    "format": "int32"
                }],
                "responses": {
                    "204": {
                        "description": "No Content"
                    }
                },
                "deprecated": false
            }
        }
    },
    "definitions": {}
}
skrusty commented 9 years ago

Currently there's no support for swagger version 2. Right now, it's 1.2 only. I am currently adding support for other swagger version (re-factoring the code to detect the swagger spec version etc) and building support for 1.1 (as I need support for it).

Once that code is checked in, it should be easy to build in support for 2.0, if you fancy helping :]

luisrudge commented 9 years ago

Great. How are you generating the api docs?

skrusty commented 9 years ago

Right now, the swagger spec c# files are generated manually. With a little help from the swashbuckle project! Unless you have a better way, if so, i'd love to hear it.

For example: https://github.com/skrusty/dotswaggen/blob/master/dotswaggen/Swagger/SwaggerSpec.cs

luisrudge commented 9 years ago

You're manually generating the swagger json?

skrusty commented 9 years ago

No? We don't generate any swagger json. We convert swagger json into something else, like C# classes.

luisrudge commented 9 years ago

Yeah. I was asking about your use case, not this project's. Are you using swagger to document any of your apis?

skrusty commented 9 years ago

I'm using swagger to documents APIs using swashbuckle and using dotswaggen to generate c# libs against those APIs.

I also use dotswaggen to generate code for the Asterisk ARI API (which is why i am coding support for 1.1, as it still uses it).

luisrudge commented 9 years ago

Yeah. That was my question. I'm trying Swashbuckle as well. Thanks!