Skip to content

Commit

Permalink
use typescript-fetch openapi-generator
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminpochat committed Aug 7, 2024
1 parent b02d416 commit f4a5ad1
Show file tree
Hide file tree
Showing 41 changed files with 165 additions and 173 deletions.
115 changes: 54 additions & 61 deletions frontend/app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions frontend/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"@viandeendirect/api": "file:../gen",
"dayjs": "^1.11.10",
"keycloak-js": "^21.1.1",
"querystring": "^0.2.1",
Expand All @@ -25,16 +26,15 @@
"react-router-dom": "^6.23.0",
"react-scripts": "5.0.1",
"typescript": "^5.2.2",
"viandeendirect_eu": "file:../gen",
"web-vitals": "^2.1.4"
},
"overrides": {
"typescript": "^5.2.2"
},
"scripts": {
"generate:api": "rm -Rf ../gen && openapi-generator-cli generate -i ../../openapi/openapi.yml -g javascript -o ../gen --skip-validate-spec",
"generate:api": "rm -Rf ../gen && openapi-generator-cli generate -i ../../openapi/openapi.yml -g typescript-fetch -o ../gen --skip-validate-spec --additional-properties=npmName=@viandeendirect/api,npmVersion=0.1.0",
"build:api": "npm install --prefix ../gen && npm run build --prefix ../gen",
"install:api": "rm -Rf ./node_modules/viandeendirect_eu && npm install ../gen",
"install:api": "rm -Rf ./node_modules/@viandeendirect/api && npm install ../gen",
"start": "react-scripts start",
"start:mock-api": "REACT_APP_MOCK_API=true react-scripts start",
"build": "react-scripts build",
Expand Down Expand Up @@ -64,7 +64,7 @@
},
"devDependencies": {
"@mui/x-data-grid": "^6.18.1",
"@openapitools/openapi-generator-cli": "^2.6.0",
"@openapitools/openapi-generator-cli": "^2.13.4",
"@types/jest": "^29.5.8",
"@types/node": "^20.9.2",
"@types/react": "^18.2.37",
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function App() {
<ReactKeycloakProvider authClient={keycloakClient} initOptions={keycloakInitOptions}>
<ThemeProvider theme={themeFactory.createTheme()}>
<LocalizationProvider dateAdapter={AdapterDayjs} adapterLocale="fr">
<RouterProvider router={routerFactory.getRouter()} />
<RouterProvider router={routerFactory.getRouter(keycloakClient)} />
</LocalizationProvider>
</ThemeProvider>
</ReactKeycloakProvider>
Expand Down
21 changes: 11 additions & 10 deletions frontend/app/src/api/ApiBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import ApiClient from 'viandeendirect_eu/dist/ApiClient'
import DefaultApi from 'viandeendirect_eu/dist/api/DefaultApi'
import { DefaultApi } from '@viandeendirect/api/dist/apis/DefaultApi'
import { MockApi } from './mock/MockApi.ts'
import { UrlService } from '../domains/commons/service/UrlService.ts'
import { Configuration } from '@viandeendirect/api/dist/runtime'

export class ApiBuilder {

Expand All @@ -16,21 +16,22 @@ export class ApiBuilder {
if(process.env.REACT_APP_MOCK_API) {
return new MockApi()
} else {
let apiClient = ApiClient.instance
apiClient.authentications['oAuth2ForViandeEnDirect'].accessToken = keycloak.token
apiClient.basePath = await this.urlService.getBackendUrl()
var api = new DefaultApi(apiClient)
return api
const configuration = new Configuration({
accessToken: keycloak.token,
basePath: await this.urlService.getBackendUrl()
});
return new DefaultApi(configuration)
}
}

async getAnonymousApi() {
if(process.env.REACT_APP_MOCK_API) {
return new MockApi()
} else {
let apiClient = ApiClient.instance
apiClient.basePath = await this.urlService.getBackendUrl()
return new DefaultApi(apiClient)
const configuration = new Configuration({
basePath: await this.urlService.getBackendUrl()
});
return new DefaultApi(configuration)
}
}

Expand Down
2 changes: 1 addition & 1 deletion frontend/app/src/api/mock/MockApiAddresses.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Address from "viandeendirect_eu/dist/model/Address"
import Address from "@viandeendirect/api/dist/models/Address"

export class MockApiAddresses {
getAddresses(): Array<Address> {
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/src/api/mock/MockApiCustomers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Customer from "viandeendirect_eu/dist/model/Customer"
import Customer from "@viandeendirect/api/dist/models/Customer"

export class MockApiCustomers {

Expand Down
8 changes: 4 additions & 4 deletions frontend/app/src/api/mock/MockApiProducers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Customer from "viandeendirect_eu/dist/model/Customer"
import Producer from "viandeendirect_eu/dist/model/Producer"
import ProducerStatus from "viandeendirect_eu/dist/model/ProducerStatus"
import Sale from "viandeendirect_eu/dist/model/Sale"
import Customer from "@viandeendirect/api/dist/models/Customer"
import Producer from "@viandeendirect/api/dist/models/Producer"
import ProducerStatus from "@viandeendirect/api/dist/models/ProducerStatus"
import Sale from "@viandeendirect/api/dist/models/Sale"

export class MockApiProducers {

Expand Down
6 changes: 3 additions & 3 deletions frontend/app/src/api/mock/MockApiProductions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import BeefProduction from "viandeendirect_eu/dist/model/BeefProduction"
import PackageTemplate from "viandeendirect_eu/dist/model/PackageTemplate"
import Production from "viandeendirect_eu/dist/model/Production"
import BeefProduction from "@viandeendirect/api/dist/models/BeefProduction"
import PackageTemplate from "@viandeendirect/api/dist/models/PackageTemplate"
import Production from "@viandeendirect/api/dist/models/Production"

export class MockApiProductions {

Expand Down
6 changes: 3 additions & 3 deletions frontend/app/src/api/mock/MockApiSales.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Order from "viandeendirect_eu/dist/model/Order";
import Sale from "viandeendirect_eu/dist/model/Sale";
import Production from "viandeendirect_eu/dist/model/Production";
import Order from "@viandeendirect/api/dist/models/Order";
import Sale from "@viandeendirect/api/dist/models/Sale";
import Production from "@viandeendirect/api/dist/models/Production";

export class MockApiSales {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Keycloak from "keycloak-js"
import Producer from "viandeendirect_eu/dist/model/Producer.js";
import Producer from "@viandeendirect/api/dist/models/Producer.js";
import { ApiInvoker } from "../../../api/ApiInvoker.ts";
import { AuthenticationService } from "../../../authentication/service/AuthenticationService.ts";

Expand Down
2 changes: 1 addition & 1 deletion frontend/app/src/domains/customer/CustomerController.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import CustomersList from './views/CustomersList.tsx'
import React from 'react'
import { useKeycloak } from '@react-keycloak/web'
import { ProducerService } from '../commons/service/ProducerService.ts'
import Producer from 'viandeendirect_eu/dist/model/Producer.js'
import Producer from '@viandeendirect/api/dist/models/Producer.js'
import AuthenticatedLayout from '../../layouts/producer/AuthenticatedLayout.tsx'

export default function CustomerController() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useEffect, useState } from 'react'
import { Button, Typography } from "@mui/material"
import Producer from 'viandeendirect_eu/dist/model/Producer.js'
import Producer from '@viandeendirect/api/dist/models/Producer.js'
import { ApiInvoker } from '../../../api/ApiInvoker.ts'
import { useKeycloak } from '@react-keycloak/web'
import { AuthenticationService } from '../../../authentication/service/AuthenticationService.ts'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useEffect, useState } from 'react'
import { Button, Typography } from "@mui/material"
import Producer from 'viandeendirect_eu/dist/model/Producer.js'
import Producer from '@viandeendirect/api/dist/models/Producer.js'
import { ApiInvoker } from '../../../api/ApiInvoker.ts'
import { useKeycloak } from '@react-keycloak/web'
import { AuthenticationService } from '../../../authentication/service/AuthenticationService.ts'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useEffect, useState } from 'react'
import { Button, Typography } from "@mui/material"
import Producer from 'viandeendirect_eu/dist/model/Producer.js'
import Producer from '@viandeendirect/api/dist/models/Producer.js'
import { ApiInvoker } from '../../../api/ApiInvoker.ts'
import { useKeycloak } from '@react-keycloak/web'
import { AuthenticationService } from '../../../authentication/service/AuthenticationService.ts'
Expand Down
Loading

0 comments on commit f4a5ad1

Please sign in to comment.