docusaurus-plugin-openapi-docs
Version:
OpenAPI plugin for Docusaurus.
82 lines (81 loc) • 3.75 kB
JavaScript
"use strict";
/* ============================================================================
* Copyright (c) Palo Alto Networks
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
* ========================================================================== */
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const path_1 = __importDefault(require("path"));
// eslint-disable-next-line import/no-extraneous-dependencies
const utils_1 = require("@docusaurus/utils");
const _1 = require(".");
const openapi_1 = require("./openapi");
// npx jest packages/docusaurus-plugin-openapi/src/openapi/openapi.test.ts --watch
describe("openapi", () => {
describe("readOpenapiFiles", () => {
it("readOpenapiFiles", async () => {
var _a, _b;
const results = await (0, _1.readOpenapiFiles)((0, utils_1.posixPath)(path_1.default.join(__dirname, "__fixtures__/examples")));
const categoryMeta = results.find((x) => x.source.endsWith("_category_.json"));
expect(categoryMeta).toBeFalsy();
// console.log(results);
const yaml = results.find((x) => x.source.endsWith("openapi.yaml"));
expect(yaml).toBeTruthy();
expect(yaml === null || yaml === void 0 ? void 0 : yaml.sourceDirName).toBe(".");
expect(yaml === null || yaml === void 0 ? void 0 : yaml.data.tags).toBeDefined();
expect(yaml === null || yaml === void 0 ? void 0 : yaml.data["x-tagGroups"]).toBeDefined();
expect((_b = (_a = yaml === null || yaml === void 0 ? void 0 : yaml.data.components) === null || _a === void 0 ? void 0 : _a.schemas) === null || _b === void 0 ? void 0 : _b.HelloString["x-tags"]).toBeDefined();
});
});
describe("schemasOnly", () => {
it("includes schema metadata when showSchemas is disabled", async () => {
const openapiData = {
openapi: "3.0.0",
info: {
title: "Schema Only",
version: "1.0.0",
},
paths: {
"/ping": {
get: {
summary: "Ping",
responses: {
"200": {
description: "OK",
},
},
},
},
},
components: {
schemas: {
WithoutTags: {
title: "Without Tags",
type: "object",
properties: {
value: {
type: "string",
},
},
},
},
},
};
const options = {
specPath: "dummy", // required by the type but unused in this context
outputDir: "build",
showSchemas: false,
schemasOnly: true,
};
const sidebarOptions = {};
const [items] = await (0, openapi_1.processOpenapiFile)(openapiData, options, sidebarOptions);
const schemaItems = items.filter((item) => item.type === "schema");
expect(schemaItems).toHaveLength(1);
expect(schemaItems[0].id).toBe("without-tags");
});
});
});