Skip to content

Instantly share code, notes, and snippets.

@jeff-french
Created April 14, 2017 21:23
Show Gist options
  • Save jeff-french/39afeab353b24388c1243eba9f3ae97e to your computer and use it in GitHub Desktop.
Save jeff-french/39afeab353b24388c1243eba9f3ae97e to your computer and use it in GitHub Desktop.
Swagger with merges
var resolve = require('json-refs').resolveRefs;
var YAML = require('yaml-js');
var fs = require('fs');
var root = YAML.load(fs.readFileSync('index.yml').toString());
var options = {
filter : ['relative', 'remote'],
loaderOptions : {
processContent : function (res, callback) {
callback(null, YAML.load(res.text));
}
}
};
resolve(root, options).then(function (results) {
fs.writeFileSync('public/swagger.json', JSON.stringify(results.resolved, null, 2));
});
DefaultResponse: &defaultResponse
400:
$ref: "common.yml#/responses/BadRequest"
401:
$ref: "common.yml#/responses/NotAuthorized"
403:
$ref: "common.yml#/responses/Forbidden"
404:
$ref: "common.yml#/responses/NotFound"
500:
$ref: "common.yml#/responses/InternalServerError"
purchases:
get:
tags:
- Purchases
summary: Returns a list of purchases for the current user.
responses:
<<: *defaultResponse
200:
description: OK
schema:
type: array
items:
$ref: "#/definitions/Purchase"
post:
tags:
- Purchases
summary: Creates a new purchase.
description: >
Creates a new purchase that consists of the Item and Warranties
in the request body. If the Item or Warranties include an id
then the corresponding pre-existing resource is used. If the
id field is missing then the corresponding resource will be
created.
parameters:
- name: purchase
in: body
description: purchase to add
required: true
schema:
$ref: "#/definitions/Purchase"
responses:
<<: *defaultResponse
201:
description: OK
schema:
$ref: "#/definitions/Purchase"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment