Skip to content

Commit 6edb4a8

Browse files
authored
Add better auth support (#74)
1 parent 5589ad7 commit 6edb4a8

File tree

29 files changed

+816
-369
lines changed

29 files changed

+816
-369
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ cypress/screenshots
55
# Dist
66
build
77
dist
8+
lib
9+
lib-next
810

911
# Dependencies
1012
/node_modules

cypress/integration/test.spec.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,29 @@ describe("test", () => {
1313
it("renders query parameters", () => {
1414
cy.findByText(/query parameters/i).should("exist");
1515
});
16+
17+
it("loads when clicking on tabs", () => {
18+
cy.on("uncaught:exception", () => {
19+
// there is an uncaught error trying to load monaco in ci
20+
return false;
21+
});
22+
23+
function checkTab(tab: RegExp, heading: RegExp) {
24+
cy.get(".navbar").findByRole("link", { name: tab }).click();
25+
cy.findByRole("heading", { name: heading, level: 1 }).should("exist");
26+
}
27+
28+
checkTab(/issue 21/i, /missing summary/i);
29+
checkTab(/cos/i, /generating an iam token/i);
30+
checkTab(/yaml/i, /hello world/i);
31+
checkTab(/api/i, /recursive/i);
32+
});
33+
34+
it("loads a page with authentication", () => {
35+
cy.visit("/cos/list-buckets");
36+
cy.findByRole("button", { name: /authorize/i }).should("exist");
37+
38+
cy.visit("/cos/create-a-bucket");
39+
cy.findByRole("button", { name: /authorize/i }).should("exist");
40+
});
1641
});

demo/docusaurus.config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,9 @@ const config = {
146146
theme: lightCodeTheme,
147147
darkTheme: darkCodeTheme,
148148
},
149-
proxy: "https://cors-anywhere.herokuapp.com",
149+
api: {
150+
authPersistance: "localStorage",
151+
},
150152
}),
151153
};
152154

demo/examples/openapi-cos.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@
6868
"schema": { "type": "string" }
6969
}
7070
],
71+
"security": [
72+
{ "BearerAuth": [] },
73+
{ "BearerAuth": [], "BasicAuth": [] }
74+
],
7175
"responses": { "200": { "description": "ok" } }
7276
}
7377
},
@@ -133,7 +137,10 @@
133137
}
134138
},
135139
"components": {
136-
"securitySchemes": { "BearerAuth": { "type": "http", "scheme": "bearer" } },
140+
"securitySchemes": {
141+
"BearerAuth": { "type": "http", "scheme": "bearer" },
142+
"BasicAuth": { "type": "http", "scheme": "basic" }
143+
},
137144
"schemas": {
138145
"AuthForm": {
139146
"type": "object",

package.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,23 @@
2222
"release:changelog": "scripts/changelog.ts",
2323
"release:version": "scripts/version.ts",
2424
"release:publish": "scripts/publish.ts",
25-
"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 {} +"
25+
"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 {} +"
2626
},
2727
"devDependencies": {
28+
"@babel/cli": "^7.16.0",
29+
"@babel/core": "^7.16.0",
30+
"@babel/eslint-parser": "^7.16.3",
31+
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.16.0",
32+
"@babel/plugin-proposal-optional-chaining": "^7.16.0",
33+
"@babel/plugin-transform-modules-commonjs": "^7.16.0",
34+
"@babel/preset-typescript": "^7.16.0",
2835
"@testing-library/cypress": "^8.0.1",
2936
"@types/jest": "^27.0.2",
3037
"@typescript-eslint/eslint-plugin": "^4.0.0",
3138
"@typescript-eslint/parser": "^4.0.0",
3239
"babel-eslint": "^10.0.0",
3340
"cypress": "^8.7.0",
41+
"cross-env": "^7.0.3",
3442
"eslint": "^7.5.0",
3543
"eslint-config-react-app": "^6.0.0",
3644
"eslint-plugin-cypress": "^2.12.1",

packages/docusaurus-plugin-openapi/src/openapi.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,10 +231,8 @@ export async function loadOpenapi(
231231
item.security = dereffedSpec.security;
232232
}
233233

234-
// TODO: we don't want this behavior anymore, but it might break things
235-
// if (i === 0 && ii === 0) {
236-
// item.id = "/";
237-
// }
234+
// Add security schemes so we know how to handle security.
235+
item.securitySchemes = dereffedSpec.components?.securitySchemes;
238236

239237
item.permalink = normalizeUrl([baseUrl, routeBasePath, item.id]);
240238

packages/docusaurus-plugin-openapi/src/types.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,13 @@ export interface ApiItem extends OperationObject {
356356
next: Page;
357357
previous: Page;
358358
jsonRequestBodyExample: string;
359+
securitySchemes?: Map<
360+
| ApiKeySecuritySchemeObject
361+
| HttpSecuritySchemeObject
362+
| Oauth2SecuritySchemeObject
363+
| OpenIdConnectSecuritySchemeObject
364+
| ReferenceObject
365+
>;
359366
}
360367

361368
export interface Page {
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/* ============================================================================
2+
* Copyright (c) Cloud Annotations
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
* ========================================================================== */
7+
8+
module.exports = {
9+
env: {
10+
// USED FOR NODE/RUNTIME
11+
// maybe we should differenciate both cases because
12+
// we mostly need to transpile some features so that node does not crash...
13+
lib: {
14+
presets: [
15+
["@babel/preset-typescript", { isTSX: true, allExtensions: true }],
16+
],
17+
// Useful to transpile for older node versions
18+
plugins: [
19+
"@babel/plugin-transform-modules-commonjs",
20+
"@babel/plugin-proposal-nullish-coalescing-operator",
21+
"@babel/plugin-proposal-optional-chaining",
22+
],
23+
},
24+
25+
// USED FOR JS SWIZZLE
26+
// /lib-next folder is used as source to swizzle JS source code
27+
// This JS code is created from TS source code
28+
// This source code should look clean/human readable to be usable
29+
"lib-next": {
30+
presets: [
31+
["@babel/preset-typescript", { isTSX: true, allExtensions: true }],
32+
],
33+
},
34+
},
35+
};

packages/docusaurus-theme-openapi/package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@
77
"access": "public"
88
},
99
"types": "src/theme-openapi.d.ts",
10-
"main": "dist/index.js",
10+
"main": "lib/index.js",
1111
"files": [
1212
"/dist"
1313
],
1414
"scripts": {
15-
"build": "scripts/build.ts",
16-
"watch": "scripts/build.ts --watch"
15+
"build": "tsc --noEmit && yarn babel:lib && yarn babel:lib-next && yarn format:lib-next",
16+
"watch": "concurrently --names \"lib,lib-next,tsc\" --kill-others \"yarn babel:lib --watch\" \"yarn babel:lib-next --watch\" \"yarn tsc --watch\"",
17+
"babel:lib": "cross-env BABEL_ENV=lib babel src -d lib --extensions \".tsx,.ts\" --ignore \"**/*.d.ts\" --copy-files",
18+
"babel:lib-next": "cross-env BABEL_ENV=lib-next babel src -d lib-next --extensions \".tsx,.ts\" --ignore \"**/*.d.ts\" --copy-files",
19+
"format:lib-next": "prettier --config ../../.prettierrc.json --write \"lib-next/**/*.{js,ts,jsx,tsc}\""
1720
},
1821
"devDependencies": {
1922
"@docusaurus/module-type-aliases": "2.0.0-beta.9",

packages/docusaurus-theme-openapi/scripts/build.ts

Lines changed: 0 additions & 36 deletions
This file was deleted.

0 commit comments

Comments
 (0)