Created
March 26, 2025 16:00
-
-
Save jdesrosiers/634c754a9c0490885b91d1f873875067 to your computer and use it in GitHub Desktop.
Amazon Selling Parterner JSON Schema Dialect
This file contains hidden or 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
import { readFile } from "node:fs/promises"; | |
import { registerSchema } from "@hyperjump/json-schema/draft-2019-09"; | |
import { addKeyword, defineVocabulary } from "@hyperjump/json-schema/experimental"; | |
import * as Browser from "@hyperjump/browser"; | |
const baseUri = "https://schemas.amazon.com/selling-partners/definitions/product-types"; | |
addKeyword({ | |
id: `${baseUri}/keyword/maxUniqueItems`, | |
compile: async (schema) => Browser.value(schema), | |
interpret: (maxUniqueItems, instance) => { | |
return false; | |
} | |
}); | |
const vocabularyUri = `${baseUri}/vocabulary/v1`; | |
defineVocabulary(vocabularyUri, { | |
"maxUniqueItems": `${baseUri}/keyword/maxUniqueItems` | |
}); | |
const metaSchemaJson = await readFile("./meta-schema-v1.schema.json", "utf8"); | |
const metaSchema = JSON.parse(metaSchemaJson); | |
registerSchema(metaSchema); | |
const vocabularySchemaJson = await readFile("./vocabulary-v1.schema.json", "utf8"); | |
const vocabularySchema = JSON.parse(vocabularySchemaJson); | |
registerSchema(vocabularySchema); | |
export * from "@hyperjump/json-schema/draft-2019-09"; |
This file contains hidden or 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
import { validate } from "./amazon-sp-dialect.js"; | |
import { BASIC } from "@hyperjump/json-schema/experimental"; | |
const instance = [1, 2, 2, 3, 3, 3]; | |
const output = await validate("./example.schema.json", instance, BASIC); | |
console.log(output); | |
// Expected output | |
// { | |
// valid: false, | |
// errors: [ | |
// { | |
// keyword: 'https://schemas.amazon.com/selling-partners/definitions/product-types/keyword/maxUniqueItems', | |
// absoluteKeywordLocation: 'file:///home/jdesrosiers/Projects/amazon-seller-central-api/example.schema.json#/maxUniqueItems', | |
// instanceLocation: '#', | |
// valid: false | |
// } | |
// ] | |
// } |
This file contains hidden or 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
{ | |
"$schema": "https://schemas.amazon.com/selling-partners/definitions/product-types/meta-schema/v1", | |
"type": "array", | |
"items": { "type": "number" }, | |
"maxUniqueItems": 2 | |
} |
This file contains hidden or 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
{ | |
"$schema": "https://json-schema.org/draft/2019-09/schema", | |
"$id": "https://schemas.amazon.com/selling-partners/definitions/product-types/meta-schema/v1", | |
"$vocabulary": { | |
"https://json-schema.org/draft/2019-09/vocab/core": true, | |
"https://json-schema.org/draft/2019-09/vocab/applicator": true, | |
"https://json-schema.org/draft/2019-09/vocab/validation": true, | |
"https://json-schema.org/draft/2019-09/vocab/meta-data": true, | |
"https://json-schema.org/draft/2019-09/vocab/format": false, | |
"https://json-schema.org/draft/2019-09/vocab/content": true, | |
"https://schemas.amazon.com/selling-partners/definitions/product-types/vocabulary/v1": true | |
}, | |
"$recursiveAnchor": true, | |
"allOf": [ | |
{ "$ref": "https://json-schema.org/draft/2019-09/schema" }, | |
{ "$ref": "../vocabulary/v1" } | |
] | |
} |
This file contains hidden or 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
{ | |
"$schema": "https://json-schema.org/draft/2019-09/schema", | |
"$id": "https://schemas.amazon.com/selling-partners/definitions/product-types/vocabulary/v1", | |
"$recursiveAnchor": true, | |
"properties": { | |
"maxUniqueItems": { "type": "integer" } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment