Code Monkey home page Code Monkey logo

swgen's People

Contributors

ngdinhtoan avatar toanatlzd avatar vearutop avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

swgen's Issues

`required` constraint in definitions should be an array

Swagger specifies boolean required property for parameters, but other objects fallback to standard json schema, which treats required as an array of required properties names.

Invalid:

{
    "definitions": {
        "MyType": {
            "properties": {
                "one": {
                    "required": true
                }
            }
        }
    }
}

Valid:

{
    "definitions": {
        "MyType": {
            "required": [
                "one"
            ],
            "properties": {
                "one": {}
            }
        }
    }
}

Infinite recursion with custom type mapping

If type mapped structure is nested in another structure, infinite recursion happens with

runtime: goroutine stack exceeds 1000000000-byte limit
fatal error: stack overflow

runtime stack:
runtime.throw(0x137c04d, 0xe)
        /usr/local/Cellar/go/1.9/libexec/src/runtime/panic.go:605 +0x95
runtime.newstack(0x0)
        /usr/local/Cellar/go/1.9/libexec/src/runtime/stack.go:1050 +0x73b
runtime.morestack()
        /usr/local/Cellar/go/1.9/libexec/src/runtime/asm_amd64.s:415 +0x86

goroutine 9 [running]:
github.com/lazada/swgen.(*Generator).ParseDefinition(0xc4601ff000, 0x1308de0, 0x13b74a0, 0xc4200a6ce8, 0x1, 0x0, 0x0, 0x0, 0x0, 0x1379c89, ...)
        /Users/vpoturaev/golang/src/github.com/lazada/swgen/parser.go:108 +0x1d13 fp=0xc440201338 sp=0xc440201330 pc=0x12b88b3
github.com/lazada/swgen.(*Generator).ParseDefinition(0xc4601ff000, 0x1334780, 0xc4200e88c0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
        /Users/vpoturaev/golang/src/github.com/lazada/swgen/parser.go:138 +0x1c45 fp=0xc440202c38 sp=0xc440201338 pc=0x12b87e5
github.com/lazada/swgen.(*Generator).parseDefInQueue(0xc4601ff000)
        /Users/vpoturaev/golang/src/github.com/lazada/swgen/parser.go:350 +0xf8 fp=0xc440202d78 sp=0xc440202c38 pc=0x12ba358
github.com/lazada/swgen.(*Generator).ParseDefinition(0xc4601ff000, 0x131f060, 0xc42007d320, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1379c89, ...)
        /Users/vpoturaev/golang/src/github.com/lazada/swgen/parser.go:206 +0xd02 fp=0xc440204678 sp=0xc440202d78 pc=0x12b78a2
github.com/lazada/swgen.(*Generator).ParseDefinition(0xc4601ff000, 0x1350700, 0xc42001be30, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
        /Users/vpoturaev/golang/src/github.com/lazada/swgen/parser.go:138 +0x1c45 fp=0xc440205f78 sp=0xc440204678 pc=0x12b87e5

Sample:

type typeMapHolder struct {
	M typeMap `json:"m"`
}

type typeMap struct {
	R1 int `json:"1"`
	R2 int `json:"2"`
	R3 int `json:"3"`
	R4 int `json:"4"`
	R5 int `json:"5"`
}
gen.AddTypeMap(typeMap{}, map[string]int{})

CORS Support

The HTTP Handler func (g *Generator) ServeHTTP(w http.ResponseWriter, r *http.Request) should support CORS.

E.g:

$ curl -I "http://petstore.swagger.io/v2/swagger.json"
HTTP/1.1 200 OK
Date: Sat, 31 Jan 2015 23:05:44 GMT
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET, POST, DELETE, PUT, PATCH, OPTIONS
Access-Control-Allow-Headers: Content-Type, api_key, Authorization
Content-Type: application/json
Content-Length: 0

Omit empty `host`

Empty string as host value does not pass pattern validation.

    "host": {
      "type": "string",
      "pattern": "^[^{}/ :\\\\]+(?::\\d+)?$",
      "description": "The host (name or ip) of the API. Example: 'swagger.io'"
    },

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.