Giter Site home page Giter Site logo

lisanchuan / swagger-parser-mock Goto Github PK

View Code? Open in Web Editor NEW

This project forked from easy-mock/swagger-parser-mock

0.0 2.0 0.0 66 KB

一个简单的 Swagger 文档解析器,支持生成演示数据与数据实体类。

License: MIT License

JavaScript 100.00%

swagger-parser-mock's Introduction

Swagger Parser Mock

npm version

一个简单的 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))
  // =>
  /**
   * { id: '@integer(60, 100)',
   *   petId: '@integer(60, 100)',
   *   quantity: '@integer(60, 100)',
   *   shipDate: '@datetime',
   *   status: 'placed',
   *   complete: '@boolean' }
   */
})

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)
  // =>
  /**
   * class Order {
   *   constructor() {
   *     this.id = 0;
   *     this.petId = 0;
   *     this.quantity = 0;
   *     this.shipDate = '';
   *     this.status = '';
   *     this.complete = false;
   *   }
   * }
   */
})

getObjectiveCEntities(schema)

// ...
specs.then(docs => {
  const api = docs.paths['/store/order']['post']
  const orderEntity = getObjectiveCEntities(api.responses['200'])[0]
  console.log(orderEntity)
  // =>
  /**
   * @interface Order : NSObject
   * @property (nonatomic, strong) NSNumber *id;
   * @property (nonatomic, strong) NSNumber *petId;
   * @property (nonatomic, strong) NSNumber *quantity;
   * @property (nonatomic, copy) NSString *shipDate;
   * @property (nonatomic, copy) NSString *status;
   * @property (nonatomic, assign) BOOL complete;
   * @end
   */
})

License

MIT

swagger-parser-mock's People

Contributors

chuangker avatar

Watchers

James Cloos avatar Sanchuan Li avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.