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

ENG: Add HTML Response View #57

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
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
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ In the `example directory` run the follow commands:

- `yarn` to install node modules in the example folder
- `yarn link "badmagic"`
- `yarn start` (to start the example that will be running on port 3000 by default)
- `yarn dev` (to start the example that will be running on port 3005 and server on port 3333 by default)
> Use env vars PORT and SERVER_PORT to change the ports if needed.

## General Usage

Expand Down Expand Up @@ -116,9 +117,7 @@ export function BadMagicClient() {
],
};

return (
<BadMagic workspaces={[superheroWorkspace]} />
);
return <BadMagic workspaces={[superheroWorkspace]} />;
}
```

Expand Down Expand Up @@ -174,7 +173,7 @@ export function AuthForm({
<TextInput name="password" />
<Button onClick={() => {
// axios request to login user, fetch access token, and store access token in state or local storage
// then in the `applyAxiosInterceptors`, the `getAccessToken()` function can fetch the token from state or
// then in the `applyAxiosInterceptors`, the `getAccessToken()` function can fetch the token from state or
// local storage
}}>
</div>
Expand Down Expand Up @@ -246,7 +245,7 @@ Example:
export function HistoryMetadata({
metadata,
}: {
metadata: Record<string, any>;
metadata: Record<string, any>,
}) {
if (!metadata?.accessToken) {
return null;
Expand Down Expand Up @@ -311,6 +310,7 @@ const superheroes = {
```

## Route Deprecation

- Each route can specify its deprecation status by adding a `deprecated` key to the object.
- `deprecated` accepts a boolean and will by default is set to `false`

Expand All @@ -324,13 +324,14 @@ const superheroes = {
{
name: "Fetch Superhero",
path: "/v1/superheroes/:superhero_id",
deprecated: true
deprecated: true,
},
],
};
```

## Input Field Tooltip

- Each input type can have a tooltip hover to describe what the input field is expecting if the name is ambiguous.
- The existence of a `description` attribute will generate the on-hover icon and it will pull the text from the `description` as well

Expand All @@ -346,7 +347,7 @@ const superheroes = {
path: "/v1/superheroes/:superhero_id",
method: "PATCH",
body: [
{
{
name: "first_name",
required: true,
description: "The first name of the hero you want to update to"
Expand Down
22 changes: 22 additions & 0 deletions example/mock-server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const express = require("express");
var cors = require("cors");
const app = express();
const port = process.env.SERVER_PORT ? Number(process.env.SERVER_PORT) : 3333;

app.use(cors());

app.get("/", (req, res) => {
res.send("Mock Example Server");
});

app.get("/breeds/list/all", (req, res) => {
res.json({
breeds: ["Labrador", "German Shepard", "Poodle"],
});
});

app.use("/views", express.static("mock-views"));

app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`);
});
17 changes: 17 additions & 0 deletions example/mock-views/breeds.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Breeds View</title>
</head>
<body>
<h1>Breeds</h1>
<ul>
<li>Labrador</li>
<li>German Shepard</li>
<li>Poodle</li>
</ul>
</body>
</html>
15 changes: 15 additions & 0 deletions example/mock-views/redirect.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Redirect View</title>
<script>
location.href = "https://www.google.com/";
</script>
</head>
<body>
<h1>Redirect</h1>
</body>
</html>
8 changes: 7 additions & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
"private": true,
"dependencies": {
"badmagic": "latest",
"react-scripts": "^4.0.3"
"react-scripts": "^5.0.0"
},
"scripts": {
"dev": "PORT=3005 yarn start & yarn server",
"server": "node mock-server.js",
"start": "react-scripts start"
},
"eslintConfig": {
Expand All @@ -23,5 +25,9 @@
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"cors": "^2.8.5",
"express": "^4.17.1"
}
}
24 changes: 24 additions & 0 deletions example/src/dog-workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,30 @@ export const dogWorkspace = {
},
},
},
{
name: "HTML response",
path: "/views/breeds.html",
responses: {
"200": {
description: "successful operation",
// schema: {
// type: "array",
// items: {
// $ref: "#/definitions/Dog",
// },
// },
Comment on lines +47 to +52
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

},
},
},
{
name: "Redirecting HTML Response",
path: "/views/redirect.html",
responses: {
"200": {
description: "Should stop the redirection from the html response",
},
},
},

{
name: "View Random Breed Image",
Expand Down
Loading