Coder Social home page Coder Social logo

generate-it-mockers's Introduction

generate-it-mockers

This package works in conjunction with generate-it to automatically return mocked responses from a domain method based on the model defined in a JSON Schema derived from swagger/openapi definitions.

Please review the documentation here: https://acrontum.github.io/generate-it-mockers/


Generate-It-Mockers is an opensourced project from acrontum, tested on the current NodeJS LTS release.

generate-it-mockers's People

Contributors

p-mcgowan avatar acrontum-revah avatar acrontum-carmichael avatar

Watchers

James Cloos avatar  avatar  avatar Santiago Sanchez avatar

generate-it-mockers's Issues

[BUG] throws if an object does not have `properties` key

with path delete model:

summary: Things
description: Create a thing
parameters:
  - $ref: "#/parameters/PathThingName"
responses:
  "200":
    description: success
    schema:
      type: object
      additionalProperties: true
  "404":
    description: Not found

generated mockers are:

async thingsNameDelete(pathParams: ThingsNameDeletePath): Promise<any> {
  return mockItGenerator({ type: 'object', additionalProperties: true });
}

and the resulting error when calling generator with that object:

TypeError: Cannot convert undefined or null to object
    at Function.keys (<anonymous>)
    at walker (myRepo/node_modules/generate-it-mockers/generators/mockItGenerator.js:38:14)
    at Object.<anonymous>.module.exports [as mockItGenerator] (myRepo/node_modules/generate-it-mockers/generators/mockItGenerator.js:52:10)
    at ThingsDomainMock.thingsNameDelete (myRepo/src/domains/__mocks__/ThingsDomainMock.ts:107:18)
    at ThingsDomain.thingsNameDelete (myRepo/src/domains/ThingsDomain.ts:42:41)
    at myRepo/src/http/nodegen/routes/thingsRoutes.ts:75:29
    at handleReturn (myRepo/node_modules/express-promise-router/lib/express-promise-router.js:24:27)
    at myRepo/node_modules/express-promise-router/lib/express-promise-router.js:56:9
    at handleReturn (myRepo/node_modules/express-promise-router/lib/express-promise-router.js:24:27)
    at myRepo/node_modules/express-promise-router/lib/express-promise-router.js:56:9

refering to line 38 in the generator

    case 'object':
      let obj = {}
      Object.keys(schema.properties).forEach((key) => {
        obj[key] = walker(schema.properties[key], key)
      })
      return obj
  }

Mock enum types

eg:

in: query
name: sortBy
type: string
required: false
enum:
  - name
  - from
  - to
  - id

mock should generate a string which is one of the possible values

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.