Skip to content

Commit

Permalink
issue #360: fertiscan backend openapi client
Browse files Browse the repository at this point in the history
  • Loading branch information
k-allagbe committed Dec 5, 2024
1 parent ca69cc7 commit 1a7606b
Show file tree
Hide file tree
Showing 37 changed files with 2,946 additions and 11 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,5 @@ yarn-error.log*
# typescript
*.tsbuildinfo
next-env.d.ts

/backend-openapi
26 changes: 15 additions & 11 deletions src/app/api/extract-label-data/route.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { BACKEND_URL } from "@/utils/server/constants";
import axios from "axios";
import { inspectionsApi, pipelineApi } from "@/utils/server/backend";

export async function POST(request: Request) {
const formData = await request.formData();
const files = formData.getAll("files") as File[];

const authHeader = request.headers.get("Authorization");
if (!authHeader) {
Expand All @@ -14,16 +14,20 @@ export async function POST(request: Request) {
);
}

return axios
.post(`${BACKEND_URL}/analyze`, formData, {
headers: { Authorization: authHeader },
})
return pipelineApi
.analyzeDocumentAnalyzePost(files)
.then((analyzeResponse) => {
formData.set("label_data", JSON.stringify(analyzeResponse.data));

return axios.post(`${BACKEND_URL}/inspections`, formData, {
headers: { Authorization: authHeader },
});
console.log(
"Analyze response:",
JSON.stringify(analyzeResponse.data, null, 2),
);
return inspectionsApi.postInspectionInspectionsPost(
analyzeResponse.data,
files,
{
headers: { Authorization: authHeader },
},
);
})
.then((inspectionsResponse) => {
return Response.json(inspectionsResponse.data);
Expand Down
22 changes: 22 additions & 0 deletions src/utils/server/backend/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* tslint:disable */
/* eslint-disable */
/**
* FastAPI
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document: 0.1.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/



export * from './api/home-api';
export * from './api/inspections-api';
export * from './api/monitoring-api';
export * from './api/pipeline-api';
export * from './api/users-api';

122 changes: 122 additions & 0 deletions src/utils/server/backend/api/home-api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/* tslint:disable */
/* eslint-disable */
/**
* FastAPI
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document: 0.1.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/


import type { AxiosInstance, AxiosPromise, RawAxiosRequestConfig } from 'axios';
import globalAxios from 'axios';
import type { Configuration } from '../configuration';
// Some imports not used depending on template conditions
// @ts-ignore
import { DUMMY_BASE_URL, createRequestFunction, setSearchParams, toPathString } from '../common';
// @ts-ignore
import { BASE_PATH, BaseAPI, RequiredError, operationServerMap, type RequestArgs } from '../base';
/**
* HomeApi - axios parameter creator
* @export
*/
export const HomeApiAxiosParamCreator = function (configuration?: Configuration) {
return {
/**
*
* @summary Home
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
homeGet: async (options: RawAxiosRequestConfig = {}): Promise<RequestArgs> => {
const localVarPath = `/`;
// use dummy base URL string because the URL constructor only accepts absolute URLs.
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
let baseOptions;
if (configuration) {
baseOptions = configuration.baseOptions;
}

const localVarRequestOptions = { method: 'GET', ...baseOptions, ...options};
const localVarHeaderParameter = {} as any;
const localVarQueryParameter = {} as any;



setSearchParams(localVarUrlObj, localVarQueryParameter);
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};

return {
url: toPathString(localVarUrlObj),
options: localVarRequestOptions,
};
},
}
};

/**
* HomeApi - functional programming interface
* @export
*/
export const HomeApiFp = function(configuration?: Configuration) {
const localVarAxiosParamCreator = HomeApiAxiosParamCreator(configuration)
return {
/**
*
* @summary Home
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
async homeGet(options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<any>> {
const localVarAxiosArgs = await localVarAxiosParamCreator.homeGet(options);
const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
const localVarOperationServerBasePath = operationServerMap['HomeApi.homeGet']?.[localVarOperationServerIndex]?.url;
return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath);
},
}
};

/**
* HomeApi - factory interface
* @export
*/
export const HomeApiFactory = function (configuration?: Configuration, basePath?: string, axios?: AxiosInstance) {
const localVarFp = HomeApiFp(configuration)
return {
/**
*
* @summary Home
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
homeGet(options?: RawAxiosRequestConfig): AxiosPromise<any> {
return localVarFp.homeGet(options).then((request) => request(axios, basePath));
},
};
};

/**
* HomeApi - object-oriented interface
* @export
* @class HomeApi
* @extends {BaseAPI}
*/
export class HomeApi extends BaseAPI {
/**
*
* @summary Home
* @param {*} [options] Override http request option.
* @throws {RequiredError}
* @memberof HomeApi
*/
public homeGet(options?: RawAxiosRequestConfig) {
return HomeApiFp(this.configuration).homeGet(options).then((request) => request(this.axios, this.basePath));
}
}

Loading

0 comments on commit 1a7606b

Please sign in to comment.