Document models
A document model represents the shape of a document in a particular Firestore collection.A literal field that specifies that this is a
document
model.An exact or generic path to the document. Must be a string consisting of path segments separated by a
/
(slash). Each segment can either be a literal ID or a generic ID of the collection or document. A literal ID is a plain string, such as users
, while a generic ID must be enclosed in curly braces (e.g. {userId}
).Example values:projects/{projectId}
: A document in a top-levelprojects
collection.users/{userId}/posts/{postId}
: A document in aposts
sub-collection.static/data/authors/{authorId}
: A document in a staticauthors
sub-collection.{rootColId}/{docId}/cities/london
: A document with a specific ID in acities
sub-collection.
Optional documentation explaining the model in more detail. Typesync will add
this to the doc comments for the generated models.
The type representing the shape of the document. A document can be represented
only by an object type.
Example
user.yml
Alias models
An alias model is used for convenience purposes to define reusable type aliases. You can use the same alias model in multiple document models. You can also use alias models when composing other aliases.A literal field that specifies that this is an
alias
model.Optional documentation explaining the model in more detail. Typesync will add
this to the doc comments for the generated models.
Example
user.yml
Autcomplete/Intellisense
When writing your schema definition in YAML, always include the following line at the top
of each definition file.This indicates to your IDE that the file is not just any YAML file but a part of a Typesync definition by linking it to the relevant JSON Schema.. This will allow your IDE to provide Intellisense/autocomplete for definition fields.
For type hinting to take effect, you may need to install a YAML extension that
automatically loads the specified JSON Schema. For VS Code, we recommend using
the YAML
extension by Red Hat.
v0.4
. Patch version is always excluded.
Validating with CLI
While utilizing a JSON schema can help identify syntax errors within your schema definition, the Typesync CLI provides the most reliable method to check if a definition is syntactically valid. To validate a schema definition, use thevalidate
command as shown below:
Typesync automatically validates your definition before running any generators. The manual validation command is needed when you just want to check if your schema definition is valid without generating any artifacts.