Repository navigation
Make schemas in the compiler as WebAssembly and the playground - #17
Merged
Merged
Conversation
The compiler as WebAssembly has schema(asni, options), which makes a JSON Schema of JER, or an XML Schema or a DTD of BASIC-XER, of the types of an .asni file, as asnkitcc schema does. Its options are format (json-schema, the default, xsd or dtd), types, a name or an array of them, and skipUnsupported. It gives the text, how many types it is of, and those it leaves out with why, and what it can not tell is an Error named SchemaError. The schemas are made by a library of asnkitcc, which both share: schema::generate() makes the text with no file to write, and the command writes it, with the warnings. They are not in asnkit-compiler, which would then need the runtime, which is not published before it in a release. The WebAssembly is larger by about 290 KB, 90 KB gzipped, as it reads the types with the runtime. The playground makes the schema of the selected type, or of every type, as each of the three, to read and to download. A type given with -t that refers to one --skip-unsupported leaves out tells what it refers to, down to the type that can not be told, and why, rather than only the first type it refers to. Signed-off-by: Matheus Xavier <mxavier@boxtheta.com>
An item of a SEQUENCE OF or a SET OF that is a CHOICE, a BOOLEAN or an ENUMERATED has no element of its own in XER (X.693 9.3.6), and the XML Schema had what is in its type in the sequence of the item. A CHOICE that is an item of itself, as Shape of tests/files/sketch.asn, of which group is a SET OF Shape, was then in itself without end, and failed as nested too deeply. Of a type with a name, the item is now the model group of that name, <xs:group ref="Shape"/>, which is what is in the type, as model groups are named apart from types. One with no name is in the sequence as before. tests/schema.rs holds the XML Schema of a tree to its model group, and tests/test_schema.py the XER of a tree that the runtime writes to it, with lxml. Signed-off-by: Matheus Xavier <mxavier@boxtheta.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Brings
asnkitcc schema(#15) to the browser: the npm compiler getsschema(), and the playground gets a Schema panel.schema(asni, options)inasnkit-compiler(npm)format:json-schema(the default),xsdordtd.types: a name or an array of names, asTypeorModule.Type. Every type if not given.skipUnsupported: leave out what a schema can't describe instead of failing.{ text, types, skipped: [{ type, reason }] }.ErrornamedSchemaError; bad options throw aTypeError.js/index.d.ts, and documented in the README and the skill reference.Shared code: a library in
asnkitccasnkitcc(src/lib.rs, which exposesschema), and the wasm crate depends on it.schema::generate()is pure: it returns the text and the skipped types.main.rsnow does the file and stdout writing, the warnings and--verbose, so the CLI output is unchanged.asnkit-compiler? It would then depend onasnkitrt, and the release workflow'scargo publish --dry-run -p asnkit-compilerwould fail before the runtime is published..wasmgrows from 508 KB to 795 KB (196 KB to 285 KB gzipped), because it reads the types through the Rust runtime.Playground
A clearer
--skip-unsupportederrorWhen a type given with
-trefers to a type that is left out, the error now traces back to the cause. Before:After:
The playground's X.509 example shows this error by default.
Fix: an XML Schema of a
CHOICEthat is an item of itselfIn XER, an item of a
SEQUENCE OForSET OFthat is aCHOICE,BOOLEANorENUMERATEDhas no element of its own (X.693 9.3.6). The XSD writer copied that type's content into every place it was used as an item.Shapeintests/files/sketch.asnhasgroup SET OF member Shape, so the copying never stopped, and the XML Schema of the Sketch-PadJournalfailed with "the types are nested too deeply". This was already the case ontrunk.<xs:group name="Shape">, and items refer to it with<xs:group ref="Shape" minOccurs=… maxOccurs=…/>. XSD keeps model groups apart from types, so the group can share the type's name.tests/schema.rschecks the XSD of aNode ::= CHOICE { leaf …, group SEQUENCE OF Node }tree.tests/test_schema.pywrites that tree as XER withasnkitcc convertand checks that lxml accepts it and rejects three wrong documents. It fails on the old binary.Journal, which nestsgroupinsidegroup, encoded as XER, now validates against its XSD. All 207 XER vectors still validate.Checked locally
cargo fmt, andclippy -D warningson the workspace and onwasm32-unknown-unknowncargo test -p asnkitcc, with the new tests intests/schema.rsschema()tests/test_schema.pyagainst the CLI build, withruffandmypycargo docandcargo packageofasnkitccschema()on every playground example in all three formats, in Node. The page itself was not opened in a browser.