swagger-mock-maker
1.1.4 • Public • Published Swagger Parser Mock
一个简单的 Swagger 文档解析器,支持生成演示数据与数据实体类。
Features
- 支持 OpenAPI Specification (1.2 & 2.0 & 3.0)
- 支持为 Parameters 与 Responses 生成演示数据
- 支持根据 Schema 生成数据实体类(JavaScript/Objective-C)
API
swaggerParserMock(url, opts)
const swaggerParserMock = require('swagger-parser-mock')
const specs = swaggerParserMock('http://petstore.swagger.io/v2/swagger.json')
specs.then(docs => {
const api = docs.paths['/store/order']['post']
const example = api.responses['200'].example
console.log(JSON.parse(example))
})
getJavaScriptEntities(schema)
const swaggerParserMock = require('swagger-parser-mock')
const {
getJavaScriptEntities,
getObjectiveCEntities
} = require('swagger-parser-mock/lib/entity')
const specs = swaggerParserMock('http://petstore.swagger.io/v2/swagger.json')
specs.then(docs => {
const api = docs.paths['/store/order']['post']
const orderEntity = getJavaScriptEntities(api.responses['200'])[0]
console.log(orderEntity)
})
getObjectiveCEntities(schema)
specs.then(docs => {
const api = docs.paths['/store/order']['post']
const orderEntity = getObjectiveCEntities(api.responses['200'])[0]
console.log(orderEntity)
})
License
MIT
Package Sidebar
Install
Weekly Downloads