Skip to content

Commit

Permalink
new frontmatter schema definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
AsherGlick committed Sep 30, 2023
1 parent 32ccac8 commit 39b4f32
Show file tree
Hide file tree
Showing 2 changed files with 194 additions and 255 deletions.
258 changes: 3 additions & 255 deletions xml_converter/generators/code_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,264 +9,12 @@
from jinja2 import Template, FileSystemLoader, Environment
from jinja_helpers import UnindentBlocks

SchemaType = Dict[str, Any]
schema = """
type: object
properties:
type:
type: string
enum: [Int32, Fixed32, Float32, String, Boolean, MultiflagValue, Enum, CompoundValue, Custom, CompoundCustomClass]
allOf:
#############################
# Int32 Type
#############################
- if:
properties:
type:
const: Int32
then:
additionalProperties: false
required: [{shared_fields}]
properties:
{shared_field_properties}
#############################
# Fixed32 Type
#############################
- if:
properties:
type:
const: Fixed32
then:
additionalProperties: false
required: [{shared_fields}]
properties:
{shared_field_properties}
#############################
# Float32 Type
#############################
- if:
properties:
type:
const: Float32
then:
additionalProperties: false
required: [{shared_fields}]
properties:
{shared_field_properties}
#############################
# String Type
#############################
- if:
properties:
type:
const: String
then:
additionalProperties: false
required: [{shared_fields}]
properties:
{shared_field_properties}
#############################
# Boolean Type
#############################
- if:
properties:
type:
const: Boolean
then:
additionalProperties: false
required: [{shared_fields}]
properties:
{shared_field_properties}
#############################
# MultiflagValue Type
#############################
- if:
properties:
type:
const: MultiflagValue
then:
additionalProperties: false
required: [{shared_fields}, flags]
properties:
{shared_field_properties}
flags:
type: object
patternProperties:
"^[a-z_]+$":
type: array
items:
type: string
#############################
# Enum Type
#############################
- if:
properties:
type:
const: Enum
then:
additionalProperties: false
required: [{shared_fields}, values]
properties:
{shared_field_properties}
values:
type: object
patternProperties:
"^[a-z_]+$":
type: array
items:
type: string
#############################
# CompoundValue Type
#############################
- if:
properties:
type:
const: CompoundValue
then:
additionalProperties: false
required: [{shared_fields}, xml_bundled_components, xml_separate_components, components]
properties:
{shared_field_properties}
xml_bundled_components:
type: array
items:
type: string
xml_separate_components:
type: array
items:
type: string
components:
type: array
items:
type: object
additionalProperties: false
required: [name, type, xml_fields, protobuf_field, compatability]
properties:
name:
type: string
type:
type: string
enum: [Int32, Fixed32, Float32]
xml_fields:
type: array
items:
type: string
pattern: "^[A-Za-z]+$"
protobuf_field:
type: string
pattern: "^[a-z_.]+$"
compatability:
type: array
items:
type: string
enum: [BlishHUD, Burrito, TacO]
#############################
# CompoundCustomClass Type
#############################
- if:
properties:
type:
const: CompoundCustomClass
then:
additionalProperties: false
required: [{shared_fields}, xml_bundled_components, xml_separate_components, class]
properties:
{shared_field_properties}
class:
type: string
xml_bundled_components:
type: array
items:
type: string
xml_separate_components:
type: array
items:
type: string
components:
type: array
items:
type: object
additionalProperties: false
required: [name, type, xml_fields, protobuf_field, compatability]
properties:
name:
type: string
type:
type: string
enum: [Int32, Fixed32, Float32]
xml_fields:
type: array
items:
type: string
pattern: "^[A-Za-z]+$"
protobuf_field:
type: string
pattern: "^[a-z_.]+$"
compatability:
type: array
items:
type: string
enum: [BlishHUD, Burrito, TacO]
#############################
# Custom Type
#############################
- if:
properties:
type:
const: Custom
then:
additionalProperties: false
required: [{shared_fields}, class]
properties:
{shared_field_properties}
class:
type: string
side_effects:
type: array
items:
type: string
uses_file_path:
type: boolean
""".format(
shared_field_properties="""type:
type: string
name:
type: string
applies_to:
type: array
items:
type: string
enum: [Icon, Trail, Category]
compatability:
type: array
items:
type: string
enum: [BlishHUD, Burrito, TacO]
xml_fields:
type: array
items:
type: string
pattern: "^[A-Za-z]+$"
protobuf_field:
type: string
pattern: "^[a-z_.]+$"
""",
shared_fields="type, name, applies_to, compatability, xml_fields, protobuf_field"
)

from schema import schema

SchemaType = Dict[str, Any]
def validate_front_matter_schema(front_matter: Any) -> str:
try:
validate(front_matter, yaml.safe_load(schema))
validate(front_matter, schema)
except ValidationError as e:
return "Error Message: {} (Path: {}".format(e.message, e.json_path)
return ""
Expand Down
Loading

0 comments on commit 39b4f32

Please sign in to comment.