Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

✅ Go package for validating JSON. It's the first Go package that can generate JSON Schema (OpeanAPI-compatible), produces user-friendly errors, and supports translations.

License

NotificationsYou must be signed in to change notification settings

orsinium-labs/valdo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

81 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

[📚 docs ] [🐙 github ]

Go package for validating JSON. Can generateJSON Schema (100% compatible withOpenAPI), produces user-friendly errors, supports translations.

You could write OpenAPI documentation by hand (which is very painful) and then use it to validate user input in your HTTP service, but then error messages are very confusing, not user-friendly, and only in English. Or you could write input validation by hand and then maintain the OpenAPI documentation separately but then the two will eventually drift and your documentation will be a lie. Valdo solves all these problems: write validation once using a real programming language, use it everywhere.

Features:

  • Mechanism to translate error messages.
  • Out-of-the-box translations for some languages.
  • Supports the latest JSON Schema specification (2020-12).
  • Pure Go.
  • No code generation, no reflection, no unsafe code.
  • User-friendly error messages.
  • Concurrency-safe, no global state.
  • Strict by default, without implicit type casting.
  • Type-safe, thanks to generics.

Installation

go get github.com/orsinium-labs/valdo

Usage

validator:=valdo.Object(valdo.Property("name",valdo.String(valdo.MinLen(1))),valdo.Property("admin",valdo.Bool()),)// validate JSONinput:= []byte(`{"name": "aragorn", "admin": true}`)err:=valdo.Validate(validator,raw)// validate and unmarshal JSONtypeUserstruct {Namestring`json:"name"`Adminbool`json:"admin"`}user,err:=valdo.Unmarshal[User](validator,input)// generate JSON Schemaschema:=valdo.Schema(validator)

Seedocumentation for more.

About

✅ Go package for validating JSON. It's the first Go package that can generate JSON Schema (OpeanAPI-compatible), produces user-friendly errors, and supports translations.

Topics

Resources

License

Stars

Watchers

Forks

Contributors2

  •  
  •  

Languages


[8]ページ先頭

©2009-2025 Movatter.jp