Generates TypeScript types from the DHIS2 OpenAPI specification.
Make sure you have have node > 18.
yarn install
yarn generate
--url, -u
: The URL of the DHIS2 OpenAPI specification. Default: "https://debug.dhis2.org/dev/api/openapi.json"--force, -f
: Force fetching the OpenAPI specification even if a cached version exists. Default: false--no-transform, -n
: Skip transforming the generated types. Default: false
yarn generate --url https://debug.dhis2.org/2.39dev/api/openapi.json --force
This example fetches the OpenAPI specification from the specified URL and generates TypeScript types. The --force
option ensures that the latest specification is fetched and not loaded from the cache.
This tool uses
- openapi-typescript-codegen to generate TypeScript types from the OpenAPI specification.
- Transformers use ts-morph for easy parsing and manipulation of the generated types.
replaceRefsWithModelType
removes all "Ref_" types and replaces them with the actual full type of the model. This is done because the OpenAPI spec generates references as a simple "Ref*TYPE" that only specifies the id.removeUnusedFiles
removes all files that are not referenced by any other file (except index) and matches the patterns[/UID*/, /Ref*/, /PropertyNames*/]
. This is done because they are mostly bloat, and due to thereplaceRefsWithModelType
-transformationREF*
-types are not needed.string
are used in most places instead ofUID*
types.setPropertiesRequired
sets all properties of a model to required. This is done because the OpenAPI schema specifies required properties in terms of model creation, but the types are mostly used for describing fetched data. The schema (eg. /api/schemas/dataElement.json) should be used in runtime to determine required properties.