Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added Json Schema for dtspec yaml format #53

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
211 changes: 6 additions & 205 deletions dtspec/api.py
Original file line number Diff line number Diff line change
@@ -1,215 +1,16 @@
import os

import networkx
import jsonschema
import yaml
from colorama import Fore, Style

from dtspec.core import Identifier, Factory, Source, Target, Scenario, Case
from dtspec.expectations import DataExpectation

SCHEMA = {
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Data Test Studio API spec",
"description": "Data Test Studio API spec",
"definitions": {
"identifier_map": {
"type": "array",
"minItems": 1,
"uniqueItems": True,
"items": {
"type": "object",
"required": ["column", "identifier"],
"additionalProperties": False,
"properties": {
"column": {"type": "string"},
"identifier": {
"type": "object",
"required": ["name", "attribute"],
"additionalProperties": False,
"properties": {
"name": {"type": "string"},
"attribute": {"type": "string"},
},
},
},
},
},
"factory_data": {
"type": "array",
"minItems": 1,
"uniqueItems": True,
"items": {
"type": "object",
"required": ["source", "table"],
"additionalProperties": False,
"properties": {
"source": {"type": "string"},
"table": {"type": "string"},
"values": {"$ref": "#/definitions/column_values"},
},
},
},
"column_values": {
"type": "array",
"minItems": 1,
"uniqueItems": True,
"items": {
"type": "object",
"required": ["column", "value"],
"additionalProperties": False,
"properties": {
"column": {"type": "string"},
"value": {"type": ["string", "null"]},
},
},
},
"expected": {
"type": "object",
"required": ["data"],
"additionalProperties": False,
"properties": {
"data": {
"type": "array",
"minItems": 1,
"uniqueItems": True,
"items": {
"type": "object",
"required": ["target"],
"additionalProperties": False,
"properties": {
"target": {"type": "string"},
"table": {"type": "string"},
"values": {"$ref": "#/definitions/column_values"},
"by": {"type": "array", "items": {"type": "string"}},
"compare_via": {"type": "string"},
},
},
}
},
},
},
"type": "object",
"properties": {
"version": {"type": "string"},
"description": {"type": "string"},
"identifiers": {
"type": "array",
"minItems": 1,
"uniqueItems": True,
"items": {
"type": "object",
"required": ["identifier", "attributes"],
"additionalProperties": False,
"properties": {
"identifier": {"type": "string"},
"attributes": {
"type": "array",
"minItems": 1,
"uniqueItems": True,
"items": {
"type": "object",
"required": ["field", "generator"],
"additionalProperties": True,
"properties": {
"field": {"type": "string"},
"generator": {"type": "string"},
},
},
},
},
},
},
"sources": {
"type": "array",
"minItems": 1,
"uniqueItems": True,
"items": {
"type": "object",
"required": ["source"],
"addtionalProperties": False,
"properties": {
"source": {"type": "string"},
"defaults": {"$ref": "#/definitions/column_values"},
"identifier_map": {"$ref": "#/definitions/identifier_map"},
"description": {"type": "string"},
},
},
},
"targets": {
"type": "array",
"minItems": 1,
"uniqueItems": True,
"items": {
"type": "object",
"required": ["target"],
"addtionalProperties": False,
"properties": {
"target": {"type": "string"},
"identifier_map": {"$ref": "#/definitions/identifier_map"},
"description": {"type": "string"},
},
},
},
"factories": {
"type": "array",
"minItems": 1,
"uniqueItems": True,
"items": {
"type": "object",
"required": ["factory"],
"additionalProperties": False,
"properties": {
"factory": {"type": "string"},
"description": {"type": "string"},
"parents": {"type": "array", "items": {"type": "string"}},
"data": {"$ref": "#/definitions/factory_data"},
},
},
},
"scenarios": {
"type": "array",
"minItems": 1,
"uniqueItems": True,
"items": {
"type": "object",
"required": ["scenario", "cases"],
"additionalProperties": False,
"properties": {
"scenario": {"type": "string"},
"description": {"type": "string"},
"factory": {
"parents": {"type": "array", "items": {"type": "string"}},
"data": {"$ref": "#/definitions/factory_data"},
},
"cases": {
"type": "array",
"minItems": 1,
"uniqueItems": True,
"items": {
"type": "object",
"required": ["case", "expected"],
"additionalProperties": False,
"properties": {
"case": {"type": "string"},
"description": {"type": "string"},
"factory": {
"type": "object",
"required": ["data"],
"additionalProperties": False,
"properties": {
"data": {"$ref": "#/definitions/factory_data"}
},
},
"expected": {"$ref": "#/definitions/expected"},
},
},
},
},
},
},
"metadata": {"type": "object"},
},
"required": ["version", "sources", "scenarios"],
"additionalProperties": False,
}

with open(os.path.dirname(os.path.realpath(__file__)) + "/schema/dtspec-schema.json", "r") as stream:
SCHEMA = yaml.safe_load(stream)


class ApiValidationError(Exception):
Expand Down
Loading