fix: extract nested schemaTypes from arrays in Fastify routes#12
Merged
fix: extract nested schemaTypes from arrays in Fastify routes#12
Conversation
When a schemaType-wrapped schema was used in a Fastify route and contained a Type.Array with another schemaType inside, the inner schema was not being extracted to components/schemas. Root cause: findTaggedSchemasInSchemas used TypeBox's Type.IsArray() which relies on an internal ~kind property that Fastify strips during schema processing. Fix: Replace Type.IsArray(s) with a direct JSON Schema check (s.type === 'array' && s.items !== undefined) that works regardless of whether TypeBox metadata is present. Added tests for: - Basic nested schemaType in arrays - Deeply nested arrays (array of arrays) - Nullable arrays via Type.Union
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a bug where nested
schemaType-wrapped schemas insideType.Arraywere not being extracted tocomponents/schemaswhen used in Fastify routes.Example that was broken:
Root Cause
findTaggedSchemasInSchemasused TypeBox'sType.IsArray()to detect array schemas. However,Type.IsArray()relies on an internal~kindproperty that Fastify strips during schema processing. This caused the array detection to fail, so nested schemas within arrays were never discovered.Fix
Replace
Type.IsArray(s)with a direct JSON Schema check:s.type === 'array' && s.items !== undefined. This approach works regardless of whether TypeBox's internal metadata is present.Test Plan
Type.Union