Skip to content

Commit

Permalink
Adds level property to the ancestors schema definition
Browse files Browse the repository at this point in the history
  • Loading branch information
akolson committed Feb 1, 2024
1 parent b890010 commit b6c558b
Show file tree
Hide file tree
Showing 4 changed files with 171 additions and 61 deletions.
72 changes: 53 additions & 19 deletions js/EmbedTopicsRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,41 +10,75 @@ export const SCHEMA = {
"description": "Schema for embed topics requests received by RayServe",
"additionalProperties": false,
"definitions": {
"ancestors": {
"type": "array",
"description": "The ancestors of the topic, in order, from the parent to the root",
"items": {
"$ref": "#/definitions/topic",
"properties": {
"level": {
"type": "integer",
"description": "The level of the ancestor, where the parent is 1 and the root is the highest level"
}
},
"required": ["level"]
}
"id": {
"type": "string",
"description": "The ID of the topic content node on Studio"
},
"title": {
"type": "string",
"description": "The title of the topic"
},
"description": {
"type": "string",
"description": "The description of the topic"
},
"language": {
"type": "string",
"description": "Language code from https://github.com/learningequality/le-utils/blob/main/le_utils/resources/languagelookup.json",
"pattern": "^[a-z]{2,3}(?:-[a-zA-Z]+)?$"
},
"level": {
"type": "integer",
"description": "The level of the ancestor, where the parent is 1 and the root is the highest level"
},
"ancestor": {
"type": "object",
"description": "An ancestor in the tree structure",
"additionalProperties": false,
"properties": {
"id": {
"$ref": "#/definitions/id"
},
"title": {
"$ref": "#/definitions/title"
},
"description": {
"$ref": "#/definitions/description"
},
"language": {
"$ref": "#/definitions/language"
},
"level": {
"$ref": "#/definitions/level"
}
},
"required": [
"id",
"title",
"description",
"level"
]
},
"ancestors": {
"type": "array",
"description": "The ancestors of the topic, in order, from the parent to the root",
"items": {
"$ref": "#/definitions/ancestor"
}
},
"topic": {
"type": "object",
"description": "A topic in the tree structure",
"additionalProperties": false,
"properties": {
"id": {
"type": "string",
"description": "The ID of the topic content node on Studio"
"$ref": "#/definitions/id"
},
"title": {
"type": "string",
"description": "The title of the topic"
"$ref": "#/definitions/title"
},
"description": {
"type": "string",
"description": "The description of the topic"
"$ref": "#/definitions/description"
},
"language": {
"$ref": "#/definitions/language"
Expand Down
55 changes: 33 additions & 22 deletions le_utils/constants/embed_topics_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,39 +16,50 @@
"description": "Schema for embed topics requests received by RayServe",
"additionalProperties": False,
"definitions": {
"ancestors": {
"type": "array",
"description": "The ancestors of the topic, in order, from the parent to the root",
"items": {
"$ref": "#/definitions/topic",
"properties": {
"level": {
"type": "integer",
"description": "The level of the ancestor, where the parent is 1 and the root is the highest level",
}
},
"required": ["level"],
},
"id": {
"type": "string",
"description": "The ID of the topic content node on Studio",
},
"title": {"type": "string", "description": "The title of the topic"},
"description": {
"type": "string",
"description": "The description of the topic",
},
"language": {
"type": "string",
"description": "Language code from https://github.com/learningequality/le-utils/blob/main/le_utils/resources/languagelookup.json",
"pattern": "^[a-z]{2,3}(?:-[a-zA-Z]+)?$",
},
"level": {
"type": "integer",
"description": "The level of the ancestor, where the parent is 1 and the root is the highest level",
},
"ancestor": {
"type": "object",
"description": "An ancestor in the tree structure",
"additionalProperties": False,
"properties": {
"id": {"$ref": "#/definitions/id"},
"title": {"$ref": "#/definitions/title"},
"description": {"$ref": "#/definitions/description"},
"language": {"$ref": "#/definitions/language"},
"level": {"$ref": "#/definitions/level"},
},
"required": ["id", "title", "description", "level"],
},
"ancestors": {
"type": "array",
"description": "The ancestors of the topic, in order, from the parent to the root",
"items": {"$ref": "#/definitions/ancestor"},
},
"topic": {
"type": "object",
"description": "A topic in the tree structure",
"additionalProperties": False,
"properties": {
"id": {
"type": "string",
"description": "The ID of the topic content node on Studio",
},
"title": {"type": "string", "description": "The title of the topic"},
"description": {
"type": "string",
"description": "The description of the topic",
},
"id": {"$ref": "#/definitions/id"},
"title": {"$ref": "#/definitions/title"},
"description": {"$ref": "#/definitions/description"},
"language": {"$ref": "#/definitions/language"},
"ancestors": {"$ref": "#/definitions/ancestors"},
},
Expand Down
72 changes: 53 additions & 19 deletions spec/schema-embed_topics_request.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,75 @@
"description": "Schema for embed topics requests received by RayServe",
"additionalProperties": false,
"definitions": {
"ancestors": {
"type": "array",
"description": "The ancestors of the topic, in order, from the parent to the root",
"items": {
"$ref": "#/definitions/topic",
"properties": {
"level": {
"type": "integer",
"description": "The level of the ancestor, where the parent is 1 and the root is the highest level"
}
},
"required": ["level"]
}
"id": {
"type": "string",
"description": "The ID of the topic content node on Studio"
},
"title": {
"type": "string",
"description": "The title of the topic"
},
"description": {
"type": "string",
"description": "The description of the topic"
},
"language": {
"type": "string",
"description": "Language code from https://github.com/learningequality/le-utils/blob/main/le_utils/resources/languagelookup.json",
"pattern": "^[a-z]{2,3}(?:-[a-zA-Z]+)?$"
},
"level": {
"type": "integer",
"description": "The level of the ancestor, where the parent is 1 and the root is the highest level"
},
"ancestor": {
"type": "object",
"description": "An ancestor in the tree structure",
"additionalProperties": false,
"properties": {
"id": {
"$ref": "#/definitions/id"
},
"title": {
"$ref": "#/definitions/title"
},
"description": {
"$ref": "#/definitions/description"
},
"language": {
"$ref": "#/definitions/language"
},
"level": {
"$ref": "#/definitions/level"
}
},
"required": [
"id",
"title",
"description",
"level"
]
},
"ancestors": {
"type": "array",
"description": "The ancestors of the topic, in order, from the parent to the root",
"items": {
"$ref": "#/definitions/ancestor"
}
},
"topic": {
"type": "object",
"description": "A topic in the tree structure",
"additionalProperties": false,
"properties": {
"id": {
"type": "string",
"description": "The ID of the topic content node on Studio"
"$ref": "#/definitions/id"
},
"title": {
"type": "string",
"description": "The title of the topic"
"$ref": "#/definitions/title"
},
"description": {
"type": "string",
"description": "The description of the topic"
"$ref": "#/definitions/description"
},
"language": {
"$ref": "#/definitions/language"
Expand Down
33 changes: 32 additions & 1 deletion tests/test_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ def test_completion_criteria__reference__invalid():


@pytest.mark.skipif(jsonschema is None, reason="jsonschema package is unavailable")
def test_embed__topics__valid():
def test_embed__topics__without__ancestors__valid():
with _assert_not_raises(jsonschema.ValidationError):
validate_embed_topics_request(
{
Expand All @@ -293,6 +293,37 @@ def test_embed__topics__valid():
)


@pytest.mark.skipif(jsonschema is None, reason="jsonschema package is unavailable")
def test_embed__topics__with__ancestors__valid():
with _assert_not_raises(jsonschema.ValidationError):
validate_embed_topics_request(
{
"topics": [
{
"id": "456",
"title": "Target topic",
"description": "Target description",
"language": "en",
"ancestors": [
{
"id": "456",
"title": "Parent topic",
"description": "Parent description",
"language": "en",
"level": 1,
}
],
}
],
"metadata": {
"channel_id": "000",
"channel_title": "Channel title",
"some_additional_field": "some_random_value",
},
}
)


@pytest.mark.skipif(jsonschema is None, reason="jsonschema package is unavailable")
def test_embed__content__valid():
with _assert_not_raises(jsonschema.ValidationError):
Expand Down

0 comments on commit b6c558b

Please sign in to comment.