Skip to content

simple-schema suggestions #312

@FreHu

Description

@FreHu

I am trying to use xml-tools to implement a language on top of xml (it's some kind of crossover of xsd and xslt, but this does not really matter for the purpose of these suggestions).

I believe I can work around these by implementing custom validators, but it would be nice if simple-schema supported

Recursive type definitions

I am using an xml file to describe the structure of an xml file, therefore I need recursive elements, e.g.

<element name="foo">
  <element name="bar">
    <attribute name="attr"><attribute>
  </element>
</element>

is used to represent

<foo>
  <bar attr=""/>
</foo>
const commonNodeProperties: Record<string, XSSAttribute> = {
	name: {
		key: "name",
		required: true
	},
	description: {
		key: "description",
		required: false
	},
	restriction: {
		key: "restriction",
		required: false,
	},
	mappingTarget: {
		key: "mappingTarget",
		required: false,
	},
	mapping: {
		key: "mapping",
		required: false,
	}
};


export const rootElementSchema: XSSElement = {
	name: "element",
	cardinality: "single",
	required: true,
	attributesType: "closed",
	attributes: {
		...commonNodeProperties
	},
	elements: {
		element: {
			name: "element",
			cardinality: "many",
			required: true,
			attributesType: "closed",
			attributes: {
				...commonNodeProperties
			},
			elements: {
                          // element can contain element, attribute with cardinality many
                        },
			elementsType: "open"
		},
		attribute: {
			name: "attribute",
			cardinality: "many",
			required: true,
			attributesType: "closed",
			attributes: {
				...commonNodeProperties
			},
			elements: {},
			elementsType: "open"
		}
	},
	elementsType: "open"
};

export const schema: SimpleSchema = {
	name: "ifme",
	required: true,
	require: true,
	cardinality: "single",
	attributes: {},
	attributesType: "closed",
	elements: {
		environment: environmentSchema,
		constants: constantsSchema,
		enumerations: enumerationsSchema,
		restrictions: restrictionsSchema,
		tree: {
			name: "tree",
			required: true,
			cardinality: "single",
			attributes: {},
			elements: {
				element: rootElementSchema
			},
			attributesType: "closed",
			elementsType: "closed"
		},
	},
};

but I don't think I will be able to accomplish this with simple-schema currently.

Empty attribute value validation

I can specify that an attribute is required, but it is also likely that a required attribute should have a non-empty value.

[minor] XSSElement type definitions

I wish elements and attributes were optional properties, in many cases you don't need them and you have to explicitly use empty objects.

const thatWillBeAllThanks: any = {
	attributes: {},
	elements: {}
};

const environmentSchema: XSSElement = {
	name: "environment",
	required: true,
	cardinality: "single",
	attributes: {
	},
	elements: {
		type: {
			name: "type",
			cardinality: "single",
			required: true,
			...thatWillBeAllThanks
		},
		id: {
			name: "id",
			cardinality: "single",
			required: true,
			...thatWillBeAllThanks
		},
		description: {
			name: "description",
			cardinality: "single",
			required: false,
			...thatWillBeAllThanks
		},
	},
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions