Skip to content

Commit

Permalink
Merge pull request #120 from akolson/split-embed-request-schema
Browse files Browse the repository at this point in the history
Split embed request schema
  • Loading branch information
bjester authored Jan 30, 2024
2 parents 159176b + 415210b commit 669d9b3
Show file tree
Hide file tree
Showing 11 changed files with 233 additions and 134 deletions.
65 changes: 65 additions & 0 deletions js/EmbedContentRequest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// -*- coding: utf-8 -*-
// Generated by scripts/generate_from_specs.py
// EmbedContentRequest


export const SCHEMA = {
"$id": "/schemas/embed_content_request",
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"description": "Schema for embed content requests received by RayServe",
"additionalProperties": false,
"definitions": {
"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]+)?$"
},
"resource": {
"type": "object",
"description": "The key textual metadata and data for a content resource",
"additionalProperties": false,
"properties": {
"id": {
"type": "string",
"description": "The ID of the content resource"
},
"title": {
"type": "string",
"description": "The title of the content resource"
},
"description": {
"type": "string",
"description": "The description of the content resource"
},
"text": {
"type": "string",
"description": "The cleaned up text extracted from the content resource (in markdown or plaintext format)"
},
"language": {
"$ref": "#/definitions/language"
}
},
"required": [
"id",
"title",
"description",
"text"
]
}
},
"properties": {
"resources": {
"type": "array",
"description": "A list of content resources to embed",
"items": {
"$ref": "#/definitions/resource"
}
},
"metadata": {
"type": "object",
"description": "The metadata of the channel for logging purposes"
}
},
"required": ["resources"]
};
50 changes: 4 additions & 46 deletions js/EmbedRequest.js → js/EmbedTopicsRequest.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// -*- coding: utf-8 -*-
// Generated by scripts/generate_from_specs.py
// EmbedRequest
// EmbedTopicsRequest


export const SCHEMA = {
"$id": "/schemas/embed_request",
"$id": "/schemas/embed_topics_request",
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"description": "Schema for embed requests received by RayServe",
"description": "Schema for embed topics requests received by RayServe",
"additionalProperties": false,
"definitions": {
"ancestors": {
Expand Down Expand Up @@ -51,38 +51,6 @@ export const SCHEMA = {
"title",
"description"
]
},
"resource": {
"type": "object",
"description": "The key textual metadata and data for a content resource",
"additionalProperties": false,
"properties": {
"id": {
"type": "string",
"description": "The ID of the content resource"
},
"title": {
"type": "string",
"description": "The title of the content resource"
},
"description": {
"type": "string",
"description": "The description of the content resource"
},
"text": {
"type": "string",
"description": "The cleaned up text extracted from the content resource (in markdown or plaintext format)"
},
"language": {
"$ref": "#/definitions/language"
}
},
"required": [
"id",
"title",
"description",
"text"
]
}
},
"properties": {
Expand All @@ -93,20 +61,10 @@ export const SCHEMA = {
"$ref": "#/definitions/topic"
}
},
"resources": {
"type": "array",
"description": "A list of content resources to embed",
"items": {
"$ref": "#/definitions/resource"
}
},
"metadata": {
"type": "object",
"description": "The metadata of the channel for logging purposes"
}
},
"required": [
"topics",
"resources"
]
"required": ["topics"]
};
2 changes: 1 addition & 1 deletion js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"version": "0.2.3"
"version": "0.2.4"
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,25 @@
# Generated by scripts/generate_from_specs.py
from __future__ import unicode_literals

# EmbedRequest
# EmbedContentRequest


choices = ()

EMBEDREQUESTLIST = []
EMBEDCONTENTREQUESTLIST = []

SCHEMA = {
"$id": "/schemas/embed_request",
"$id": "/schemas/embed_content_request",
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"description": "Schema for embed requests received by RayServe",
"description": "Schema for embed content 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"},
},
"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]+)?$",
},
"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",
},
"language": {"$ref": "#/definitions/language"},
"ancestors": {"$ref": "#/definitions/ancestors"},
},
"required": ["id", "title", "description"],
},
"resource": {
"type": "object",
"description": "The key textual metadata and data for a content resource",
Expand Down Expand Up @@ -72,11 +48,6 @@
},
},
"properties": {
"topics": {
"type": "array",
"description": "A list of topics to embed",
"items": {"$ref": "#/definitions/topic"},
},
"resources": {
"type": "array",
"description": "A list of content resources to embed",
Expand All @@ -87,5 +58,5 @@
"description": "The metadata of the channel for logging purposes",
},
},
"required": ["topics", "resources"],
"required": ["resources"],
}
61 changes: 61 additions & 0 deletions le_utils/constants/embed_topics_request.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# -*- coding: utf-8 -*-
# Generated by scripts/generate_from_specs.py
from __future__ import unicode_literals

# EmbedTopicsRequest


choices = ()

EMBEDTOPICSREQUESTLIST = []

SCHEMA = {
"$id": "/schemas/embed_topics_request",
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"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"},
},
"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]+)?$",
},
"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",
},
"language": {"$ref": "#/definitions/language"},
"ancestors": {"$ref": "#/definitions/ancestors"},
},
"required": ["id", "title", "description"],
},
},
"properties": {
"topics": {
"type": "array",
"description": "A list of topics to embed",
"items": {"$ref": "#/definitions/topic"},
},
"metadata": {
"type": "object",
"description": "The metadata of the channel for logging purposes",
},
},
"required": ["topics"],
}
11 changes: 11 additions & 0 deletions le_utils/validators/embed_content_request.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import jsonschema

from le_utils.constants.embed_content_request import SCHEMA


def validate(data):
"""
:param data: Dictionary of data to validate
:raises: jsonschema.ValidationError: When invalid
"""
jsonschema.validate(instance=data, schema=SCHEMA)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import jsonschema

from le_utils.constants.embed_request import SCHEMA
from le_utils.constants.embed_topics_request import SCHEMA


def validate(data):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
setup(
name="le-utils",
packages=find_packages(),
version="0.2.3",
version="0.2.4",
description="LE-Utils contains shared constants used in Kolibri, Ricecooker, and Kolibri Studio.",
long_description=long_description,
long_description_content_type="text/markdown",
Expand Down
60 changes: 60 additions & 0 deletions spec/schema-embed_content_request.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"$id": "/schemas/embed_content_request",
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"description": "Schema for embed content requests received by RayServe",
"additionalProperties": false,
"definitions": {
"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]+)?$"
},
"resource": {
"type": "object",
"description": "The key textual metadata and data for a content resource",
"additionalProperties": false,
"properties": {
"id": {
"type": "string",
"description": "The ID of the content resource"
},
"title": {
"type": "string",
"description": "The title of the content resource"
},
"description": {
"type": "string",
"description": "The description of the content resource"
},
"text": {
"type": "string",
"description": "The cleaned up text extracted from the content resource (in markdown or plaintext format)"
},
"language": {
"$ref": "#/definitions/language"
}
},
"required": [
"id",
"title",
"description",
"text"
]
}
},
"properties": {
"resources": {
"type": "array",
"description": "A list of content resources to embed",
"items": {
"$ref": "#/definitions/resource"
}
},
"metadata": {
"type": "object",
"description": "The metadata of the channel for logging purposes"
}
},
"required": ["resources"]
}
Loading

0 comments on commit 669d9b3

Please sign in to comment.