This guide explains how to maintain and verify documentation for the AWS Generative AI CDK Constructs library.
This project uses jsii-rosetta to ensure that all code examples in the documentation are syntactically correct and can be compiled. This prevents common issues where documentation examples become outdated or contain errors.
This library uses jsii make it polyglot. jsii allows code in any language to naturally interact with JavaScript classes. It is the technology that enables the AWS Cloud Development Kit to deliver polyglot libraries from a single codebase, like this one. A class library written in TypeScript can be used in projects authored in TypeScript or Javascript (as usual), but also in Python, Java, C# (and other languages from the .NET family), ...
jsii first compiles the code written in Typescript using the standard typescript compiler (tsc) to produce the Javascript code. It then generates an assembly file (.jsii), which is a JSON-formatted document. This file contains a lot of information about the constructs, their fields, methods and the documentation.
jsii is a toolchain with multiple tools:
- jsii-rosetta that transliterates code snippets (in docs) from TypeScript to target languages. We’ll come back to this one.
- jsii-packmack generates libraries in different programming languages.
- jsii-docgen generates the API.md file and more. All the tools are described in the documentation
Specifically around the documentation, jsii-rosetta will use the generated assemble file (.jsii) to extract all the examples, compile them and transliterate (translate) them in all languages. If the compilation succeed, it will generate a tablet file (named .jsii.tabl.json) that will contain all the code snippets from your project in all languages.
Rosetta fixtures are template files that provide the necessary imports and boilerplate code for examples. They are located in the rosetta/ directory:
default.ts-fixture: Default template for most examples
The README.md file uses special keywords to reference example files:
typescript fixture=defaultYou can reference any fixture located in the fixture folder.
Update the existing fixture file in the rosetta folder, or create a new one for your use case.
References your fixture in the code snippet definition:
typescript fixture=defaultRun the documentation verification:
projen docs:compileThis will:
- Compile the TypeScript code
- Extract and verify all examples using jsii-rosetta
- Fail if any examples have compilation errors
This step will also run as part of the full build (projen build).
Examples should demonstrate the most common use case for a construct. Complex scenarios can be documented separately.
Choose the fixture that best matches your example:
- Use
default.ts-fixturefor basic examples - Use specific fixtures (e.g.,
special.ts-fixture) for domain-specific examples
Run projen docs:compile before committing changes to ensure all examples compile correctly.
- Import Errors: Make sure all necessary imports are included in your fixture file
- Compilation Errors: Check that your example code is syntactically correct
- Missing Fixtures: Create appropriate fixture files for new domains
If you encounter issues with documentation verification:
- Check the jsii-rosetta documentation: https://github.com/aws/jsii/tree/main/packages/jsii-rosetta
- Review the fixture files in the
rosetta/directory