public static function getSwaggerDocument($id, $host)
    {
        // load document from filesystem
        $filePath = CACHE . self::$filePrefix . $id . '.json';
        if (!Configure::read('Swagger.docs.crawl')) {
            if (!file_exists($filePath)) {
                throw new NotFoundException("Swagger json document was not found on filesystem: $filePath");
            }
            $fh = new File($filePath);

            return $fh->read();
        }

        // otherwise crawl-generate a fresh document
        $swaggerOptions = [];
        if (Configure::read("Swagger.library.$id.exclude")) {
            $swaggerOptions = [
                'exclude' => Configure::read("Swagger.library.$id.exclude")
            ];
        }
        if (Configure::read('Swagger.analyser')) {
            $swaggerOptions['analyser'] = Configure::read('Swagger.analyser');
        }
        $swagger = \Swagger\scan(Configure::read("Swagger.library.$id.include"), $swaggerOptions);

        // set object properties required by UI to generate the BASE URL
        $swagger->host = $host;
        if (empty($swagger->basePath)) {
            $swagger->basePath = '/' . Configure::read('App.base');
        }
        $swagger->schemes = Configure::read('Swagger.ui.schemes');

        // write document to filesystem
        self::writeSwaggerDocumentToFile($filePath, $swagger);

        return $swagger;
    }