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

Add openapi support #698

Draft
wants to merge 20 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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: 0 additions & 3 deletions babel.config.js

This file was deleted.

12 changes: 12 additions & 0 deletions docs/integrations/rest-api.md → docs/integrations/rest-api.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,20 @@
sidebar_position: 1
---

import SwaggerUIWrapper from "../../src/components/SwaggerUiWrapper";

# REST API

Die HTTP REST API ist ein einfaches Interface um automatisiert Einstellungen zu ändern.
Diese Schnittstelle wird auch von der Weboberfläche genutzt.

<SwaggerUIWrapper
url="/rest-api.yaml"
showCommonExtensions
displayRequestDuration
defaultModelsExpandDepth={-1}
/>

Alle API IDs (z.B. die Loadpoint ID) beginnen bei `1`.

## State
Expand Down
1,560 changes: 1,552 additions & 8 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
"version": "0.0.0",
"private": true,
"scripts": {
"generate": "node src/generateFromTemplate.js",
"generate": "node src/generateFromTemplate.js && node src/copySwaggerStyles.js",
"docusaurus": "docusaurus",
"start": "npm run generate && docusaurus start",
"restart": "npm run clear && npm run start",
"start:en": "npm run start -- --locale en",
"build": "npm run generate && docusaurus build",
"swizzle": "docusaurus swizzle",
Expand All @@ -17,7 +18,7 @@
"write-heading-ids": "docusaurus write-heading-ids"
},
"dependencies": {
"@docusaurus/core": "^3.0.1",
"@docusaurus/core": "^3.6.3",
"@docusaurus/faster": "^3.6.1",
"@docusaurus/plugin-client-redirects": "^3.5.2",
"@docusaurus/preset-classic": "^3.0.1",
Expand All @@ -30,6 +31,7 @@
"mdx-mermaid": "^2.0.0",
"prism-react-renderer": "^2.3.1",
"raw-loader": "^4.0.2",
"swagger-ui-react": "^5.18.2",
"url-loader": "^4.1.1"
},
"browserslist": {
Expand All @@ -48,4 +50,4 @@
"prettier": "^3.1.1",
"trim": ">=0.0.3"
}
}
}
45 changes: 45 additions & 0 deletions src/components/SwaggerUIWrapper.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import React, { useRef, useEffect } from "react";
import ReactDOM from "react-dom";
import SwaggerUI from "swagger-ui-react";

const customCss = `
@import url('/swagger-ui.css');
.swagger-ui .information-container {
display: none;
}
.swagger-ui .scheme-container {
box-shadow: none;
background-color: transparent;
}
.swagger-ui .wrapper {
padding: 0;
}
.swagger-ui .copy-to-clipboard {
transition: none !important;
}
`;

export default (props) => {
const containerRef = useRef(null);

useEffect(() => {
if (containerRef.current?.attachShadow) {
try {
const shadowRoot = containerRef.current.attachShadow({ mode: "open" });
const style = document.createElement("style");
style.textContent = customCss;
shadowRoot.appendChild(style);

const div = document.createElement("div");
shadowRoot.appendChild(div);

const root = ReactDOM.createRoot(div);
root.render(<SwaggerUI {...props} />);
} catch (e) {
console.error(e);
}
}
}, [props]);

return <div ref={containerRef}></div>;
};
9 changes: 9 additions & 0 deletions src/copySwaggerStyles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const fs = require("fs");
const path = require("path");

fs.copyFileSync(
path.join(__dirname, "../node_modules/swagger-ui-react/swagger-ui.css"),
path.join(__dirname, "../static/swagger-ui.css"),
);

console.log("Copied swagger-ui.css to static directory");
2 changes: 1 addition & 1 deletion src/generateFromTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ function generateMarkdown(data, type, translations, target) {
const content = fs
.readFileSync(target, "utf-8")
.replace(
new RegExp(`${escapeRegExp(AUTOGEN_MARKER)}(.|\n)*`, "gm"),
new RegExp(`${escapeRegExp(AUTOGEN_MARKER)}([\\s\\S])*`, "gm"),
`${AUTOGEN_MARKER}\n\n${generated}`,
);
console.log(`${type}: ${brandCounter} brands, ${productCounter} products`);
Expand Down
Loading