Skip to content

Add support for custom tags #461

@mfelipe

Description

@mfelipe

Would be nice to have the possibility to add other struct tags automatically from the schema, besides json, yaml and mapstructure.

For example, with https://github.com/brianvoe/gofakeit, we can generate random data for testing.

Here I'm picking $comment as the source of this metadata, but it's just an idea:

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "id": "https://example.com/case",
  "type": "object",
  "properties": {
    "url": {
      "type": "string",
      "$comment": "$go-jsonschema-tag:fake:\"{url}\"",
      "$comment": "Just a regular comment to be ignored..."
    },
    "id": {
      "type": "string",
      "$comment": "$go-jsonschema-tag:fake:\"{number:1,10}\""
    },
    "html": {
      "type": "string",
      "$comment": "$go-jsonschema-tag:fake:\"skip\""
    }
  }
}

It would generate something like this:

type Tags struct {
	// Html corresponds to the JSON schema field "html".
	Html *string `yaml:"html,omitempty" fake:"skip"`

	// Id corresponds to the JSON schema field "id".
	Id *string `yaml:"id,omitempty" fake:"{number:1,10}"`

	// Url corresponds to the JSON schema field "url".
	Url *string `yaml:"url,omitempty" fake:"{url}"`
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions