我可以在非 nodejs 应用程序中使用 swagger 测试模板吗? [英] Can I use swagger test template with non nodejs app?

查看:34
本文介绍了我可以在非 nodejs 应用程序中使用 swagger 测试模板吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为 php 应用程序构建 api 测试套件.现在该应用程序正在使用 swagger 注释,我可以轻松创建一个 swagger.json.但是从查看 the swagger 测试模板,看起来我必须先使用 swagger node 创建一个 nodejs 应用程序?有什么办法可以跳过那一步并改用我的 php 应用程序吗?

I'm working in building out a api test suite for a php application. Right now the app is using swagger annotation and I can easily create a swagger.json. But from looking at the swagger test template, it looks like I have to create a nodejs app first using swagger node? Is there a way I can skip that step and use my php app instead?

我已经使用 swagger-php 启动并运行了 swagger 文档.只是想知道是否可以在不使用 swagger-node 的情况下使用 swagger-test-template.

I already have the swagger docs up and running using swagger-php. Just wondering if it's possible to use swagger-test-template without using swagger-node.

推荐答案

我是 swagger-test-templates 的贡献者之一.(我之前没有回答任何关于 SO 的问题,请耐心等待)

I am one of the contributors on swagger-test-templates. (I haven't answered anything on SO before so bear with me)

我是通过最近打开的 Github 问题来解决您的问题的!我在那里回答了它,但我会在这里复制它并进一步扩展它.我希望它有帮助.如果我没有完全回答你的问题,请跟进.

I was brought to your question through a Github issue someone recently opened to address this! I answered it there, but I will copy it here and expand on it some more. I hope it helps. Please follow up if I didn't completely answer your question.

简单的回答:不,它不仅适用于 Node.js API 或 swagger-node.

Simple answer: No, it is not exclusively for Node.js APIs or swagger-node.

更长的答案:您可以像使用 Node.js 项目中的任何其他 Node.js 模块一样完全独立地使用 STT.请参阅自述文件或测试文件如何独立运行它的示例.此外,不必在 Node.js 中实现 API,以便 STT 生成的测试以 HTTP 请求为目标.您必须使用 Node.js 来利用此模块的功能,但只要您将测试指向正在运行的服务器(localhost:1337、my.api.test.net),后端实现就无关紧要.这里需要注意的是,此模块旨在与 mocha 一起运行,后者是一个 Node.js 测试运行程序/框架.所以测试必须在 Node.js 项目中,但服务器实现不是.

Longer answer: You can use STT like any other Node.js module in a Node.js project, completely on its own. See the Readme or the test files for an example of how to run it standalone. Furthermore, the API doesn't have to be implemented in Node.js for a STT generated test to target it with an HTTP request. You have to use Node.js to utilize this module's functionality, but as long as you point the tests at a running server (localhost:1337, my.api.test.net) the backend implementation doesn't matter. The caveat here is that this module was designed to run with mocha which is a Node.js test runner/framework. So the tests have to be in a Node.js project, but the server implementation doesn't.

这篇关于我可以在非 nodejs 应用程序中使用 swagger 测试模板吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆