Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter undefined values from schema.allOf when generating schema example #2442

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
7 changes: 4 additions & 3 deletions packages/react-openapi/src/generateSchemaExample.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,10 @@ export function generateSchemaExample(
new Set(ancestors).add(schema),
);
}

if (schema.allOf && schema.allOf.length > 0) {
return schema.allOf.reduce(

const filteredAllOf = schema.allOf && schema.allOf.filter(item => item !== undefined)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you give some more context on the issue you are fixing?

How can we end up with allOf items being undefined? Does the spec allow it?
I thought that the allOf should be a list of schema object or references to schema object, typed like this for example:

(ReferenceObject | SchemaObject)[]

Is this an issue in resolving a schema reference maybe? To me sounds more like something we should fix at the schema parsing level rather than having to filter undefined at this level.

if (filteredAllOf && filteredAllOf.length > 0) {
return filteredAllOf.reduce(
(acc, curr) => {
const example = generateSchemaExample(
noReference(curr),
Expand Down
Loading