Search code examples
typescriptopenapi-generator

OpenApiGenerator - How can I skip generating file changes because of a version change


I am using the typescript-rxjs generator. Whenever I generate a new version of my API clients, all files get changed, 99% of them because of the version change: * The version of the OpenAPI document: 1.47.0-rc.20. Real changes get lost in that amount of changes.

I don't want to overwrite all file templates of the generator. That seems to be inefficient since I would have to watch changes of the templates.


Solution

  • The different OpenAPI generators use Mustache as the template engine for generating the different artifacts.

    In this specific use case, the version information is defined in licenseInfo.mustache.

    This template is included by the rest of templates used to generate the different client artifacts.

    You can try to modify that template and provide your own version. The OpenAPI generator gives you the ability to override existing templates.

    Once modified, you need to configure the tool (CLI, Maven, Gradle) you are using as your generator to indicate where to look for the modified template.

    If necessary, you can even provide your own custom user defined templates.

    Another approach could be to define some kind of file post-processing logic that will be executed once the generator has finished its process.

    In the case of the typescript-rxjs generator, the code to be executed must be defined as a string value in the environment variable TS_POST_PROCESS_FILE.

    A typical example:

    export TS_POST_PROCESS_FILE="/usr/local/bin/prettier --write"
    

    In your case perhaps you can define some kind of script, for instance, with sed or other text processing tool, if you are using a linux or unix based OS, or a custom node.js script, that removes that information. The solution will depend again on the actual mechanism - CLI, Maven, Gradle,... - you are using for generating your code.

    Having said that, please consider if it is necessary to put a generated file under version control. Possibly there are mechanisms that would allow it to be generated and used directly by your code, or you can define CI flows that generate an npm package that could be used in a private registry and use this package in your different projects, if necessary.