简体   繁体   中英

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 .

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).

私人Maven

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

在此输入图像描述

Swagger uses Mustache templates for generating the code. For making simpler changes you can simple create a copy of one of the built-in templates and modify that.

Then you can use your modified template like this:

swagger-codegen-cli generate -t path/to/template/dir/ -i spec.json

The output directory structure, however, cannot be changed using templates alone. For that you'd need a custom codegen module. You can either create your own or modify one of the built-in ones .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM