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

Exp: Pull examples from object schema props #2324

Draft
wants to merge 16 commits into
base: master
Choose a base branch
from

Conversation

RobinTail
Copy link
Owner

@RobinTail RobinTail commented Jan 18, 2025

When describing examples of the IO schemas only top level calls of .example() method used to be taken into account in the generated Documentation

factory.build({
  input: z
    .object({
      key: z.string().nonempty(),
    })
    .example({
      key: "1234-5678-90",
    }),
})

This feature enabled pulling examples up from the shape of object schema properties, so the syntax can be simplified:

factory.build({
  input: z.object({
    key: z.string().nonempty().example("1234-5678-90"),
  }),
})

@RobinTail RobinTail added enhancement New feature or request miracle Mysterious events are happening here labels Jan 18, 2025
@RobinTail RobinTail force-pushed the exp-proxy-object-prop-examples branch from 0141805 to 2df1e67 Compare January 18, 2025 20:35
@RobinTail RobinTail changed the title Exp: Collect examples from object props Exp: Pull examples from object props Jan 19, 2025
@RobinTail RobinTail changed the title Exp: Pull examples from object props Exp: Pull examples from object schema shape Jan 19, 2025
Copy link

coveralls-official bot commented Jan 19, 2025

Coverage Status

coverage: 100.0%. remained the same
when pulling 61b7ed7 on exp-proxy-object-prop-examples
into 85e5f54 on master.

src/common-helpers.ts Outdated Show resolved Hide resolved
@RobinTail RobinTail force-pushed the exp-proxy-object-prop-examples branch from f85cd02 to 90732f4 Compare January 19, 2025 11:27
@RobinTail
Copy link
Owner Author

RobinTail commented Jan 19, 2025

I want to revisit the composition of the established workflow involved into depicting examples in the generated documentation:

  • getFinalEndpointInputSchema
  • extractObjectSchema
  • getExamples

Perhaps something here should be simplified

@RobinTail RobinTail changed the title Exp: Pull examples from object schema shape Exp: Pull examples from object schema props Jan 19, 2025
@RobinTail
Copy link
Owner Author

RobinTail commented Jan 20, 2025

  • getFinalEndpointInputSchema
  • extractObjectSchema
  • getExamples
    Perhaps something here should be simplified

Reviewed. Once again, it can be simplified but for input flow only (moving copyMeta from getFinalEndpointInputSchema and the pulling from getExamples into extractObjectSchema).
The response part does not go through extractObjectSchema, because it can be not object-based.
The approach also complicates extractObjectSchema significantly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request miracle Mysterious events are happening here
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant