-
-
Notifications
You must be signed in to change notification settings - Fork 349
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(samples): add a react app examples
- Loading branch information
Showing
49 changed files
with
11,959 additions
and
16 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Orval basic example</title> | ||
</head> | ||
<body> | ||
<h1>Orval basic example</h1> | ||
</body> | ||
</html> |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* | ||
* Generated by orval v2.1.1 🍺 | ||
* Do not edit manually. | ||
* Swagger Petstore | ||
* OpenAPI spec version: 1.0.0 | ||
*/ | ||
|
||
export interface Error { | ||
code: number; | ||
message: string; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export * from './pet'; | ||
export * from './pets'; | ||
export * from './error'; | ||
export * from './listPetsParams'; |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* | ||
* Generated by orval v2.1.1 🍺 | ||
* Do not edit manually. | ||
* Swagger Petstore | ||
* OpenAPI spec version: 1.0.0 | ||
*/ | ||
|
||
export type listPetsParams = { limit?: number }; |
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
* Generated by orval v2.1.1 🍺 | ||
* Do not edit manually. | ||
* Swagger Petstore | ||
* OpenAPI spec version: 1.0.0 | ||
*/ | ||
|
||
export interface Pet { | ||
id: number; | ||
name: string; | ||
tag?: string; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* | ||
* Generated by orval v2.1.1 🍺 | ||
* Do not edit manually. | ||
* Swagger Petstore | ||
* OpenAPI spec version: 1.0.0 | ||
*/ | ||
import { Pet } from './pet'; | ||
|
||
export type Pets = Pet[]; |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = (url, config) => [url, { ...config, responseType: 'json' }]; |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"name": "basic", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.html", | ||
"scripts": { | ||
"example": "run-p example:*", | ||
"example:github": "node ../../lib/bin/orval.js import --input https://github.com/OAI/OpenAPI-Specification/blob/master/examples/v3.0/petstore.yaml --output ./petstoreFromGithubSpec.ts", | ||
"example:file": "node ../../lib/bin/orval.js import --input ./petstore.yaml --output ./petstoreFromFileSpec.ts", | ||
"example:advanced": "node ../../lib/bin/orval.js import --config ./orval.config.js" | ||
}, | ||
"author": "Victor Bury", | ||
"license": "ISC" | ||
} |
File renamed without changes.
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Generated by orval v2.1.1 🍺 | ||
* Do not edit manually. | ||
* Swagger Petstore | ||
* OpenAPI spec version: 1.0.0 | ||
*/ | ||
import { AxiosInstance, AxiosPromise } from 'axios'; | ||
|
||
export interface Pet { | ||
id: number; | ||
name: string; | ||
tag?: string; | ||
} | ||
|
||
export type Pets = Pet[]; | ||
|
||
export interface Error { | ||
code: number; | ||
message: string; | ||
} | ||
|
||
export type listPetsParams = { limit?: number }; | ||
|
||
export interface SwaggerPetstore { | ||
// List all pets | ||
listPets(params?: listPetsParams): AxiosPromise<Pets>; | ||
// Create a pet | ||
createPets(): AxiosPromise<unknown>; | ||
// Info for a specific pet | ||
showPetById(petId: string, testId: string): AxiosPromise<Pet>; | ||
} | ||
|
||
export const getSwaggerPetstore = (axios: AxiosInstance): SwaggerPetstore => ({ | ||
listPets(params?: listPetsParams): AxiosPromise<Pets> { | ||
return axios.get(`/pets`, { | ||
params, | ||
}); | ||
}, | ||
createPets(): AxiosPromise<unknown> { | ||
return axios.post(`/pets`, undefined); | ||
}, | ||
showPetById(petId: string, testId: string): AxiosPromise<Pet> { | ||
return axios.get(`/pets/${petId}/test/${testId}`); | ||
}, | ||
}); |
21 changes: 21 additions & 0 deletions
21
samples/basic/petstoreFromFileSpecWithTransformer.definition.ts
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* Generated by orval v2.1.1 🍺 | ||
* Do not edit manually. | ||
* Swagger Petstore | ||
* OpenAPI spec version: 1.0.0 | ||
*/ | ||
import { AxiosPromise } from 'axios'; | ||
import { listPetsParams, Pet, Pets } from './model'; | ||
|
||
export interface SwaggerPetstore { | ||
// List all pets | ||
listPets(params?: listPetsParams, version?: number): AxiosPromise<Pets>; | ||
// Create a pet | ||
createPets(version?: number): AxiosPromise<unknown>; | ||
// Info for a specific pet | ||
showPetById( | ||
petId: string, | ||
testId: string, | ||
version?: number, | ||
): AxiosPromise<Pet>; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Generated by orval v2.1.1 🍺 | ||
* Do not edit manually. | ||
* Swagger Petstore | ||
* OpenAPI spec version: 1.0.0 | ||
*/ | ||
import { AxiosPromise } from 'axios'; | ||
import faker from 'faker'; | ||
import { listPetsParams, Pet, Pets } from './model'; | ||
import { SwaggerPetstore } from './petstoreFromFileSpecWithTransformer.definition'; | ||
|
||
export const getSwaggerPetstoreMock = (): SwaggerPetstore => ({ | ||
listPets(params?: listPetsParams, version?: number): AxiosPromise<Pets> { | ||
return Promise.resolve( | ||
[...Array(faker.random.number({ min: 1, max: 10 }))].map(() => ({ | ||
id: 8, | ||
name: 'jon', | ||
tag: faker.helpers.randomize(['jon', undefined]), | ||
})), | ||
).then((data) => ({ data })) as AxiosPromise<Pets>; | ||
}, | ||
createPets(version?: number): AxiosPromise<unknown> { | ||
return Promise.resolve(undefined).then((data) => ({ | ||
data, | ||
})) as AxiosPromise<unknown>; | ||
}, | ||
showPetById( | ||
petId: string, | ||
testId: string, | ||
version?: number, | ||
): AxiosPromise<Pet> { | ||
return Promise.resolve( | ||
(() => ({ | ||
id: faker.random.number({ min: 1, max: 99 }), | ||
name: faker.name.firstName(), | ||
tag: faker.helpers.randomize([faker.random.word(), undefined]), | ||
}))(), | ||
).then((data) => ({ data })) as AxiosPromise<Pet>; | ||
}, | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Generated by orval v2.1.1 🍺 | ||
* Do not edit manually. | ||
* Swagger Petstore | ||
* OpenAPI spec version: 1.0.0 | ||
*/ | ||
import { AxiosInstance, AxiosPromise, AxiosRequestConfig } from 'axios'; | ||
import { listPetsParams, Pet, Pets } from './model'; | ||
import { SwaggerPetstore } from './petstoreFromFileSpecWithTransformer.definition'; | ||
|
||
export const getSwaggerPetstore = (axios: AxiosInstance): SwaggerPetstore => ({ | ||
listPets(params?: listPetsParams, version = 1): AxiosPromise<Pets> { | ||
type Mutator = ( | ||
url: string, | ||
config?: AxiosRequestConfig, | ||
) => [string, AxiosRequestConfig | undefined]; | ||
|
||
const mutator: Mutator = (url, { params }) => [ | ||
url, | ||
{ params, responseType: 'json' }, | ||
]; | ||
|
||
return axios.get( | ||
...mutator(`/v${version}/pets`, { | ||
params, | ||
}), | ||
); | ||
}, | ||
createPets(version = 1): AxiosPromise<unknown> { | ||
return axios.post(`/v${version}/pets`, undefined); | ||
}, | ||
showPetById(petId: string, testId: string, version = 1): AxiosPromise<Pet> { | ||
return axios.get(`/v${version}/pets/${petId}/test/${testId}`); | ||
}, | ||
}); |
File renamed without changes.
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
REACT_APP_API_MODE=mock |
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
/node_modules | ||
/.pnp | ||
.pnp.js | ||
|
||
# testing | ||
/coverage | ||
|
||
# production | ||
/build | ||
|
||
# misc | ||
.DS_Store | ||
.env.local | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
|
||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* |
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). | ||
|
||
## Available Scripts | ||
|
||
In the project directory, you can run: | ||
|
||
### `yarn start` | ||
|
||
Runs the app in the development mode.<br /> | ||
Open [http://localhost:3000](http://localhost:3000) to view it in the browser. | ||
|
||
The page will reload if you make edits.<br /> | ||
You will also see any lint errors in the console. | ||
|
||
### `yarn test` | ||
|
||
Launches the test runner in the interactive watch mode.<br /> | ||
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. | ||
|
||
### `yarn build` | ||
|
||
Builds the app for production to the `build` folder.<br /> | ||
It correctly bundles React in production mode and optimizes the build for the best performance. | ||
|
||
The build is minified and the filenames include the hashes.<br /> | ||
Your app is ready to be deployed! | ||
|
||
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. | ||
|
||
### `yarn eject` | ||
|
||
**Note: this is a one-way operation. Once you `eject`, you can’t go back!** | ||
|
||
If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. | ||
|
||
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. | ||
|
||
You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. | ||
|
||
## Learn More | ||
|
||
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). | ||
|
||
To learn React, check out the [React documentation](https://reactjs.org/). |
Oops, something went wrong.