|
| 1 | +# Code Generation |
| 2 | + |
| 3 | +This directory contains OpenAPI code generation configuration and post-processing scripts for language server runtime types. |
| 4 | + |
| 5 | +## Structure |
| 6 | + |
| 7 | +- `schema/` - OpenAPI schema definitions |
| 8 | +- `custom-templates/` - Custom Mustache templates for code generation sorted by langauage |
| 9 | +- `generated/` - Generated output directory where TypeScript and Java types will be located post generation |
| 10 | +- `post-generate.js` - Post-processing script |
| 11 | +- `openapitools.json` - OpenAPI Generator configuration |
| 12 | + |
| 13 | +## Configuration |
| 14 | + |
| 15 | +### openapitools.json |
| 16 | + |
| 17 | +OpenAPI Generator configuration defining code generation settings for TypeScript and Java: |
| 18 | + |
| 19 | +**Common Configuration:** |
| 20 | +- `generatorName` - Specifies the generator type (typescript-fetch, java) |
| 21 | +- `disabled` - Allows selective turning off of generators during development. By default, all generators run. New languages/input specs can be added with their own customization |
| 22 | +- `output` - Target directory for generated code |
| 23 | +- `inputSpec` - Source OpenAPI schema file |
| 24 | +- `templateDir` - Points to custom Mustache templates that overwrite canonical templates from [OpenAPI Generator templates](https://openapi-generator.tech/docs/templating) |
| 25 | + |
| 26 | +**TypeScript Configuration:** |
| 27 | +- `additionalProperties` - Language-specific options from the [typescript-fetch generator](https://openapi-generator.tech/docs/generators/typescript-fetch/). Notable settings: |
| 28 | + - `stringEnums` - Generates string enums instead of numeric |
| 29 | + - `withoutRuntimeChecks` - Reduces unnecessary generated code by removing runtime validation |
| 30 | + - `supportsES6` - Enables ES6 features |
| 31 | + - `modelPropertyNaming`/`enumPropertyNaming` - Sets camelCase naming conventions |
| 32 | +- `global-property` - [Global properties](https://openapi-generator.tech/docs/globals) for debugging and selective model generation (alternative to .openapi-generator-ignore file) |
| 33 | +- `openapi-normalizer` - [Normalizers](https://openapi-generator.tech/docs/customization/#openapi-normalizer) shape input before generation: |
| 34 | + - `REF_AS_PARENT_IN_ALLOF` - Enables traditional inheritance (extends) via allOf instead of including all parent fields in child, resulting in cleaner code |
| 35 | +- `reservedWordsMappings` - Overcomes generator renaming of reserved words. Forces `export` field to remain `export` instead of being renamed to `_export` |
| 36 | +- `typeMappings` - Overcomes generator quirks where `Date` gets converted to `string` or `ModelDate`. Forces generator to use proper `Date` type |
| 37 | + |
| 38 | +**Java Configuration:** TODO TODO TODO |
| 39 | +- `additionalProperties` - Java-specific settings including Java 21 compatibility, validation options, and serialization settings |
| 40 | +- `global-property.models` - Specifies exact models to generate (CursorPosition, FileParams, etc.) for selective generation |
| 41 | +- `importMappings` - Maps external types to LSP4J classes for seamless integration with Language Server Protocol |
| 42 | + |
| 43 | +## Post-Processing |
| 44 | + |
| 45 | +The `post-generate.js` script runs after OpenAPI code generation to customize the generated TypeScript types: |
| 46 | + |
| 47 | +- **Adds constants**: Adds protocol method constants from `constants.ts` to the generated index file. This is due to a limitation of the OpenAPI generator which ignores type alias constants in generation. |
| 48 | +- **Modifies interfaces**: Changes `PartialResultParams` from exported to internal interface. This is because `PartialResultParams` is only used internally and causes conflicts with VS Code LSP protocol type of the same name if exported. This interface is not exported in the current `chat.ts` either. |
| 49 | +- **Extensible**: Other post-processing steps should be added here. |
| 50 | + |
| 51 | +This ensures the generated types integrate properly with the language server runtime while maintaining clean separation between generated and hand-written code. |
0 commit comments