Skip to content

Commit e0f8ed0

Browse files
committed
fixes
1 parent d264347 commit e0f8ed0

File tree

4 files changed

+8
-42
lines changed

4 files changed

+8
-42
lines changed

packages/react-openapi/src/OpenAPISchema.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ export function getSchemaAlternatives(
550550
type,
551551
flattenAlternatives(type, schemas, new Set(ancestors).add(schema))
552552
) ?? [],
553-
...(discriminator ? { discriminator } : {}),
553+
discriminator,
554554
};
555555
}
556556

@@ -653,9 +653,7 @@ function mergeAlternatives(
653653
: []),
654654
])
655655
);
656-
if (latest.nullable || schemaOrRef.nullable) {
657-
latest.nullable = latest.nullable || schemaOrRef.nullable;
658-
}
656+
latest.nullable = latest.nullable || schemaOrRef.nullable;
659657

660658
// Preserve safe extensions and vendor extensions
661659
// Always overwrite (last schema has priority)
@@ -688,6 +686,7 @@ function flattenAlternatives(
688686
schemasOrRefs: (OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject)[],
689687
ancestors: Set<OpenAPIV3.SchemaObject>
690688
): OpenAPIV3.SchemaObject[] {
689+
// Get the parent schema's required fields from the most recent ancestor
691690
const latestAncestor = Array.from(ancestors).pop();
692691
const result: OpenAPIV3.SchemaObject[] = [];
693692

@@ -706,6 +705,9 @@ function flattenAlternatives(
706705
return result;
707706
}
708707

708+
/**
709+
* Flatten a schema that is an alternative of another schema.
710+
*/
709711
function flattenSchema(
710712
schema: OpenAPIV3.SchemaObject,
711713
alternativeType: AlternativeType,

packages/react-openapi/src/contentTypeChecks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@ export function isFormData(contentType?: string): boolean {
3434
return !!contentType && contentType.toLowerCase().includes('multipart/form-data');
3535
}
3636

37-
export function isPlainObject(value: unknown): boolean {
37+
export function isPlainObject(value: unknown): value is Record<string, unknown> {
3838
return typeof value === 'object' && value !== null && !Array.isArray(value);
3939
}

packages/react-openapi/src/generateSchemaExample.test.ts

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,36 +1038,6 @@ describe('generateSchemaExample', () => {
10381038
).toBeUndefined();
10391039
});
10401040

1041-
it('handles oneOf -> allOf returning a string without spreading characters', () => {
1042-
// Create a circular reference that will return "[Circular Reference]" string
1043-
const circularSchema = {
1044-
type: 'object',
1045-
properties: {
1046-
nested: {},
1047-
},
1048-
} satisfies OpenAPIV3.SchemaObject;
1049-
circularSchema.properties.nested = circularSchema;
1050-
1051-
const schema = {
1052-
type: 'object',
1053-
properties: {
1054-
foo: {
1055-
type: 'string',
1056-
},
1057-
},
1058-
oneOf: [
1059-
{
1060-
allOf: [circularSchema],
1061-
},
1062-
],
1063-
} satisfies OpenAPIV3.SchemaObject;
1064-
1065-
const result = generateSchemaExample(schema);
1066-
1067-
expect(result).toBeDefined();
1068-
expect(result).toHaveProperty('foo');
1069-
});
1070-
10711041
it('merges object properties from oneOf -> allOf', () => {
10721042
const schema = {
10731043
type: 'object',

packages/react-openapi/src/generateSchemaExample.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { OpenAPIV3 } from '@gitbook/openapi-parser';
2+
import { isPlainObject } from './contentTypeChecks';
23
import { checkIsReference } from './utils';
34

45
type JSONValue = string | number | boolean | null | JSONValue[] | { [key: string]: JSONValue };
@@ -99,13 +100,6 @@ function guessFromFormat(schema: Record<string, any>, fallback = '') {
99100
return genericExampleValues[schema.format] ?? fallback;
100101
}
101102

102-
/**
103-
* Check if a value is a plain object (not null, not array)
104-
*/
105-
function isPlainObject(value: unknown): value is Record<string, unknown> {
106-
return typeof value === 'object' && value !== null && !Array.isArray(value);
107-
}
108-
109103
/**
110104
* This function takes an OpenAPI schema and generates an example from it
111105
* Forked from : https://github.com/scalar/scalar/blob/main/packages/oas-utils/src/spec-getters/getExampleFromSchema.ts

0 commit comments

Comments
 (0)