1
0
mirror of https://github.com/matrix-org/matrix-authentication-service.git synced 2025-07-29 22:01:14 +03:00

Host a Swagger UI both in the static documentation and by the server

This commit is contained in:
Quentin Gliech
2024-07-26 17:09:42 +02:00
parent 70222eeb19
commit 3f947025e2
16 changed files with 2713 additions and 106 deletions

File diff suppressed because it is too large Load Diff

View File

@ -37,6 +37,7 @@
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-i18next": "^14.1.2",
"swagger-ui-react": "^5.17.14",
"urql": "^4.1.0",
"vaul": "^0.9.1",
"zod": "^3.23.8"
@ -60,6 +61,7 @@
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"@types/react-test-renderer": "^18.3.0",
"@types/swagger-ui-react": "^4.18.3",
"@vitejs/plugin-react": "^4.3.1",
"@vitest/coverage-v8": "^1.6.0",
"autoprefixer": "^10.4.19",

35
frontend/src/swagger.tsx Normal file
View File

@ -0,0 +1,35 @@
// Copyright 2024 The Matrix.org Foundation C.I.C.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import { createRoot } from "react-dom/client";
import SwaggerUI from "swagger-ui-react";
import "swagger-ui-react/swagger-ui.css";
type ApiConfig = {
openapiUrl: string;
callbackUrl: string;
};
interface IWindow {
API_CONFIG?: ApiConfig;
}
const config = typeof window !== "undefined" && (window as IWindow).API_CONFIG;
if (!config) {
throw new Error("API_CONFIG is not defined");
}
createRoot(document.getElementById("root") as HTMLElement).render(
<SwaggerUI url={config.openapiUrl} oauth2RedirectUrl={config.callbackUrl} />,
);

View File

@ -65,6 +65,7 @@ export default defineConfig((env) => ({
resolve(__dirname, "src/main.tsx"),
resolve(__dirname, "src/shared.css"),
resolve(__dirname, "src/templates.css"),
resolve(__dirname, "src/swagger.tsx"),
],
},
},