Swagger Express Middleware

Swagger 2.0 middlware and mocks for Express.js

The DataStore abstract class

The Mock middleware uses DataStore classes to store its data, and you can use the DataStore API to to add/modify/remove this mock data, which is very handy for demos and POCs. Refer to the Mock middleware documentation to find out how to specify which DataStore class is used. Refer to the Sample 2 walkthrough to see how to initialize the data store with data.

TIP: This is an abstract base class, which means you should not use this class directly. Instead, you should use one of its child classes: MemoryDataStore or FileDataStore. Or, if you want to store your data somewhere else — such as a SQL database, a Cloud service, etc. — then you can create your own child class that inherits from DataStore.

Methods

get(resource, callback)

Returns the specified resource from the data store

save(resource1, resource2, ..., callback)

Saves the specified resource(s) to the data store. If any of the resources already exist, the new data is merged with the existing data.

delete(resource1, resource2, ..., callback)

Deletes the specified resource(s) from the data store.

getCollection(collection, callback)

Returns all resources in the specified collection

deleteCollection(collection, callback)

Deletes all resources in the specified collection