Skip to content

Commit db11b3d

Browse files
task: update openapi cli
1 parent 75c9948 commit db11b3d

File tree

11 files changed

+81
-255
lines changed

11 files changed

+81
-255
lines changed

constants/api.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const apiUrl = "https://api.dev.pov.io/";

constants/github.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

docs/bolt/2_external_api.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@ Use this mode when the backend is already developed or being developed in parall
1919
};
2020
```
2121

22-
3. **Generate data layer**
22+
3. **Change API URL**
23+
24+
- Open `constants/api.ts`
25+
- Change value to the base URL of your backend
26+
27+
4. **Generate data layer**
2328
```bash
2429
npm run openapi:gen
2530
```

openapi-codegen.config.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ const config: OpenAPICodegenConfig = {
55
input: "https://api.dev.pov.io/api/docs-json", // External deployed backend
66
output: "./openapi",
77
tsPath: "@/openapi",
8-
errorHandlingImportPath: "@/utils/vendor/error-handling",
8+
restClientImportPath: "@/utils/rest/appRestClient",
99
replaceOptionalWithNullish: true,
10-
infiniteQueries: true,
11-
standalone: true,
10+
infiniteQueries: false,
11+
builderConfigs: false,
12+
mutationEffects: false,
1213
acl: false,
14+
checkAcl: false,
1315
};
1416

1517
export default config;

package-lock.json

Lines changed: 21 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"@dev-plugins/react-query": "^0.4.0",
2626
"@gorhom/bottom-sheet": "^5.2.7",
2727
"@hookform/resolvers": "^5.2.2",
28+
"@povio/openapi-codegen-cli": "^2.0.1",
2829
"@react-native-async-storage/async-storage": "2.2.0",
2930
"@react-native-community/datetimepicker": "8.4.4",
3031
"@react-native-community/slider": "5.0.1",
@@ -68,7 +69,6 @@
6869
"@babel/core": "^7.26.0",
6970
"@biomejs/biome": "^2.3.8",
7071
"@expo/env": "^1.0.5",
71-
"@povio/openapi-codegen-cli": "^1.2.10",
7272
"@testing-library/jest-dom": "^6.9.1",
7373
"@testing-library/react-native": "^13.3.3",
7474
"@types/css": "^0.0.38",

utils/axios.ts

Lines changed: 0 additions & 28 deletions
This file was deleted.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { RestClient, RestInterceptor } from "@povio/openapi-codegen-cli";
2+
3+
import { apiUrl } from "@/constants/api";
4+
5+
import { AppErrorHandler } from "./errorHandler";
6+
7+
const RequestInterceptor = new RestInterceptor((client) => {
8+
return client.interceptors.request.use(
9+
async (config) => {
10+
// attach token to request header
11+
return config;
12+
},
13+
(error) => {
14+
return Promise.reject(error);
15+
},
16+
);
17+
});
18+
19+
const ResponseInterceptor = new RestInterceptor((client) => {
20+
return client.interceptors.response.use(
21+
(response) => {
22+
return response;
23+
},
24+
(error) => {
25+
return Promise.reject(error);
26+
},
27+
);
28+
});
29+
30+
export const AppRestClient = new RestClient({
31+
config: { baseURL: apiUrl },
32+
errorHandler: AppErrorHandler,
33+
interceptors: [RequestInterceptor, ResponseInterceptor],
34+
});

utils/rest/openapi/errorHandler.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { type ApplicationException, type ErrorEntry, ErrorHandler } from "@povio/openapi-codegen-cli";
2+
import * as Sentry from "@sentry/react-native";
3+
4+
type ErrorCodes = string;
5+
6+
const errorEntries: ErrorEntry<ErrorCodes>[] = [];
7+
8+
export const AppErrorHandler = new ErrorHandler({
9+
entries: errorEntries,
10+
onRethrowError: (_error, applicationException: ApplicationException<ErrorCodes>) => {
11+
Sentry.captureException(applicationException.serverMessage ?? applicationException.code);
12+
},
13+
});

utils/rest/rest.utils.ts

Lines changed: 0 additions & 66 deletions
This file was deleted.

0 commit comments

Comments
 (0)