简体   繁体   English

从Typescript项目生成OpenApi规范

[英]Generate OpenApi Spec from Typescript Project

We are running our typescript services on aws-lambda using the plain ApiGatewayProxyEvent instead of any express or other middlewares. 我们正在使用普通的ApiGatewayProxyEvent而不是任何express或其他中间件在aws-lambda上运行我们的打字稿服务。 Each route in the service has it's own function definition in AWS Lambda . 服务中的每个路由在AWS Lambda都有其自己的功能定义。

We would like to have a code-first approach on creating our OpenApi spec similar to what SpringFox does for Spring, but without using any runtime dependency on a framework. 我们希望采用一种代码优先的方法来创建我们的OpenApi规范,类似于SpringFox对Spring SpringFox那样,但是不使用任何对框架的运行时依赖。

In our current PoC we use typescript-rest and typescript-rest-swagger to annotate the controllers and then call swaggerGen -c ./swaggerConfig.json -p ./tsconfig.json . 在当前的PoC中,我们使用typescript-resttypescript-rest-swagger来注释控制器,然后调用swaggerGen -c ./swaggerConfig.json -p ./tsconfig.json This provides us with the correct OpenApi Specification. 这为我们提供了正确的OpenApi规范。 However, when we run the actual function in our environment we get the following exception: 但是,当我们在环境中运行实际功能时,会出现以下异常:

Module not found: Error: Can't resolve 'typescript-ioc' in '/(...)/node_modules/typescript-rest/dist/server'
 @ ./node_modules/typescript-rest/dist/server/server.js 105:18-72
 @ ./node_modules/typescript-rest/dist/typescript-rest.js
 @ ./src/controllers/myController.ts
 @ ./src/handlers/myHandler.ts
 @ ./src/lambda.ts

ERROR in ./node_modules/typescript-rest/dist/server/server.js
Module not found: Error: Can't resolve 'typescript-ioc/es6' in '(...)/node_modules/typescript-rest/dist/server'
 @ ./node_modules/typescript-rest/dist/server/server.js 105:18-72
 @ ./node_modules/typescript-rest/dist/typescript-rest.js
 @ ./src/controllers/myController.ts
 @ ./src/handlers/myHandler.ts
 @ ./src/lambda.ts

Our assumption is, that this is since typescript-rest is an express plugin and thus needs the service to run on express . 我们的假设是,这是因为typescript-restexpress插件,因此需要该服务在express上运行。 Is there any way to create the spec without having the runtime dependencies? 有没有运行时相关性的规范创建方法吗? If not, are there other tools that allow the code-first approach? 如果没有,是否还有其他工具允许代码优先方法?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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