Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions demo/examples/tests/allOf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,41 @@ paths:
priority:
$ref: "#/components/schemas/Priority"

/allof-incompatible-types:
get:
tags:
- allOf
summary: allOf with Incompatible Types
description: |
Schema with a property whose allOf contains incompatible primitive types
(string and integer).

Schema:
```yaml
type: object
properties:
numero:
allOf:
- type: string
- type: integer
name:
type: string
```
responses:
"200":
description: Successful response
content:
application/json:
schema:
type: object
properties:
numero:
allOf:
- type: string
- type: integer
name:
type: string

/allof-multiple-oneof:
post:
tags:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function mergeAllOf(allOf: SchemaObject) {
};

const mergedSchemas = merge(allOf, { onMergeError }) as SchemaObject;
return mergedSchemas;
return mergedSchemas ?? ({} as SchemaObject);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,36 @@ describe("sampleFromSchema", () => {
expect(result).toBe("dog");
});
});

describe("allOf with incompatible types", () => {
it("should return undefined when allOf contains incompatible types", () => {
const schema: SchemaObject = {
allOf: [{ type: "string" }, { type: "integer" }],
};
const context = { type: "request" as const };

const result = sampleFromSchema(schema, context);

expect(result).toBeUndefined();
});

it("should handle incompatible allOf types in a property", () => {
const schema: SchemaObject = {
type: "object",
properties: {
numero: {
allOf: [{ type: "string" }, { type: "integer" }],
},
name: {
type: "string",
},
},
};
const context = { type: "request" as const };

const result = sampleFromSchema(schema, context);

expect(result.name).toBe("string");
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const mergeAllOf = (allOf: any) => {

const mergedSchemas = merge(allOf, { onMergeError });

return mergedSchemas;
return mergedSchemas ?? {};
};

interface MarkdownProps {
Expand Down
Loading