GithubHelp home page GithubHelp logo

gin-jsonschema's People

Contributors

fabulousduck avatar hepri avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

gin-jsonschema's Issues

Does it support regex pattern

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

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.