Skip to content

Commit 8d0d287

Browse files
antonielfabien0102
andauthored
docs: add frontend example (#60)
* docs: add frontend example * docs: add README to frontend example * Fix example Co-authored-by: Fabien BERNARD <[email protected]>
1 parent f1e3e0b commit 8d0d287

19 files changed

+76151
-0
lines changed

examples/frontend/.gitignore

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
pnpm-debug.log*
8+
lerna-debug.log*
9+
10+
node_modules
11+
dist
12+
dist-ssr
13+
*.local
14+
15+
# Editor directories and files
16+
.vscode/*
17+
!.vscode/extensions.json
18+
.idea
19+
.DS_Store
20+
*.suo
21+
*.ntvs*
22+
*.njsproj
23+
*.sln
24+
*.sw?

examples/frontend/README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# OpenAPI Codegen `github` example
2+
3+
## Getting started
4+
5+
To try the playground out for yourself, run the following commands:
6+
7+
```shell
8+
git clone https://github.com/fabien0102/openapi-codegen.git
9+
cd openapi-codegen/examples/frontend
10+
npm install
11+
npm run dev
12+
```
13+
14+
You can play around with the example by removing the ./openapi-codegen.config.ts and ./src/github/ and run the following commands to generate these files on your own:
15+
16+
```shell
17+
npx openapi-codegen init
18+
npx openapi-codegen gen {namespace}
19+
```
20+
21+
## References
22+
23+
You can find a detailed description of how to use openapi-codegen on https://xata.io/blog/openapi-typesafe-react-query-hooks

examples/frontend/index.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<link rel="icon" type="image/svg+xml" href="/src/favicon.svg" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>Vite App</title>
8+
</head>
9+
<body>
10+
<div id="root"></div>
11+
<script type="module" src="/src/main.tsx"></script>
12+
</body>
13+
</html>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import {
2+
generateSchemaTypes,
3+
generateReactQueryComponents,
4+
} from "@openapi-codegen/typescript";
5+
import { defineConfig } from "@openapi-codegen/cli";
6+
7+
export default defineConfig({
8+
github: {
9+
from: {
10+
source: "url",
11+
url: "https://api.apis.guru/v2/specs/github.com/1.1.4/openapi.yaml",
12+
},
13+
outputDir: "src/github",
14+
to: async (context) => {
15+
const filenamePrefix = "github";
16+
const { schemasFiles } = await generateSchemaTypes(context, {
17+
filenamePrefix,
18+
});
19+
await generateReactQueryComponents(context, {
20+
filenamePrefix,
21+
schemasFiles,
22+
});
23+
},
24+
},
25+
});

0 commit comments

Comments
 (0)