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

Feat: support custom brands handling in Documentation and Integration #1750

Merged
merged 33 commits into from May 14, 2024

Conversation

RobinTail
Copy link
Owner

@RobinTail RobinTail commented May 9, 2024

Based on #1470 and thanks to #1730

This will be a feature in v19.
I'd like to keep changes of 19.0.0 smaller, making it easier to migrate.
Thus, I'm going to separate breaking changes from features and release this as 19.1.0.

This will be the interface:

import { z } from "zod";
import { Documentation, Integration } from "express-zod-api";

const myBrand = Symbol("MamaToldMeImSpecial"); // I highly recommend using symbols for this purpose
const myBrandedSchema = z.string().brand(myBrand);

new Documentation({
  /* config, routing, title, version */
  brandHandling: {
    [myBrand]: (
      schema: typeof myBrandedSchema, // you should assign type yourself
      { next, path, method, isResponse }, // handle a nested schema using next()
    ) => {
      const defaultResult = next(schema.unwrap()); // { type: string }
      return { summary: "Special type of data" };
    },
  },
});

import ts from "typescript";
const { factory: f } = ts;

new Integration({
  /* routing */
  brandHandling: {
    [myBrand]: (
      schema: typeof myBrandedSchema, // you should assign type yourself
      { next, isResponse, serializer }, // handle a nested schema using next()
    ) => f.createKeywordTypeNode(ts.SyntaxKind.BooleanKeyword),
  },
});

@RobinTail RobinTail added the enhancement New feature or request label May 9, 2024
@RobinTail RobinTail added this to the v19 milestone May 9, 2024
src/documentation.ts Outdated Show resolved Hide resolved
src/schema-walker.ts Outdated Show resolved Hide resolved
Copy link

coveralls-official bot commented May 9, 2024

Coverage Status

coverage: 100.0%. remained the same
when pulling 3c93150 on feat-support-custom-schema
into 38e157c on master.

@RobinTail
Copy link
Owner Author

THIS is getting so neat!

@RobinTail RobinTail mentioned this pull request May 10, 2024
Base automatically changed from make-v19 to master May 13, 2024 21:23
@RobinTail RobinTail marked this pull request as ready for review May 13, 2024 21:33
src/deep-checks.ts Outdated Show resolved Hide resolved
@RobinTail RobinTail removed this from the v19 milestone May 14, 2024
@RobinTail RobinTail added the refactoring The better way to achieve the same result label May 14, 2024
src/documentation.ts Outdated Show resolved Hide resolved
src/integration.ts Outdated Show resolved Hide resolved
src/index.ts Show resolved Hide resolved
Copy link
Owner Author

@RobinTail RobinTail left a comment

Choose a reason for hiding this comment

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

ready

README.md Outdated Show resolved Hide resolved
Copy link
Owner Author

@RobinTail RobinTail left a comment

Choose a reason for hiding this comment

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

ready now

@RobinTail RobinTail changed the title Feat: support custom schema by Documentation and Intergration Feat: support custom brands handling in Documentation and Integration May 14, 2024
@RobinTail RobinTail merged commit a99939b into master May 14, 2024
11 checks passed
@RobinTail RobinTail deleted the feat-support-custom-schema branch May 14, 2024 17:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request refactoring The better way to achieve the same result
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant