Skip to content

Commit 0033f9c

Browse files
authored
feat(json_schemas): Add $id property to JSON schemas (#544)
We have JSON schemas publicly available at `https://apify.com/schemas`: - [`https://apify.com/schemas/v1/actor.json`](https://apify.com/schemas/v1/actor.json) - [`https://apify.com/schemas/v1/input.json`](https://apify.com/schemas/v1/input.json) - [`https://apify.com/schemas/v1/dataset.json`](https://apify.com/schemas/v1/dataset.json) - [`https://apify.com/schemas/v1/key-value-store.json`](https://apify.com/schemas/v1/key-value-store.json) - [`https://apify.com/schemas/v1/output.json`](https://apify.com/schemas/v1/output.json) This sets the `$id` property to the respective URL. Also add optional `$schema` property to all schemas so the actual schema can link the validation schema (our JSON schema) to provide validation lints in IDE.
1 parent 17554e8 commit 0033f9c

File tree

7 files changed

+33
-14
lines changed

7 files changed

+33
-14
lines changed

packages/input_schema/src/input_schema.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,11 @@ const validateAgainstSchemaOrThrow = (validator: Ajv, obj: Record<string, unknow
114114
* We override schema.properties.properties not to validate field definitions.
115115
*/
116116
function validateBasicStructure(validator: Ajv, obj: Record<string, unknown>): asserts obj is InputSchemaBaseChecked {
117+
// We need to remove $id from the schema, because AJV cache the schema by id and if we provide
118+
// different schema instance with the same id, it will throw an error.
119+
const { $id, ...schemaWithoutId } = schema;
117120
const schemaWithoutProperties = {
118-
...schema,
121+
...schemaWithoutId,
119122
properties: { ...schema.properties, properties: { type: 'object' } as any },
120123
};
121124
validateAgainstSchemaOrThrow(validator, obj, schemaWithoutProperties, 'schema');

packages/json_schemas/schemas/actor.schema.json

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
{
2-
"$id": "actor.json",
2+
"$id": "https://apify.com/schemas/v1/actor.json",
33
"title": "JSON schema of Apify Actor actor.json file",
44
"type": "object",
55
"properties": {
6+
"$schema": {
7+
"type": "string"
8+
},
69
"actorSpecification": {
710
"type": "integer",
811
"minimum": 1,
@@ -77,7 +80,7 @@
7780
"type": "string"
7881
},
7982
{
80-
"$ref": "output.json"
83+
"$ref": "https://apify.com/schemas/v1/output.json"
8184
}
8285
]
8386
},
@@ -87,7 +90,7 @@
8790
"type": "string"
8891
},
8992
{
90-
"$ref": "output.json"
93+
"$ref": "https://apify.com/schemas/v1/output.json"
9194
}
9295
]
9396
},
@@ -100,7 +103,7 @@
100103
"type": "string"
101104
},
102105
{
103-
"$ref": "key_value_store.json"
106+
"$ref": "https://apify.com/schemas/v1/key-value-store.json"
104107
}
105108
]
106109
},
@@ -110,7 +113,7 @@
110113
"type": "string"
111114
},
112115
{
113-
"$ref": "dataset.json"
116+
"$ref": "https://apify.com/schemas/v1/dataset.json"
114117
}
115118
]
116119
},

packages/json_schemas/schemas/dataset.schema.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
{
2-
"$id": "dataset.json",
2+
"$id": "https://apify.com/schemas/v1/dataset.json",
33
"title": "JSON schema of Apify Actor dataset schema",
44
"type": "object",
55
"properties": {
6+
"$schema": {
7+
"type": "string"
8+
},
69
"actorSpecification": {
710
"type": "integer",
811
"minimum": 1,

packages/json_schemas/schemas/input.schema.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"$id": "https://apify.com/schemas/v1/input.json",
23
"title": "JSON schema of Apify Actor input",
34
"type": "object",
45
"properties": {

packages/json_schemas/schemas/key_value_store.schema.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
{
2-
"$id": "key_value_store.json",
2+
"$id": "https://apify.com/schemas/v1/key-value-store.json",
33
"title": "JSON schema of Apify Actor key-value store schema",
44
"type": "object",
55
"properties": {
6+
"$schema": {
7+
"type": "string"
8+
},
69
"actorKeyValueStoreSchemaVersion": {
710
"type": "integer",
811
"minimum": 1,

packages/json_schemas/schemas/output.schema.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
{
2-
"$id": "output.json",
2+
"$id": "https://apify.com/schemas/v1/output.json",
33
"title": "JSON schema of Apify Actor output schema",
44
"type": "object",
55
"properties": {
6+
"$schema": {
7+
"type": "string"
8+
},
69
"actorOutputSchemaVersion": {
710
"type": "integer",
811
"minimum": 1,

packages/json_schemas/src/actor.schema.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@ import { ACTOR_LIMITS } from '@apify/consts';
44
// The schemas/actor.schema.json file is generated from this file during the build step.
55

66
export const actorSchema = {
7-
$id: 'actor.json',
7+
$id: 'https://apify.com/schemas/v1/actor.json',
88
title: 'JSON schema of Apify Actor actor.json file',
99
type: 'object',
1010
properties: {
11+
$schema: {
12+
type: 'string',
13+
},
1114
actorSpecification: {
1215
type: 'integer',
1316
minimum: 1,
@@ -82,7 +85,7 @@ export const actorSchema = {
8285
type: 'string',
8386
},
8487
{
85-
$ref: 'output.json',
88+
$ref: 'https://apify.com/schemas/v1/output.json',
8689
},
8790
],
8891
},
@@ -92,7 +95,7 @@ export const actorSchema = {
9295
type: 'string',
9396
},
9497
{
95-
$ref: 'output.json',
98+
$ref: 'https://apify.com/schemas/v1/output.json',
9699
},
97100
],
98101
},
@@ -105,7 +108,7 @@ export const actorSchema = {
105108
type: 'string',
106109
},
107110
{
108-
$ref: 'key_value_store.json',
111+
$ref: 'https://apify.com/schemas/v1/key-value-store.json',
109112
},
110113
],
111114
},
@@ -115,7 +118,7 @@ export const actorSchema = {
115118
type: 'string',
116119
},
117120
{
118-
$ref: 'dataset.json',
121+
$ref: 'https://apify.com/schemas/v1/dataset.json',
119122
},
120123
],
121124
},

0 commit comments

Comments
 (0)