Skip to content

Commit

Permalink
feat(react-query): implementation new client
Browse files Browse the repository at this point in the history
  • Loading branch information
anymaniax committed Oct 7, 2020
1 parent f7ad0cc commit f88fed8
Show file tree
Hide file tree
Showing 50 changed files with 12,099 additions and 72 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ interface InputOptions = {
override?: OverrideInput;
};

type OutputClient = 'axios' | 'angular';
type OutputClient = 'axios' | 'angular' | 'react-query';

export type OutputMode = 'single' | 'split' | 'tags' | 'tags-split';

Expand Down Expand Up @@ -199,7 +199,8 @@ interface OutputOptions = {
// tags-split a mix of tags and split
mode?: OutputMode;
// add mock to your implementation
mock?: boolean | 'msw';
// old version will be removed in the next major version
mock?: boolean | 'old-version';
// override the output like your mock implementation or transform the api implementation like you want
override?: OverrideOutput;
};
Expand Down
2 changes: 1 addition & 1 deletion samples/angular-app/orval.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module.exports = {
target: 'src/api/endpoints/petstoreFromFileSpecWithTransformer.ts',
schemas: 'src/api/model',
client: 'angular',
mock: 'msw',
mock: true,
override: {
operations: {
listPets: {
Expand Down
2 changes: 1 addition & 1 deletion samples/basic/orval.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module.exports = {
output: {
target: './api/endpoints/petstoreFromFileSpecWithTransformer.ts',
schemas: './api/model',
mock: true,
mock: 'old-version',
override: {
operations: {
listPets: {
Expand Down
1 change: 1 addition & 0 deletions samples/react-app-with-react-query/.env.development
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
REACT_APP_API_MODE=mock
23 changes: 23 additions & 0 deletions samples/react-app-with-react-query/.gitignore
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*
50 changes: 50 additions & 0 deletions samples/react-app-with-react-query/orval.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
const faker = require('faker');
/**
* Example config for `yarn example:advanced`
*/

module.exports = {
petstore: {
output: {
mode: 'split',
target: 'src/api/endpoints/petstoreFromFileSpecWithTransformer.ts',
schemas: 'src/api/model',
client: 'react-query',
mock: true,
override: {
operations: {
listPets: {
mutator: 'src/api/mutator/response-type.js',
mock: {
properties: () => {
return {
id: () => faker.random.number({ min: 1, max: 99999 }),
};
},
},
},
showPetById: {
mock: {
data: () => ({
id: faker.random.number({ min: 1, max: 99 }),
name: faker.name.firstName(),
tag: faker.helpers.randomize([faker.random.word(), undefined]),
}),
},
},
},
mock: {
properties: {
'/tag|name/': () => faker.name.lastName(),
},
},
},
},
input: {
target: './petstore.yaml',
override: {
transformer: 'src/api/transformer/add-version.js',
},
},
},
};
41 changes: 41 additions & 0 deletions samples/react-app-with-react-query/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"name": "react-app",
"version": "0.1.0",
"private": true,
"dependencies": {
"@types/node": "^14.11.2",
"@types/react": "^16.9.49",
"@types/react-dom": "^16.9.8",
"axios": "^0.20.0",
"faker": "^5.1.0",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-query": "^2.23.0",
"react-scripts": "^3.4.3",
"typescript": "~3.7.2"
},
"scripts": {
"start": "SKIP_PREFLIGHT_CHECK=true react-scripts start",
"build": "react-scripts build",
"eject": "react-scripts eject",
"generate-api": "node ../../lib/bin/orval.js --config ./orval.config.js"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"msw": "^0.21.2"
}
}
117 changes: 117 additions & 0 deletions samples/react-app-with-react-query/petstore.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
openapi: '3.0.0'
info:
version: 1.0.0
title: Swagger Petstore
license:
name: MIT
servers:
- url: http://petstore.swagger.io/v1
paths:
/pets:
get:
summary: List all pets
operationId: listPets
tags:
- pets
parameters:
- name: limit
in: query
description: How many items to return at one time (max 100)
required: false
schema:
type: integer
format: int32
responses:
'200':
description: A paged array of pets
headers:
x-next:
description: A link to the next page of responses
schema:
type: string
content:
application/json:
schema:
$ref: '#/components/schemas/Pets'
default:
description: unexpected error
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
post:
summary: Create a pet
operationId: createPets
tags:
- pets
responses:
'201':
description: Null response
default:
description: unexpected error
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
/pets/{petId}/test/{testId}:
get:
summary: Info for a specific pet
operationId: showPetById
tags:
- pets
parameters:
- name: petId
in: path
required: true
description: The id of the pet to retrieve
schema:
type: string
- name: testId
in: path
required: true
description: The id of the pet to retrieve
schema:
type: string
responses:
'200':
description: Expected response to a valid request
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
default:
description: unexpected error
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
components:
schemas:
Pet:
type: object
required:
- id
- name
properties:
id:
type: integer
format: int64
name:
type: string
tag:
type: string
Pets:
type: array
items:
$ref: '#/components/schemas/Pet'
Error:
type: object
required:
- code
- message
properties:
code:
type: integer
format: int32
message:
type: string
Binary file not shown.
43 changes: 43 additions & 0 deletions samples/react-app-with-react-query/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions samples/react-app-with-react-query/public/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"short_name": "React App",
"name": "Create React App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
},
{
"src": "logo192.png",
"type": "image/png",
"sizes": "192x192"
},
{
"src": "logo512.png",
"type": "image/png",
"sizes": "512x512"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
Loading

0 comments on commit f88fed8

Please sign in to comment.