invopop / invopop/jsonschema

schema.Type should be string or []string

Open
#151 3 comments 3 reactions 0 assignees View on GitHub
enhancement
Dominant language
Go
Stars
952
Forks
136
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by locating the schema.Type field and the code that renders it to JSON. Review the JSON Schema type reference linked in the issue, then determine how singular and array-valued types should be represented without breaking existing users. Done means the chosen API supports both forms and renders a string or array as appropriate, with tests covering each case.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.