Nx 的 OpenAPI 插件
将您的 API 光谱文件保存在 libs 中,以及自动生成源和文档中 .
这是什么?
它是用于在库中组织OpenAPI spec文件的插件. 然后,您可以拥有其它用于API SDK的库,服务器根,或者文档,所有自定义文件自动生成的.
如何安装
nx add @driimus/nx-plugin-openapi
先决条件
来源通过 openapi-generator-cli,所以你需要Java 8或多克安装.
使用量
为 API spec 文件创建 lib
nx generate @driimus/nx-plugin-openapi:api-spec
✔ What name would you like to use? · api-spec
✔ Do you want me to also create a sample spec file for you? (y/N) · true
UPDATE package.json
UPDATE workspace.json
UPDATE nx.json
CREATE libs/my-service-api-spec/src/my-service-api-spec.openapi.yml
为自动生成的文档创建 lib
nx generate @driimus/nx-plugin-openapi:api-lib
✔ What name would you like to use? · api-docs
✔ Which OpenAPITool generator would you like to use? (https://github.com/OpenAPITools/openapi-generator) · html
✔ Is the API spec file published online? (y/N) · false
✔ If it's online, what's the URL where I can get the API spec file from? ·
✔ If it's online, which authorization headers do you need to add? ·
✔ If it's local, what's the name of the lib containing the API spec file? · api-spec
✔ If it's local, what's the path of the API spec file starting from the lib root? · src/api-spec.openapi.yml
✔ Do you want to specify any additional properties for the generator? key1=value1,key2=value2 (https://openapi-generator.tech/docs/generators) ·
✔ Do you want to specify any global properties for the generator? key1=value1,key2=value2 (https://openapi-generator.tech/docs/globals) ·
UPDATE workspace.json
UPDATE nx.json
CREATE libs/api-docs/README.md
UPDATE tsconfig.base.json
为自动生成的客户端源创建 lib
nx generate @driimus/nx-plugin-openapi:api-lib
✔ What name would you like to use? · api-fetch
✔ Which OpenAPITool generator would you like to use? (https://github.com/OpenAPITools/openapi-generator) · typescript-fetch
✔ Is the API spec file published online? (y/N) · false
✔ If it's online, what's the URL where I can get the API spec file from? ·
✔ If it's online, which authorization headers do you need to add? ·
✔ If it's local, what's the name of the lib containing the API spec file? · api-spec
✔ If it's local, what's the path of the API spec file starting from the lib root? · src/api-spec.openapi.yml
✔ Do you want to specify any additional properties for the generator? key1=value1,key2=value2 (https://openapi-generator.tech/docs/generators) · typescriptThreePlus=true,supportsES6=true
✔ Do you want to specify any global properties for the generator? key1=value1,key2=value2 (https://openapi-generator.tech/docs/globals) ·
UPDATE workspace.json
UPDATE nx.json
CREATE libs/api-fetch/README.md
UPDATE tsconfig.base.json
生成或更新来源
鉴于以上例子中产生的自由
nx run api-docs:generate-sources
# Then you can simply serve it
npx http-server libs/api-docs/src
# Or you can configure a Nx serve target for it, or do whatever you want
nx run api-fetch:generate-sources
发电机
Nx 的 OpenAPI 插件应该支持您可以使用的任何生成器 openapi-generator-cli。 。 。 .
查找您需要的, 以及每个生成器可用的所有附加属性 : https://openapi-generator.tech/docs/generators 页面存档备份,存于互联网档案馆
鸣谢
多亏了每一个项目 和每一个我从中得到灵感的人,但特别:
- @vsavkin (英语) 页:1 @nrwl/反应
- @ ericwooley (英语) 页:1 他自己的 @ ericwooley/ opanapi- sdk
- @ tinesoft (英语) 激励我使用 Nx 插件开发 以旋转, 发行他们的 @nxrocks/nx-spring-boot (英语)