-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
1,603 additions
and
1,601 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,20 @@ | ||
{ | ||
"$schema": "https://biomejs.dev/schemas/1.7.0/schema.json", | ||
"organizeImports": { | ||
"enabled": true | ||
}, | ||
"files": { | ||
"ignore": ["dist", "examples/react-app/openapi"] | ||
}, | ||
"linter": { | ||
"enabled": true, | ||
"rules": { | ||
"recommended": true | ||
} | ||
}, | ||
"formatter": { | ||
"enabled": true | ||
} | ||
"$schema": "https://biomejs.dev/schemas/1.7.0/schema.json", | ||
"organizeImports": { | ||
"enabled": true | ||
}, | ||
"files": { | ||
"ignore": ["dist", "examples/react-app/openapi"] | ||
}, | ||
"linter": { | ||
"enabled": true, | ||
"rules": { | ||
"recommended": true | ||
} | ||
}, | ||
"formatter": { | ||
"enabled": true, | ||
"indentStyle": "space", | ||
"indentWidth": 2 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,31 @@ | ||
{ | ||
"name": "@7nohe/react-app", | ||
"private": true, | ||
"version": "0.0.0", | ||
"type": "module", | ||
"scripts": { | ||
"dev": "run-p dev:mock dev:client", | ||
"dev:client": "vite --clearScreen=false", | ||
"dev:mock": "prism mock ./petstore.yaml --dynamic", | ||
"build": "tsc && vite build", | ||
"preview": "vite preview", | ||
"generate:api": "node ../../dist/cli.mjs -i ./petstore.yaml -c axios --request ./request.ts", | ||
"test:generated": "tsc -p ./tsconfig.openapi.json --noEmit" | ||
}, | ||
"dependencies": { | ||
"@tanstack/react-query": "^5.18.1", | ||
"axios": "^1.6.7", | ||
"form-data": "~4.0.0", | ||
"react": "^18.2.0", | ||
"react-dom": "^18.2.0" | ||
}, | ||
"devDependencies": { | ||
"@stoplight/prism-cli": "^5.5.2", | ||
"@types/react": "^18.2.52", | ||
"@types/react-dom": "^18.2.18", | ||
"@vitejs/plugin-react": "^4.2.1", | ||
"npm-run-all": "^4.1.5", | ||
"typescript": "^5.3.3", | ||
"vite": "^5.0.12" | ||
} | ||
"name": "@7nohe/react-app", | ||
"private": true, | ||
"version": "0.0.0", | ||
"type": "module", | ||
"scripts": { | ||
"dev": "run-p dev:mock dev:client", | ||
"dev:client": "vite --clearScreen=false", | ||
"dev:mock": "prism mock ./petstore.yaml --dynamic", | ||
"build": "tsc && vite build", | ||
"preview": "vite preview", | ||
"generate:api": "node ../../dist/cli.mjs -i ./petstore.yaml -c axios --request ./request.ts", | ||
"test:generated": "tsc -p ./tsconfig.openapi.json --noEmit" | ||
}, | ||
"dependencies": { | ||
"@tanstack/react-query": "^5.18.1", | ||
"axios": "^1.6.7", | ||
"form-data": "~4.0.0", | ||
"react": "^18.2.0", | ||
"react-dom": "^18.2.0" | ||
}, | ||
"devDependencies": { | ||
"@stoplight/prism-cli": "^5.5.2", | ||
"@types/react": "^18.2.52", | ||
"@types/react-dom": "^18.2.18", | ||
"@vitejs/plugin-react": "^4.2.1", | ||
"npm-run-all": "^4.1.5", | ||
"typescript": "^5.3.3", | ||
"vite": "^5.0.12" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,79 +1,79 @@ | ||
import { useState } from "react"; | ||
import { | ||
useDefaultServiceAddPet, | ||
useDefaultServiceFindPets, | ||
useDefaultServiceFindPetsKey, | ||
useDefaultServiceGetNotDefined, | ||
useDefaultServicePostNotDefined, | ||
useDefaultServiceAddPet, | ||
useDefaultServiceFindPets, | ||
useDefaultServiceFindPetsKey, | ||
useDefaultServiceGetNotDefined, | ||
useDefaultServicePostNotDefined, | ||
} from "../openapi/queries"; | ||
import "./App.css"; | ||
import { SuspenseParent } from "./components/SuspenseParent"; | ||
import { queryClient } from "./queryClient"; | ||
|
||
function App() { | ||
const [tags, _setTags] = useState<string[]>([]); | ||
const [limit, _setLimit] = useState<number>(10); | ||
const [tags, _setTags] = useState<string[]>([]); | ||
const [limit, _setLimit] = useState<number>(10); | ||
|
||
const { data, error, refetch } = useDefaultServiceFindPets({ tags, limit }); | ||
// This is an example of using a hook that has all parameters optional; | ||
// Here we do not have to pass in an object | ||
const { data: _ } = useDefaultServiceFindPets(); | ||
const { data, error, refetch } = useDefaultServiceFindPets({ tags, limit }); | ||
// This is an example of using a hook that has all parameters optional; | ||
// Here we do not have to pass in an object | ||
const { data: _ } = useDefaultServiceFindPets(); | ||
|
||
// This is an example of a query that is not defined in the OpenAPI spec | ||
// this defaults to any - here we are showing how to override the type | ||
// Note - this is marked as deprecated in the OpenAPI spec and being passed to the client | ||
const { data: notDefined } = useDefaultServiceGetNotDefined<undefined>(); | ||
const { mutate: mutateNotDefined } = | ||
useDefaultServicePostNotDefined<undefined>(); | ||
// This is an example of a query that is not defined in the OpenAPI spec | ||
// this defaults to any - here we are showing how to override the type | ||
// Note - this is marked as deprecated in the OpenAPI spec and being passed to the client | ||
const { data: notDefined } = useDefaultServiceGetNotDefined<undefined>(); | ||
const { mutate: mutateNotDefined } = | ||
useDefaultServicePostNotDefined<undefined>(); | ||
|
||
const { mutate: addPet } = useDefaultServiceAddPet(); | ||
const { mutate: addPet } = useDefaultServiceAddPet(); | ||
|
||
if (error) | ||
return ( | ||
<div> | ||
<p>Failed to fetch pets</p> | ||
<button type="button" onClick={() => refetch()}> | ||
Retry | ||
</button> | ||
</div> | ||
); | ||
if (error) | ||
return ( | ||
<div> | ||
<p>Failed to fetch pets</p> | ||
<button type="button" onClick={() => refetch()}> | ||
Retry | ||
</button> | ||
</div> | ||
); | ||
|
||
return ( | ||
<div className="App"> | ||
<h1>Pet List</h1> | ||
<ul> | ||
{Array.isArray(data) && | ||
data?.map((pet, index) => ( | ||
<li key={`${pet.id}-${index}`}>{pet.name}</li> | ||
))} | ||
</ul> | ||
<button | ||
type="button" | ||
onClick={() => { | ||
addPet( | ||
{ | ||
requestBody: { name: "Duggy" }, | ||
}, | ||
{ | ||
onSuccess: () => { | ||
queryClient.invalidateQueries({ | ||
queryKey: [useDefaultServiceFindPetsKey], | ||
}); | ||
console.log("success"); | ||
}, | ||
onError: (error) => console.error(error), | ||
}, | ||
); | ||
}} | ||
> | ||
Create a pet | ||
</button> | ||
<div> | ||
<h1>Suspense Components</h1> | ||
<SuspenseParent /> | ||
</div> | ||
</div> | ||
); | ||
return ( | ||
<div className="App"> | ||
<h1>Pet List</h1> | ||
<ul> | ||
{Array.isArray(data) && | ||
data?.map((pet, index) => ( | ||
<li key={`${pet.id}-${index}`}>{pet.name}</li> | ||
))} | ||
</ul> | ||
<button | ||
type="button" | ||
onClick={() => { | ||
addPet( | ||
{ | ||
requestBody: { name: "Duggy" }, | ||
}, | ||
{ | ||
onSuccess: () => { | ||
queryClient.invalidateQueries({ | ||
queryKey: [useDefaultServiceFindPetsKey], | ||
}); | ||
console.log("success"); | ||
}, | ||
onError: (error) => console.error(error), | ||
}, | ||
); | ||
}} | ||
> | ||
Create a pet | ||
</button> | ||
<div> | ||
<h1>Suspense Components</h1> | ||
<SuspenseParent /> | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
export default App; |
Oops, something went wrong.