Source code for gxformat2.schema.json_schema
"""JSON Schema export for gxformat2 workflow models.
Provides export functions that generate standard Draft 2020-12 JSON Schema
from gxformat2's Pydantic models. Exported schemas are intended for consumption
by external validators (Python jsonschema, TypeScript ajv, VSCode YAML extension).
"""
import json
from typing import (
Any,
)
from pydantic import BaseModel
from pydantic.json_schema import GenerateJsonSchema
from typing import Literal
MODE = Literal["validation", "serialization"]
[docs]
def workflow_json_schema(*, strict: bool = False, mode: MODE = "validation") -> dict[str, Any]:
"""Export GalaxyWorkflow JSON Schema.
Args:
strict: If True, use strict model (extra="forbid" — rejects unknown keys).
mode: Pydantic schema mode ("validation" or "serialization").
"""
model_class: type[BaseModel]
if strict:
from .gxformat2_strict import GalaxyWorkflow as model_class
else:
from .gxformat2 import GalaxyWorkflow as model_class
return model_class.model_json_schema(
schema_generator=GxFormat2GenerateJsonSchema,
mode=mode,
)
[docs]
def native_workflow_json_schema(*, strict: bool = False, mode: MODE = "validation") -> dict[str, Any]:
"""Export NativeGalaxyWorkflow JSON Schema.
Args:
strict: If True, use strict model (extra="forbid" — rejects unknown keys).
mode: Pydantic schema mode ("validation" or "serialization").
"""
model_class: type[BaseModel]
if strict:
from .native_strict import NativeGalaxyWorkflow as model_class
else:
from .native import NativeGalaxyWorkflow as model_class
return model_class.model_json_schema(
schema_generator=GxFormat2GenerateJsonSchema,
mode=mode,
)
[docs]
def workflow_json_schema_string(*, strict: bool = False, mode: MODE = "validation") -> str:
"""Export GalaxyWorkflow JSON Schema as formatted string."""
return json.dumps(workflow_json_schema(strict=strict, mode=mode), indent=4)
[docs]
def native_workflow_json_schema_string(*, strict: bool = False, mode: MODE = "validation") -> str:
"""Export NativeGalaxyWorkflow JSON Schema as formatted string."""
return json.dumps(native_workflow_json_schema(strict=strict, mode=mode), indent=4)