hepri / gin-jsonschema Goto Github PK
View Code? Open in Web Editor NEWGin jsonschema validation
License: MIT License
Gin jsonschema validation
License: MIT License
I am trying to use a json schema that has a regular experssion as below.
var MySchema string = `
{
"title": "My Schema",
"type": "object",
"properties" : {
"btValue": {
"type": "string",
"pattern": "(?:(0)|(1)|(2))(?(1)([1379]))(?(2)(5|10))(?(3)([02468]))"
}
}
}
`
When I make a json request having a body like below...
{
"btValue": "11"
}
it fails with an error like below, finally leading to http 500.
Cannot build schema from string
{
"title": "MySchema",
"type": "object",
"properties" : {
"btValue": {
"type": "string",
"pattern": "(?:(0)|(1)|(2))(?(1)([1379]))(?(2)(5|10))(?(3)([02468]))"
}
}
}
It works fine, when I remove the "pattern" from the json schema. Am I missing something here..?
Here is the full stack trace for the failure..
2022/07/08 19:19:14 [Recovery] 2022/07/08 - 19:19:14 panic recovered:
POST /api/v1/app/colors1/_bit HTTP/1.1
Host: localhost:8081
Accept: */*
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Content-Length: 23
Content-Type: application/json
Postman-Token: 27006c7f-0a7f-48c1-ab45-f869208b6fd6
User-Agent: PostmanRuntime/7.29.0
Cannot build schema from string
{
"title": "MySchema",
"type": "object",
"properties" : {
"btValue": {
"type": "string",
"pattern": "(?:(0)|(1)|(2))(?(1)([1379]))(?(2)(5|10))(?(3)([02468]))"
}
}
}
/Users/rvnath/go/pkg/mod/github.com/hepri/[email protected]/wrapper.go:81 (0x14ba107)
Validate: panic(fmt.Sprintf("Cannot build schema from string %v", schemaStr))
/Users/rvnath/projects/rogue/rogue-wa/cmd/app/users.go:69 (0x1659c17)
placeBit: schema.Validate(func (c *gin.Context) {
/Users/rvnath/go/pkg/mod/github.com/gin-gonic/[email protected]/context.go:168 (0x147a2a1)
(*Context).Next: c.handlers[c.index](c)
/Users/rvnath/go/pkg/mod/github.com/gin-gonic/[email protected]/recovery.go:99 (0x147a28c)
CustomRecoveryWithWriter.func1: c.Next()
/Users/rvnath/go/pkg/mod/github.com/gin-gonic/[email protected]/context.go:168 (0x14793c6)
(*Context).Next: c.handlers[c.index](c)
/Users/rvnath/go/pkg/mod/github.com/gin-gonic/[email protected]/logger.go:241 (0x14793a9)
LoggerWithConfig.func1: c.Next()
/Users/rvnath/go/pkg/mod/github.com/gin-gonic/[email protected]/context.go:168 (0x1478490)
(*Context).Next: c.handlers[c.index](c)
/Users/rvnath/go/pkg/mod/github.com/gin-gonic/[email protected]/gin.go:555 (0x14780f8)
(*Engine).handleHTTPRequest: c.Next()
/Users/rvnath/go/pkg/mod/github.com/gin-gonic/[email protected]/gin.go:511 (0x1477c31)
(*Engine).ServeHTTP: engine.handleHTTPRequest(c)
/usr/local/go/src/net/http/server.go:2916 (0x12bb09a)
serverHandler.ServeHTTP: handler.ServeHTTP(rw, req)
/usr/local/go/src/net/http/server.go:1966 (0x12b6096)
(*conn).serve: serverHandler{c.server}.ServeHTTP(w, w.req)
/usr/local/go/src/runtime/asm_amd64.s:1571 (0x1064340)
goexit: BYTE $0x90 // NOP
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.