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:
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 examplesThe README.md file uses special keywords to reference example files:
typescript fixture=default
You 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=default
Run the documentation verification:
projen docs:compile
This will:
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:
default.ts-fixture
for basic examplesspecial.ts-fixture
) for domain-specific examplesRun projen docs:compile
before committing changes to ensure all examples compile correctly.
If you encounter issues with documentation verification:
rosetta/
directory