npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

swagger-fixtures

v1.0.2

Published

swagger-fixtures, generate a test fixture from the definition properties examples in your swagger doc

Downloads

20

Readme

swagger-fixtures

Build Status

Introduction

swagger-fixtures, generate a test fixture from the definitions, property examples in your swagger document.

Swagger/Open API Specification

Swagger, allows you to define within your swagger document, examples, this module will grab those property examples and construct a json object.

If a property has no example, we set this to null.

Supports, swagger types:

object
array
boolean
string
number
integer
ref

Install

npm install swagger-fixtures

Usage

const swagger = require('./swagger.json');
const swaggerFixture = require('swagger-fixtures');
const fixture = swaggerFixture(swagger, 'User');

Based on the below swagger doc, we will get an object like so, which can be used as a test fixture:

const fixture = {
  id: '12345',
  username: 'airasoul',
  firstName: 'andrew',
  lastName: 'keig',
  email: '[email protected]',
  password: 'password',
  userStatus: '1',
  bornDay: 'Monday',
  dimensions: { weight: 180, height: 120 },
  isHappy: false,
  phones: [{ number: '07943818181' }],
  address: { street: 'no 4', postcode: 'w1' },
};

Example swagger doc:

{
  "definitions": {
    "Address": {
      "type": "object",
      "properties": {
        "street": {
          "type": "string",
          "example": "no 4"
        },
        "postcode": {
          "type": "string",
          "example": "w1"
        }
      }
    },
    "DayOfWeek": {
      "title": "DayOfWeek",
      "description": "Day of the Week",
      "type": "string",
      "example": "Monday",
      "enum": ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
    },
    "User": {
      "type": "object",
      "properties": {
        "id": {
          "type": "integer",
          "format": "int64",
          "example": "12345"
        },
        "username": {
          "type": "string",
          "example": "airasoul"
        },
        "firstName": {
          "type": "string",
          "example": "andrew"
        },
        "lastName": {
          "type": "string",
          "example": "keig"
        },
        "email": {
          "type": "string",
          "example": "[email protected]"
        },
        "password": {
          "type": "string",
          "example": "password"
        },
        "isHappy": {
          "description": "Set it to True andrew is happy.",
          "example": false,
          "type": "boolean",
          "default": false
        },
        "bornDay": {
          "$ref": "#/definitions/DayOfWeek"
        },
        "address": {
          "$ref": "#/definitions/Address"
        },
        "phones": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "number": {
                "description": "List of phone numbers",
                "example": "07943818181",
                "type": "string"
              }
            }
          }
        },
        "dimensions": {
          "type": "object",
          "properties": {
            "weight": {
              "description": "weight in kg",
              "example": 180,
              "type": "number"
            },
            "height": {
              "description": "height in metres",
              "example": 120,
              "type": "number"
            }
          }
        },
        "userStatus": {
          "type": "integer",
          "format": "int32",
          "description": "User Status",
          "example": "1"
        }
      }
    }
  }
}

Test

npm test

Lint

npm run lint

coverage

npm run coverage