Using openapi-generator for typescript-angular, how to generate just a module inside an existing Angular project instead a full separate package?

huangapple go评论71阅读模式
英文:

Using openapi-generator for typescript-angular, how to generate just a module inside an existing Angular project instead a full separate package?

问题

我正在使用 openapi-generator 生成 typescript-angular 模块。

我可以成功生成一个包含所有构件的Angular模块,但它是一个单独的npm包。

我明白这种方法有其好处,一个单独的包可以以专业的方式进行维护、版本化、分发等。

然而,我仍然想要在我的现有Angular应用程序中生成一个新模块。是否有一种配置生成器以完成这项任务的方式?

如果不能,那么需要哪些手动步骤来转换和集成生成的源代码以获得这个结果(即在我的现有Angular应用程序中创建一个模块)?

英文:

I am using openapi-generator for typescript-angular.

I can successfully generate an Angular module, with all artifacts, however it is a separate npm package.

I do understand, that this approach has its benefits, and a separate package can be maintained, versioned, distributed etc, in a professional way.

However still, I would like to just generate a new module inside in my existing Angular application. Is there a way to configure the generator to accomplish that task?

In case if not, what manual steps are required to transform and integrate the generated source code to get this result (meaining: a module in my existing Angular application)

答案1

得分: 3

如果您使用以下命令:

openapi-generator-cli generate -i yourApiYAMLfile.yaml -g typescript-angular -o src/app/api

或者

openapi-generator-cli generate -i yourApiSwaggerfile.json -g typescript-angular -o src/app/api

来生成您的客户端代码,作为您的应用程序的一部分。

然后,您可以直接从您的应用程序中使用生成的模型和服务。

查看我根据此创建的文章:https://blog.josematos.work/use-auto-generated-client-code-to-consume-your-api-from-an-angular-app-363c64f6c83a

英文:

If you use this command:

openapi-generator-cli generate -i yourApiYAMLfile.yaml -g typescript-angular -o src/app/api

or

openapi-generator-cli generate -i yourApiSwaggerfile.json -g typescript-angular -o src/app/api

to generate your client code as part of your app.

You can then use the models and services generated, directly from your app.

Check this article I wrote out of this: https://blog.josematos.work/use-auto-generated-client-code-to-consume-your-api-from-an-angular-app-363c64f6c83a

huangapple
  • 本文由 发表于 2023年2月26日 21:09:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/75572198.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定