I have my yaml files split up according to a structure like this:
.
├── index.yaml
├── info
│ └── index.yaml
├── definitions
│ └── index.yaml
│ └── User.yaml
└── paths
├── index.yaml
├── bar.yaml
└── foo.yaml
index.yaml:
swagger: '2.0'
info:
$ref: ./info/index.yaml
paths:
$ref: ./paths/index.yaml
definitions:
$ref: ./definitions/index.yaml
info/index.yaml:
version: 1.0.0
title: Service API
definitions/index.yaml
User:
$ref: ./User.yaml
definitions/User.yaml
type: object
properties:
name:
type: string
...and so on (but you get the idea). I followed the guidance of a blog post that did exactly this. So before calling initializeMiddleware
from the swagger-tools
library, my understanding is that I need to merge all these yaml files into a single file. I tried doing that the way @mohsen____ describes in his blog, leveraging the json-refs
library and calling the resolveRefs
(or resolveRefsAt
) function to get a promise-ified response object that contains a version of the document with the JSON references resolved. This doesn't seem to work though. When I try the following nothing gets logged to the console:
let options = {
filter: ['relative', 'remote']
};
jsonRefs.resolveRefsAt('./swagger/index.yaml', options)
.then(function (res): any {
console.dir(res);
console.log(JSON.stringify(res.resolved, null, 2));
}, (err) => {
console.error(err);
});