question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Feature Request]: Meta data/labels

See original GitHub issue

I saw this being mentioned before in another issue, but I’d like to make the request again with a slightly different user story.

My team is looking at replacing Joi with ZodV2 in its Hapi microservice. We really like that we can create an input validation for a handler, and have it tightly coupled to the handler’s input’s type definition. So there is no more worrying about, “Oh, is the validation wrong, or is the input’s typing wrong”. Its the same.

The only loose thread is documentation. We want to create something that parses our Hapi route objects, sees the Zod object we have passed to the validator, and generates a documentation page for that route.

Simply parsing the ZodObject isn’t quite cutting it. It ends up lacking information and context that we’d like, between refinements, transformations, and things that we just want to have more explanation on. If individual Zod elements could have a .label or a .meta property, it’d give us a bit more flexibility in creating documentation that is tightly coupled with our zod schema.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:11
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
lukemtcommented, Jun 5, 2022

What I was imagining he had done was something like this:

import { z, AnyZodObject } from 'zod';

const seatSchema = z.object({
  color: z.string(),
  height: z.number(),
});

const mirrorSchema = z.object({
  color: z.string(),
  width: z.number(),
});

interface Model {
  schema: AnyZodObject;
  label: string;
}

const seat:Model = {
  schema: seatSchema,
  label: "Seat",
}
const mirror:Model = {
  schema: mirrorSchema,
  label: "Mirror",
}

const car = z.object({
  frontLeftSeat: seat,
  frontRightSeat: seat,
  rearLeftSeat: seat,
  rearRightSeat: seat,
  leftMirror: mirror,
  rightMirror: mirror,
});

Object.entries(car.shape).forEach(([key, sub]) => {
    console.log(`${key}: ${sub.label}`);
});

Run with Codesandbox.io

But this isn’t really possible unfortunately.

1reaction
colinhackscommented, Mar 9, 2021

As I’ve suggested in other issues, I recommend doing this by wrapping Zod.

type MyEndpoint<T extends z.Schema<any>> = {
  validator: T;
  label: string;
}

Bringing this inside Zod is a huge footgun and encourages lots of anti-patterns that would be better solved by either creating higher-level constructs that include a Zod schema (like MyEndpoint) or using factory/generator functions that return a schema.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Highcharts dataLabels reposition on overlap - Stack Overflow
I have a Highcharts component where the user can add comments to a graph, and the comment shows up as a dataLabel in...
Read more >
SOLVED: Dynamic Data Labels - Feature Requests / Improvements ...
Not 100% a bug per se, I have some custom Meta Box fields on a settings page used for opening hours. This leads...
Read more >
Adding rich data labels to charts in Excel 2013 - Microsoft
To illustrate some of the features and uses of data labels, let's first look at simple chart. This clustered column chart shows the...
Read more >
DataHub Feature Requests
Vote or request new DataHub Feature Requests features. Subscribe to get updates about new features from DataHub Feature Requests.
Read more >
Feature request: save author/provider as meta data
2. Allows users to keep track of where they sourced their images from by running a custom query for the image, date, author...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found