OASGraph 转换rest api graphql 试用
创建rest api
lb4 appdemo
参考提示即可
安装 OASGraph
git clone https://github.com/strongloop/oasgraph.git
cd oasgraph
npm link
或者 npm install -g oasgraph
如果提示权限问题,使用sudo 或者加上 --unsafe-perm
这部分有点慢
启动rest api
cd appdemo
yarn && yarn start
默认openapi 地址是:http://127.0.0.1:3000/openapi.json
配置服务
oasgraph http://127.0.0.1:3000/openapi.json
graphql api 访问
http://127.0.0.1:3001/graphql
说明
因为OASGraph 是基于express 以及graphql、openapi 解析运行的,建议的方式是clone 代码,或者使用api 调用
模块调用格式
const express = require('express')
const graphqlHTTP = require('express-graphql')
const OASGraph = require('oasgraph') // use real name here
const app = express()
OASGraph.createGraphQlSchema(oas)
.then(({schema}) => {
app.use('/graphql', graphqlHTTP({
schema,
graphiql: true
}))
app.listen(3001)
})
.catch(err => {
// handle errors when creating the schema
})
参考资料
https://www.npmjs.com/package/oasgraph
https://github.com/strongloop/oasgraph
http://v4.loopback.io/getting-started-oasgraph.html
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
2015-10-26 messagepcak 资料