react-openapi and react-auth cleanup. index.ts for react-openapi

This commit is contained in:
2026-04-04 18:01:22 +05:30
parent 86e5bc6429
commit ffa41825dd
15 changed files with 26 additions and 1733 deletions

View File

@@ -1,6 +1,5 @@
import SwaggerParser from "@apidevtools/swagger-parser";
import { AppConfig, ResourceConfig, ResourceField, FieldType } from "../types/config";
import { configuration, profileConfiguration } from "../../src/openapi-config";
/**
* Maps OpenAPI property types to our internal FieldType
@@ -40,7 +39,8 @@ function mapOpenApiType(prop: any): FieldType {
function parseSchemaFields(
schema: any,
resourceName: string,
schemaToResourceMap: Map<any, string>
schemaToResourceMap: Map<any, string>,
configuration: Record<string, any> = {}
): Record<string, ResourceField> {
const fields: Record<string, ResourceField> = {};
const properties = schema.properties || {};
@@ -84,7 +84,7 @@ function parseSchemaFields(
// Recursively parse nested objects (only if not a relation)
if (fields[key].type === "object" && prop.properties && !relation) {
fields[key].schema = parseSchemaFields(prop, resourceName, schemaToResourceMap);
fields[key].schema = parseSchemaFields(prop, resourceName, schemaToResourceMap, configuration);
}
}
@@ -94,7 +94,7 @@ function parseSchemaFields(
/**
* Scans paths to identify resources and their basic configuration
*/
export async function loadConfigFromOpenApi(baseUrl: string): Promise<AppConfig> {
export async function loadConfigFromOpenApi(baseUrl: string, configuration: Record<string, any> = {}, profileConfiguration: any = {}): Promise<AppConfig> {
// Use SwaggerParser to dereference the spec.
// Dereferencing preserves object identity for $ref targets.
const api = await SwaggerParser.dereference(
@@ -150,7 +150,7 @@ export async function loadConfigFromOpenApi(baseUrl: string): Promise<AppConfig>
const label = name.charAt(0).toUpperCase() + name.slice(1, -1);
const pluralLabel = name.charAt(0).toUpperCase() + name.slice(1);
const fields = parseSchemaFields(schema, name, schemaToResourceMap);
const fields = parseSchemaFields(schema, name, schemaToResourceMap, configuration);
const resourceOverride = configuration[name] || {};