Giter Club home page Giter Club logo

swagger-mock-server's Introduction

swagger-mock-server

Swagger mock server based on akka-http

Experimental project for auto-generating mock-server from Swagger spec

  • using akka-http static build the route from the swagger file ..
  • using yod-mock to generate mock data

Feature

  • add x-yod-type on definitions can specify the generate behavior
 properties:
      id:
        type: integer
        format: int32
        description: key
        x-yod-type: '@Int(50, 100)'

or can aware of the type-name from the response schema which is defined by x-yod-name

 responses:
   '200':
    description: real bank
    schema:
      type: array
      x-yod-name: bank
      items:
      $ref: '#/definitions/GeneralItem'
      
...


 GeneralItem:
    description: Tuple[integer, String]
    type: object
    properties:
      id:
        type: integer
        format: int32
        description: key
      name:
        type: string
        description: name
        x-yod-type:
          bank: '@(["**银行", "工商银行", "农业银行", "建设银行", "交通银行"]).sample @([沪太路支行, 五角场支行]).sample'

support size&page context

context var is a string start with '$'

  • size: the request size
  • page: the request page
  • max: max of the mock data
 x-yod-array:
    size: '$size'
    page: '$page'
    max: 100

support chance to return a response definitions object

once you define a reponse definiitons object with following extentions

responses:
  GeneralError:
    description: Entity not found
    schema:
      $ref: "#/definitions/Response"
    x-is-global: true
    x-chance: 0.2
    x-status-code: 503
  GeneralResponse:
    description: General Response
    schema:
      $ref: "#/definitions/Response"

  • x-is-global will make other extentions to work accept true/false
  • x-chance a chance that response will take place if multiply responsese have been defined take the first in order
  • x-status-code bind the response object to a fixed HttpStatusCode

How to Start

  • prepare your swagger spec file xxx.yml
  • build this project
mvn clean install
  • run with java
java -jar mock-server-1.0-snapshot.jar path-to-file port

TODO

  • Bind Context to the Response to build context-based Response
  • make the refactor ..lame code
  • pass the Swagger test (Done with my own yaml file)

swagger-mock-server's People

Contributors

mumutu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

scaltoy mumutu66

swagger-mock-server's Issues

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.