-
-
Notifications
You must be signed in to change notification settings - Fork 1k
fix: invalid option error when modifying enums in docsSchema's extend #3936
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
Open
miichom
wants to merge
15
commits into
withastro:main
Choose a base branch
from
miichom:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
f93f7d3
fix: invalid option error when modifying enums in docsSchema's extend
miichom 92ea6bb
[ci] format
miichom f7da3e6
[ci] changeset
miichom 55ff02d
Merge branch 'main' into pr/3936
delucis 038cabf
Add test suites for schema extension
delucis 8c7ce93
Discard changes to README.md
delucis 4b2d4e5
Represent runtime failure in snapshot
delucis 657ebcc
Also add snapshot for hero action
delucis 706e02f
Fix typing failure for nested object
miichom 776508b
Revert typing fixes
miichom 1201a37
chore: cherry-pick code from #4040
miichom 4d5becf
feat: extend docs schema to override existing property with hero actions
miichom 090d769
refactor: move typings and functions to packages/starlight/utils
miichom 8a4e56a
docs(changelog): update release note for Zod enum extension fix
miichom d58283d
refactor(schema): rename schema module to zodDeepMerge for clarity
miichom File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@astrojs/starlight': patch | ||
| --- | ||
|
|
||
| Fixes support for modifying Zod enums when passing an [`extend` option](https://starlight.astro.build/reference/frontmatter/#extend) to Starlight’s `docsSchema()` |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| import { docsSchema } from '@astrojs/starlight/schema'; | ||
| import { z } from 'astro/zod'; | ||
| import { describe, expectTypeOf, test } from 'vitest'; | ||
|
|
||
| interface PartialDocsSchemaOutput { | ||
| title: string; | ||
| description?: string | undefined; | ||
| template: 'doc' | 'splash'; | ||
| sidebar: { | ||
| hidden: boolean; | ||
| }; | ||
| } | ||
|
|
||
| describe('docs schema', () => { | ||
| test('docs schema should parse to expected shape', () => { | ||
| const schema = docsSchema()({ image: () => ({}) as any }); | ||
| const parsed = schema.parse({}); | ||
| expectTypeOf(parsed).toExtend<PartialDocsSchemaOutput>(); | ||
| }); | ||
|
|
||
| test('docs schema should parse to expected shape when making existing key required', () => { | ||
| const schema = docsSchema({ extend: z.object({ description: z.string() }) })({ | ||
| image: () => ({}) as any, | ||
| }); | ||
| const parsed = schema.parse({}); | ||
| expectTypeOf(parsed.description).toBeString(); | ||
| }); | ||
|
|
||
| test('docs schema should parse to expected shape when extending existing enum', () => { | ||
| const schema = docsSchema({ | ||
| extend: z.object({ | ||
| template: z.enum(['doc', 'splash', 'custom']), | ||
| hero: z | ||
| .object({ | ||
| actions: z | ||
| .array( | ||
| z.object({ variant: z.enum(['primary', 'secondary', 'custom']).default('primary') }) | ||
| ) | ||
| .default([]), | ||
| }) | ||
| .optional(), | ||
| }), | ||
| })({ | ||
| image: () => ({}) as any, | ||
| }); | ||
| const parsed = schema.parse({}); | ||
| expectTypeOf(parsed.template).toEqualTypeOf<'doc' | 'splash' | 'custom'>(); | ||
| expectTypeOf(parsed.hero!.actions[0]!.text).toBeString(); | ||
| expectTypeOf(parsed.hero!.actions[0]!.link).toBeString(); | ||
| expectTypeOf(parsed.hero!.actions[0]!.variant).toEqualTypeOf< | ||
| 'primary' | 'secondary' | 'custom' | ||
| >(); | ||
| }); | ||
|
|
||
| test('docs schema should parse to expected shape when adding a custom key', () => { | ||
| const schema = docsSchema({ extend: z.object({ custom: z.string() }) })({ | ||
| image: () => ({}) as any, | ||
| }); | ||
| const parsed = schema.parse({}); | ||
| expectTypeOf(parsed).toExtend<PartialDocsSchemaOutput>(); | ||
| expectTypeOf(parsed.custom).toBeString(); | ||
| }); | ||
|
|
||
| test('docs schema should parse to expected shape when extending a nested object', () => { | ||
| const schema = docsSchema({ | ||
| extend: z.object({ sidebar: z.object({ custom: z.number() }) }), | ||
| })({ | ||
| image: () => ({}) as any, | ||
| }); | ||
| const parsed = schema.parse({}); | ||
| expectTypeOf(parsed).toExtend<PartialDocsSchemaOutput>(); | ||
| expectTypeOf(parsed.sidebar.custom).toBeNumber(); | ||
| }); | ||
| }); | ||
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.