Opened 14 years ago

Closed 14 years ago

Last modified 3 years ago

#413 closed task (fixed)

Automatic validation of entity templates

Reported by: Philip Taylor Owned by: Philip Taylor
Priority: Should Have Milestone:
Component: UI & Simulation Keywords:
Cc: Patch:

Description

Entity templates are a kind of tree structure, defined by a series of XML files (each inheriting from a parent file and overriding some parts). To save component code from having to worry about detecting and reporting invalid input (missing fields, incorrect data types, etc) there should be a centralised validation system. Each component reports its requirements, and the validator checks each template against them.

It would probably be sensible to use libxml2's RelaxNG support for this, since it provides a reasonable schema language for checking the structure and data types. The entity template can be serialised into XML (after applying all the inheritance rules etc) and then validated. If validation fails then the entity won't be loaded. It'd be particularly nice to use the RelaxNG Compact syntax, but libxml2 doesn't support that (it just has a half-finished RNC->RNG converter in its source control repository that is of unknown quality), so I don't know how feasible that is.

For efficiency (if it turns out that it matters), the validation status of entity templates could perhaps be cached at the same time as they're converted to XMB.

Change History (5)

comment:1 by Philip Taylor, 14 years ago

Milestone: UnclassifiedSimulation stage 4

See also #245

comment:2 by philip, 14 years ago

(In [7452]) # Initial support for automatic validation of entity template XML. Add RelaxNG schemas for all current components. Add -dumpSchema command-line option to dump the combined entity schema. Add a Perl script to validate entity templates against the schema. See #413.

comment:3 by philip, 14 years ago

Resolution: fixed
Status: newclosed

(In [7455]) # Automatic runtime validation of entity template files. Fixes #413.

comment:4 by (none), 14 years ago

Milestone: Simulation stage 4

Milestone Simulation stage 4 deleted

comment:5 by wraitii, 3 years ago

In 25258:

Delete "Compact RelaxNG" / .rnc files

(Follows rP25210 where I deleted actor.rnc)

This deletes the .rnc validation files, upgrading the .rng files to being the source of truth.

  • The engine uses, via LibXML2, .rng files to validate XML schemas, to the .rnc files are redundant.
  • The RelaxNG "Compact" format is a DSL for the RelaxNG XML format. Its syntax is unique, unlike .rng files which are XML.
  • Some errors are likely - I'm not sure anyone has converted the compact files in years.
  • The tool to generate .rng from .rnc files is trang (https://github.com/relaxng/jing-trang), which runs on the JVM and is quite annoying to install compared to "your usual text editor".
  • The JS components use the full .rng format in XML, so editing this format is already familiar to most people that mod the game.

The .rnc files were added in rP15377 along the .rng files.

Refs #413, #245

Differential Revision: https://code.wildfiregames.com/D3824

Note: See TracTickets for help on using tickets.