mohsen1 / multi-file-swagger-example

Multi-file Swagger example
http://azimi.me/2015/07/16/split-swagger-into-smaller-files.html
168 stars 39 forks source link

Upgrade json-refs dependency - fixes #6 #7

Closed floydpink closed 8 years ago

floydpink commented 8 years ago

adapt to the breaking changes in json-refs API

There were a couple of breaking changes introduced in v2.0.0 in json-refs as detailed here.

The options.processContent callback needs to be nested as options.loaderOptions.processContent as there is a new module (path-loader) that is doing the content loading and also, it has a new signature to enable asynchronous processing of content done by a callback that needs to be called (details are at https://github.com/whitlockjc/path-loader/issues/7).

Another new option that is added (filter : ['relative', 'remote']) enables retaining the local references (like the schema for 200 within responses below - which is retained as "$ref": "#/definitions/User"), since it is a local reference that is not supplied in the filter (details about the filter option is here).

Below is how the result now looks with the updated code and dependencies:

{
  "swagger": "2.0",
  "info": {
    "version": "0.0.0",
    "title": "Simple API"
  },
  "paths": {
    "/foo": {
      "get": {
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/bar": {
      "get": {
        "responses": {
          "200": {
            "description": "OK",
            "schema": {
              "$ref": "#/definitions/User"
            }
          }
        }
      }
    }
  },
  "definitions": {
    "User": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string"
        }
      }
    }
  }
}
mohsen1 commented 8 years ago

Thank you!