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

schema.Type should be string or []string #151

Open
chancez opened this issue Sep 3, 2024 · 1 comment
Open

schema.Type should be string or []string #151

chancez opened this issue Sep 3, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@chancez
Copy link

chancez commented Sep 3, 2024

Types are not only singular, but can be an array of valid types: https://json-schema.org/understanding-json-schema/reference/type

The schema.Type field currently only supports a single type currently, but should also support an array of types if many are provided.

I'd be open to implementing this myself, but wanted feedback before opening a PR.

  1. Since this would be a breaking change, should I do it as a new field/struct tag?
  2. How should it be implemented? I could add a new type:
type SchemaType struct {
  Type string
  Types []string
}

Or the existing value could be changed from string to []string, and in the singular case, it would just be a list with a single element. When rendering to JSON it could render it conditionally to a single string or a list, based on how many entries there are.

@samlown
Copy link
Contributor

samlown commented Oct 7, 2024

This is a really tricky one to implement in a strictly typed language like Go. A possible solution as you suggest would be to create a new type like type Type []string and provide a set of methods around it for serialization to and from a single string or array, depending on the number of entries...

@samlown samlown added the enhancement New feature or request label Oct 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants