Search code examples
javascriptangularexpressswaggerswagger-codegen

Swagger-Codegen: How do I consolidate all files into one file for Client-Code-Generation


I’ve just got started with Swagger and NodeJS. I was able to implement Swagger to my NodeExpress application and was also able to generate typescript-client-code with Swagger-Codegen (Typescript-Angular) to be exact.

One problem that I have is the generated code is so spread out many different files. I was hoping that it only output one file api.ts and it contains everything from API calls and interfaces/models.

I’ve been looking for a way to solve this problem because it is hard to read and maintain the generated-client-code as the backend grows.

Any suggestions or pointers would be much appreciated.

Happy Holiday! Thank you

EDIT: I have been looking for answers for this for a couple of days and still haven't found one. I'm currently working on a project with ASP.NET Core and they have NSwag which does what I want to achieve with Node Swagger.


Solution

  • TL; DR

    You may compile all files into a single *.ts file as shown at this post.

    Continuous Integration Approach

    Swagger code generator simplifies maintenance because it allows you to think in terms of continuous integrations.

    You should not be worried about code review or aesthetics (because it is a machine generated code), but about:

    • API versioning
    • Functions, methods and classes signatures
    • Documentation

    If you are working with a CI system such as Jenkins or Ansible, you could automatically deploy the library to a private NPM account (for JS and TS) or Maven server (for Java and Kotlin).

    Private Maven

    Keeping the package version number consistently updated will allow the IDE to correctly prompt the user about updates on the API.

    enter image description here