mirror of
https://github.com/stack-auth/stack.git
synced 2026-06-04 21:04:37 +08:00
satisfy remaining comments
This commit is contained in:
parent
9dd76b0012
commit
dca3a068a1
@ -432,7 +432,6 @@ function ModernAPIPlayground({
|
||||
onExecute,
|
||||
onCopy,
|
||||
description,
|
||||
generateExample,
|
||||
}: {
|
||||
operation: OpenAPIOperation,
|
||||
path: string,
|
||||
@ -1150,10 +1149,17 @@ function RequestBodyFieldsSection({
|
||||
placeholder={resolvedFieldSchema.example ? String(resolvedFieldSchema.example) : `Enter ${fieldName}`}
|
||||
value={String(values[fieldName] || '')}
|
||||
onChange={(e) => {
|
||||
let value: string | number = e.target.value;
|
||||
// Convert to number for number/integer types
|
||||
const inputValue = e.target.value;
|
||||
let value: string | number = inputValue;
|
||||
|
||||
// Convert to number for number/integer types, but keep as string if invalid
|
||||
if (resolvedFieldSchema.type === 'number' || resolvedFieldSchema.type === 'integer') {
|
||||
value = e.target.value === '' ? '' : Number(e.target.value);
|
||||
if (inputValue === '') {
|
||||
value = '';
|
||||
} else {
|
||||
const numValue = Number(inputValue);
|
||||
value = !isNaN(numValue) ? numValue : inputValue;
|
||||
}
|
||||
}
|
||||
onChange({ ...values, [fieldName]: value });
|
||||
}}
|
||||
|
||||
@ -1,23 +1,36 @@
|
||||
import type { OpenAPISchema, OpenAPISpec } from '../components/api/enhanced-api-page';
|
||||
|
||||
/**
|
||||
* Resolves $ref references in OpenAPI schemas
|
||||
* Resolves $ref references in OpenAPI schemas recursively
|
||||
* @param schema - The schema to resolve
|
||||
* @param spec - The OpenAPI specification containing the schema definitions
|
||||
* @param visited - Set of visited $ref paths to prevent infinite recursion
|
||||
* @returns The resolved schema
|
||||
*/
|
||||
export const resolveSchema = (schema: OpenAPISchema, spec: OpenAPISpec): OpenAPISchema => {
|
||||
export const resolveSchema = (schema: OpenAPISchema, spec: OpenAPISpec, visited = new Set<string>()): OpenAPISchema => {
|
||||
if (schema.$ref) {
|
||||
// Prevent infinite recursion
|
||||
if (visited.has(schema.$ref)) {
|
||||
console.warn(`Circular $ref reference detected: ${schema.$ref}`);
|
||||
return schema;
|
||||
}
|
||||
|
||||
visited.add(schema.$ref);
|
||||
const refPath = schema.$ref.replace('#/', '').split('/');
|
||||
let refSchema: any = spec;
|
||||
let refSchema: Record<string, unknown> = spec as Record<string, unknown>;
|
||||
for (const part of refPath) {
|
||||
refSchema = refSchema?.[part];
|
||||
if (!refSchema) {
|
||||
const nextSchema = refSchema[part];
|
||||
if (!nextSchema || typeof nextSchema !== 'object') {
|
||||
console.error(`Failed to resolve $ref: ${schema.$ref}`);
|
||||
return schema;
|
||||
}
|
||||
refSchema = nextSchema as Record<string, unknown>;
|
||||
}
|
||||
return refSchema as OpenAPISchema;
|
||||
|
||||
// Recursively resolve the resolved schema in case it contains more $refs
|
||||
const resolvedSchema = resolveSchema(refSchema as OpenAPISchema, spec, visited);
|
||||
visited.delete(schema.$ref);
|
||||
return resolvedSchema;
|
||||
}
|
||||
return schema;
|
||||
};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user