-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(bundle/definition): add custom validator for contentEncoding
- Loading branch information
Showing
4 changed files
with
64 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package definition | ||
|
||
import ( | ||
"github.com/qri-io/jsonschema" | ||
) | ||
|
||
// ContentEncoding represents a "custom" Schema property | ||
type ContentEncoding string | ||
|
||
// NewContentEncoding allocates a new ContentEncoding validator | ||
func NewContentEncoding() jsonschema.Validator { | ||
return new(ContentEncoding) | ||
} | ||
|
||
// Validate implements the Validator interface for ContentEncoding | ||
// Currently, this is a no-op and is only used to register with the jsonschema library | ||
// that 'contentEncoding' is a valid property (as of writing, it isn't one of the defaults) | ||
func (c ContentEncoding) Validate(propPath string, data interface{}, errs *[]jsonschema.ValError) {} | ||
|
||
// NewRootSchema returns a jsonschema.RootSchema with any needed custom | ||
// jsonschema.Validators pre-registered | ||
func NewRootSchema() *jsonschema.RootSchema { | ||
// Register custom validators here | ||
// Note: as of writing, jsonschema doesn't have a stock validator for intances of type `contentEncoding` | ||
// There may be others missing in the library that exist in http://json-schema.org/draft-07/schema# | ||
// and thus, we'd need to create/register them here (if not included upstream) | ||
jsonschema.RegisterValidator("contentEncoding", NewContentEncoding) | ||
return new(jsonschema.RootSchema) | ||
} |