lazada / swgen Goto Github PK
View Code? Open in Web Editor NEWSwagger Generator
License: Apache License 2.0
Swagger Generator
License: Apache License 2.0
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": {}
}
}
}
}
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{})
Definitions are mapped by type name disregarding type package.
This leads to wrong schema.
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
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'"
},
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.