Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE]: Go validator tags support #2665

Open
timsofteng opened this issue Nov 25, 2024 · 0 comments
Open

[FEATURE]: Go validator tags support #2665

timsofteng opened this issue Nov 25, 2024 · 0 comments

Comments

@timsofteng
Copy link

timsofteng commented Nov 25, 2024

It would be great if quicktype produce validate tags for go structures.

Input Format: JSONSchema
Output Language: go

Description

Unfortunately in go there are no way add validation tags to json without external library. The most popular library currently is validator from google (https://github.com/go-playground/validator). It will give an abillity to validate json data in go applications.

Current Behaviour / Output

This json schema

{
  "id": "http://json-schema.org/geo",
  "$schema": "http://json-schema.org/draft-06/schema#",
  "description": "A geographical coordinate",
  "type": "object",
  "properties": {
    "latitude": {
      "type": "number",
      "minLength": 5
    },
    "ll": {
      "type": "number",
      "minLength": 5
    },
    "longitude": {
      "type": "number"
    }
  }
}

will be generated into this go struct

type Coordinate struct {
	Latitude  *float64 `json:"latitude,omitempty"`
	Ll        *float64 `json:"ll,omitempty"`
	Longitude *float64 `json:"longitude,omitempty"`
}

Proposed Behaviour / Output

This json schema

{
  "id": "http://json-schema.org/geo",
  "$schema": "http://json-schema.org/draft-06/schema#",
  "description": "A geographical coordinate",
  "type": "object",
  "properties": {
    "latitude": {
      "type": "number",
      "minLength": 5
    },
    "ll": {
      "type": "number",
      "minLength": 5
    },
    "longitude": {
      "type": "number"
    }
  }
}

will be generated into this go struct

type Coordinate struct {
	Latitude  *float64 `json:"latitude,omitempty" validate:"min=5"`
	Ll        *float64 `json:"ll,omitempty", validate:"min=5"`
	Longitude *float64 `json:"longitude,omitempty"`
}

Solution

Alternatives

Context

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant