Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug Fix]: CORS Issue - Monaco editor #48

Merged
merged 45 commits into from
Apr 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
442f5d5
Add mustache package
sserrata Apr 12, 2022
c8c6fbd
Remove docs modules
sserrata Apr 12, 2022
bfb2fda
Remove sidebars modules
sserrata Apr 12, 2022
27738df
Refactor openapi module
sserrata Apr 12, 2022
e66f5fb
Cleanup options and unused types/packages; introduce outputDir and te…
sserrata Apr 12, 2022
66be8af
Extend docs types and remove unused types
sserrata Apr 12, 2022
d9c4e66
Declare plugin-content-docs-types module
sserrata Apr 12, 2022
ae7a81c
Cleanup remark-admonitions module declaration
sserrata Apr 12, 2022
a4d95ac
Cleanup plugin options and update ApiPageMetadata
sserrata Apr 12, 2022
7659373
Refactor plugin to emit mdx
sserrata Apr 12, 2022
8a02d9f
Fix @paloaltonetworks/docusaurus-theme-openapi import
sserrata Apr 12, 2022
e5d67af
Refactor plugin to write mdx files to plugin-content-docs path
sserrata Apr 12, 2022
fdf081a
Refactor to support new plugin
sserrata Apr 12, 2022
868c83f
Add @docusaurus/plugin-content-docs-types declaration
sserrata Apr 12, 2022
f324a05
Comment out VSCode to avoid cross-origin errors
sserrata Apr 12, 2022
f1e3b9b
Add @ts-ignore as workaround
sserrata Apr 12, 2022
c63cb6d
Remove ApiPage component
sserrata Apr 12, 2022
79a2ca0
Refactor to support additional plugin-content-docs features
sserrata Apr 12, 2022
a836a28
Update yarn.lock
sserrata Apr 12, 2022
a90af10
Comment out unused imports/vars
sserrata Apr 12, 2022
7492f5b
Add API md/mdx files to gitignore
sserrata Apr 13, 2022
10673b3
Generate md/mdx before loadContent() life cycle method
sserrata Apr 13, 2022
cf144b1
Rename cos and routeBasePath
sserrata Apr 13, 2022
dc311ff
Update cypress tests
sserrata Apr 13, 2022
df14045
Fix navbar links
sserrata Apr 13, 2022
3e94e4d
Cleanup apiSidebars
sserrata Apr 13, 2022
2c15ca9
Update gitignore
sserrata Apr 13, 2022
7c998af
Add cleanApiDocs script
sserrata Apr 13, 2022
04b4060
Rename info doc to index.mdx
sserrata Apr 13, 2022
ac3acab
Render TOC for all non-api docs
sserrata Apr 13, 2022
9906e5d
Add non-API doc examples
sserrata Apr 13, 2022
ccb9d53
Remove examples
sserrata Apr 13, 2022
45d5a90
Add sidebar_class_name to mustache template
sserrata Apr 13, 2022
6acca1e
Fix heading level in info description to allow TOC
sserrata Apr 13, 2022
340d83f
Hide TOC for api docs
sserrata Apr 13, 2022
594d766
Respect hideTableOfContents
sserrata Apr 13, 2022
57a167a
Define openapi-code variables with ifm values
blindaa121 Apr 13, 2022
0fc71ea
Import monaco-editor and add support for rgb and shortened hex values
blindaa121 Apr 13, 2022
7a7ad06
Uncomment VSCode component
blindaa121 Apr 13, 2022
3a13c49
Merge branch 'refactor-plugin' of https://github.com/PaloAltoNetworks…
blindaa121 Apr 13, 2022
91a3e0f
Satisfy linter
blindaa121 Apr 14, 2022
1717327
Implement useMonaco hook
blindaa121 Apr 14, 2022
b363037
Trigger workflows
blindaa121 Apr 14, 2022
dd92846
Remove comment
blindaa121 Apr 14, 2022
ad2c8b7
Change monaco type to any
blindaa121 Apr 14, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,6 @@ dist

# TernJS port file
.tern-port

# demo API MDX files
demo/api/**/*.mdx
33 changes: 2 additions & 31 deletions cypress/integration/test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,41 +8,12 @@
describe("test", () => {
it("loads Petstore page", () => {
cy.viewport("macbook-15");
cy.visit("/petstore");
cy.visit("/api/petstore");
navTo(
[/^pet$/i, /add a new pet to the store/i],
[/^petstore$/i, /add a new pet to the store/i],
/add a new pet to the store/i
);
});

it("loads Cloud Object Storage page", () => {
cy.viewport("macbook-15");
cy.visit("/cos");
navTo([], /generating an iam token/i);
});

it("loads Multi-spec page", () => {
cy.viewport("macbook-15");
cy.visit("/multi-spec");
navTo(
[
/foods/i,
/burger store/i,
/burger example/i,
/^api$/i,
/list all burgers/i,
],
/list all burgers/i
);
});

it("loads a page with authentication", () => {
cy.visit("/cos/list-buckets");
cy.findByRole("button", { name: /authorize/i }).should("exist");

cy.visit("/cos/create-a-bucket");
cy.findByRole("button", { name: /authorize/i }).should("exist");
});
});

/**
Expand Down
4 changes: 4 additions & 0 deletions demo/api/cos/_category_.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"label": "IBM Cloud Object Storage",
"collapsed": true
}
9 changes: 9 additions & 0 deletions demo/api/first.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
id: first
sidebar_label: First Doc
sidebar_position: 1
---

## This doc comes first

This doc supercedes all other docs in the sidebar.
4 changes: 4 additions & 0 deletions demo/api/food/_category_.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"label": "Food",
"collapsed": true
}
4 changes: 4 additions & 0 deletions demo/api/food/burgers/_category_.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"label": "Burgers",
"collapsed": true
}
4 changes: 4 additions & 0 deletions demo/api/food/yogurtstore/_category_.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"label": "Yogurt Store",
"collapsed": true
}
4 changes: 4 additions & 0 deletions demo/api/openapi-issue/_category_.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"label": "OpenAPI Issue",
"collapsed": true
}
4 changes: 4 additions & 0 deletions demo/api/petstore/_category_.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"label": "Petstore",
"collapsed": true
}
9 changes: 9 additions & 0 deletions demo/api/petstore/first.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
id: before-petstore
sidebar_label: Before Petstore API
sidebar_position: 1
---

## This is only a test!

This is how you would "front load" a non-API doc.
9 changes: 9 additions & 0 deletions demo/api/second.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
id: second
sidebar_label: Second Doc
sidebar_position: 2
---

## This doc comes second

This doc comes after the first doc.
19 changes: 19 additions & 0 deletions demo/apiSidebars.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Creating a sidebar enables you to:
- create an ordered group of docs
- render a sidebar for each doc of that group
- provide next/previous navigation

The sidebars can be generated from the filesystem, or explicitly defined here.

Create as many sidebars as you want.
*/

/** @type {import('@docusaurus/plugin-content-docs').SidebarsConfig} */
const sidebars = {
// By default, Docusaurus generates a sidebar from the api folder structure
// openApiSidebar: require("./api/sidebar").sidebar,
openApiSidebar: [{ type: "autogenerated", dirName: "." }],
};

module.exports = sidebars;
116 changes: 73 additions & 43 deletions demo/docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,73 +8,103 @@ const darkCodeTheme = require("prism-react-renderer/themes/dracula");
const config = {
title: "Docusaurus OpenAPI",
tagline: "OpenAPI plugin for generating API reference docs in Docusaurus v2.",
url: "https://docusaurus-openapi.netlify.app",
url: "https://docusaurus-openapi.tryingpan.dev",
baseUrl: "/",
onBrokenLinks: "warn",
onBrokenMarkdownLinks: "warn",
favicon: "img/favicon.ico",
organizationName: "cloud-annotations", // Usually your GitHub org/user name.
organizationName: "PaloAltoNetworks", // Usually your GitHub org/user name.
projectName: "docusaurus-openapi", // Usually your repo name.

presets: [
[
"@paloaltonetworks/docusaurus-preset-openapi",
/** @type {import('@paloaltonetworks/docusaurus-preset-openapi').Options} */
({
api: {
path: "examples/petstore.yaml",
routeBasePath: "petstore",
beforeApiDocs: [
"examples/test.md",
"examples/test2.mdx",
"examples/test3.md",
],
},
"@docusaurus/preset-classic",
{
docs: {
sidebarPath: require.resolve("./sidebars.js"),
// Please change this to your repo.
editUrl:
"https://github.com/cloud-annotations/docusaurus-openapi/edit/main/demo/",
"https://github.com/facebook/docusaurus/edit/master/website/",
},
blog: {
showReadingTime: true,
// Please change this to your repo.
editUrl:
"https://github.com/facebook/docusaurus/edit/master/website/blog/",
},
blog: false,
theme: {
customCss: require.resolve("./src/css/custom.css"),
},
proxy: {
"/proxy": {
target: "http://localhost:8091",
pathRewrite: { "^/proxy": "" },
},
},
}),
},
],
],

plugins: [
[
"@paloaltonetworks/docusaurus-plugin-openapi",
{
id: "petstore",
path: "examples/petstore.yaml",
outputDir: "api/petstore",
},
],
[
"@paloaltonetworks/docusaurus-plugin-openapi",
{
id: "cos",
path: "examples/openapi-cos.json",
routeBasePath: "cos",
beforeApiDocs: ["examples/test.md", "examples/test2.mdx"],
outputDir: "api/cos",
},
],
[
"@paloaltonetworks/docusaurus-plugin-openapi",
{
id: "openapi-issue",
path: "examples/openapi-issue-21.json",
outputDir: "api/openapi-issue",
},
],
[
"@paloaltonetworks/docusaurus-plugin-openapi",
{
id: "burgers",
path: "examples/food/burgers/openapi.yaml",
outputDir: "api/food/burgers",
},
],
[
"@paloaltonetworks/docusaurus-plugin-openapi",
{
id: "multi-spec",
path: "examples",
routeBasePath: "multi-spec",
showExecuteButton: false,
showManualAuthentication: false,
id: "yogurt",
path: "examples/food/yogurtstore/openapi.yaml",
outputDir: "api/food/yogurtstore",
},
],
// [require.resolve("./plugins/webpackOptimizer"), {}],
[
"@docusaurus/plugin-content-docs",
{
id: "openapi",
path: "api",
breadcrumbs: true,
routeBasePath: "api",
include: ["**/*.md", "**/*.mdx"],
sidebarPath: "apiSidebars.js",
docLayoutComponent: "@theme/DocPage", // This solves the providers issue and drop the need for ApiPage component
docItemComponent: "@theme/ApiItem", // Will probably need to clean this up/refactor to get it fully updated
remarkPlugins: [],
rehypePlugins: [],
beforeDefaultRemarkPlugins: [],
beforeDefaultRehypePlugins: [],
showLastUpdateAuthor: true, // We can now add stuff like this :)
showLastUpdateTime: true,
},
],
[require.resolve("./plugins/webpackOptimizer"), {}],
],
themes: ["@paloaltonetworks/docusaurus-theme-openapi"],

themeConfig:
/** @type {import('@paloaltonetworks/docusaurus-preset-openapi').ThemeConfig} */
/** @type {import('@docusaurus/preset-classic').ThemeConfig} */
({
colorMode: {
disableSwitch: false,
Expand All @@ -97,13 +127,16 @@ const config = {
label: "Examples",
position: "left",
items: [
{ to: "/petstore/test", label: "Petstore" },
{ to: "/cos/test", label: "Cloud Object Storage" },
{ to: "/multi-spec", label: "Multi-spec" },
{ to: "/api/petstore/", label: "Petstore" },
{
to: "/api/cos/create-a-bucket",
label: "Cloud Object Storage",
},
{ to: "api/food/burgers/", label: "Food" },
],
},
{
href: "https://github.com/cloud-annotations/docusaurus-openapi",
href: "https://github.com/PaloAltoNetworks/docusaurus-openapi",
position: "right",
className: "header-github-link",
"aria-label": "GitHub repository",
Expand All @@ -113,21 +146,18 @@ const config = {
footer: {
style: "dark",
logo: {
alt: "Deploys by Netlify",
src: "https://www.netlify.com/img/global/badges/netlify-color-accent.svg",
alt: "Deploys by Firebase",
src: "https://firebase.google.com/downloads/brand-guidelines/SVG/logo-built_knockout.svg",
width: 160,
height: 51,
href: "https://www.netlify.com",
href: "https://firebase.google.com",
},
copyright: `Copyright © ${new Date().getFullYear()} Cloud Annotations. Built with Docusaurus.`,
copyright: `Copyright © ${new Date().getFullYear()} Palo Alto Networks. Built with Docusaurus.`,
},
prism: {
theme: lightCodeTheme,
darkTheme: darkCodeTheme,
},
api: {
authPersistance: "localStorage",
},
}),
};

Expand Down
8 changes: 4 additions & 4 deletions demo/examples/petstore.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,26 @@ info:
[http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/).
For this sample, you can use the api key `special-key` to test the authorization filters.

# Introduction
## Introduction
This API is documented in **OpenAPI format** and is based on
[Petstore sample](http://petstore.swagger.io/) provided by [swagger.io](http://swagger.io) team.
It was **extended** to illustrate features of [generator-openapi-repo](https://github.com/Rebilly/generator-openapi-repo)
tool and [ReDoc](https://github.com/Redocly/redoc) documentation. In addition to standard
OpenAPI syntax we use a few [vendor extensions](https://github.com/Redocly/redoc/blob/master/docs/redoc-vendor-extensions.md).

# OpenAPI Specification
## OpenAPI Specification
This API is documented in **OpenAPI format** and is based on
[Petstore sample](http://petstore.swagger.io/) provided by [swagger.io](http://swagger.io) team.
It was **extended** to illustrate features of [generator-openapi-repo](https://github.com/Rebilly/generator-openapi-repo)
tool and [ReDoc](https://github.com/Redocly/redoc) documentation. In addition to standard
OpenAPI syntax we use a few [vendor extensions](https://github.com/Redocly/redoc/blob/master/docs/redoc-vendor-extensions.md).

# Cross-Origin Resource Sharing
## Cross-Origin Resource Sharing
This API features Cross-Origin Resource Sharing (CORS) implemented in compliance with [W3C spec](https://www.w3.org/TR/cors/).
And that allows cross-domain communication from the browser.
All responses have a wildcard same-origin which makes them completely public and accessible to everyone, including any code on any site.

# Authentication
## Authentication

Petstore offers two forms of authentication:
- API Key
Expand Down
2 changes: 1 addition & 1 deletion demo/src/css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
--openapi-code-red: var(--ifm-color-danger) !important;
--openapi-code-orange: var(--ifm-color-warning) !important;
/* Helps avoid #aaa bug in monaco-editor */
--openapi-code-dim-light: var(--ifm-color-secondary-lightest) !important;
/* --openapi-code-dim-light: var(--ifm-color-secondary-lightest) !important; */
}

/* For readability concerns, you should choose a lighter palette in dark mode. */
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"release:changelog": "scripts/changelog.ts",
"release:version": "scripts/version.ts",
"release:publish": "scripts/publish.ts",
"clean": "rm -rf node_modules build demo/.docusaurus demo/build demo/node_modules && find packages -name node_modules -type d -maxdepth 2 -exec rm -rf {} + && find packages -name dist -type d -maxdepth 2 -exec rm -rf {} + && find packages -name lib -type d -maxdepth 2 -exec rm -rf {} + && find packages -name lib-next -type d -maxdepth 2 -exec rm -rf {} +"
"clean": "rm -rf node_modules build demo/.docusaurus demo/build demo/node_modules && find packages -name node_modules -type d -maxdepth 2 -exec rm -rf {} + && find packages -name dist -type d -maxdepth 2 -exec rm -rf {} + && find packages -name lib -type d -maxdepth 2 -exec rm -rf {} + && find packages -name lib-next -type d -maxdepth 2 -exec rm -rf {} +",
"cleanApiDocs": "find ./demo/api -name '*.mdx' -type f | xargs rm"
},
"devDependencies": {
"@babel/cli": "^7.16.0",
Expand Down
5 changes: 3 additions & 2 deletions packages/docusaurus-plugin-openapi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
"@docusaurus/module-type-aliases": "2.0.0-beta.17",
"@docusaurus/types": "2.0.0-beta.17",
"@types/fs-extra": "^9.0.13",
"@types/js-yaml": "^4.0.5",
"@types/json-schema": "^7.0.9",
"@types/lodash": "^4.14.176",
"@types/postman-collection": "^3.5.7",
Expand All @@ -37,14 +36,16 @@
"@docusaurus/utils-validation": "2.0.0-beta.17",
"@paloaltonetworks/openapi-to-postmanv2": "3.1.0-hotfix.1",
"@paloaltonetworks/postman-collection": "^4.1.0",
"@types/js-yaml": "^4.0.5",
"@types/mustache": "^4.1.2",
"chalk": "^4.1.2",
"clsx": "^1.1.1",
"fs-extra": "^9.0.1",
"js-yaml": "^4.1.0",
"json-refs": "^3.0.15",
"json-schema-merge-allof": "^0.8.1",
"lodash": "^4.17.20",
"remark-admonitions": "^1.2.1",
"mustache": "^4.2.0",
"webpack": "^5.61.0"
},
"peerDependencies": {
Expand Down
Loading