Skip to content

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

Merged
RobinTail merged 33 commits into
masterfrom
feat-support-custom-schema
May 14, 2024
Merged

Feat: support custom brands handling in Documentation and Integration#1750
RobinTail merged 33 commits into
masterfrom
feat-support-custom-schema

Conversation

@RobinTail

@RobinTail RobinTail commented May 9, 2024

Copy link
Copy Markdown
Owner

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
Comment thread src/documentation.ts Outdated
Comment thread src/schema-walker.ts Outdated
@coveralls-official

coveralls-official Bot commented May 9, 2024

Copy link
Copy Markdown

Coverage Status

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

@RobinTail

Copy link
Copy Markdown
Owner Author

THIS is getting so neat!

@RobinTail RobinTail force-pushed the feat-support-custom-schema branch from c92a3ec to 307c605 Compare May 10, 2024 21:06
@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
Comment thread src/schema-walker.ts
Comment thread src/deep-checks.ts Outdated
@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
Comment thread src/documentation-helpers.ts Outdated
Comment thread src/zts-helpers.ts
Comment thread src/documentation-helpers.ts
Comment thread src/documentation.ts Outdated
Comment thread src/integration.ts Outdated
Comment thread src/index.ts
Comment thread tests/unit/documentation-helpers.spec.ts Outdated

@RobinTail RobinTail left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

ready

Comment thread README.md

@RobinTail RobinTail left a comment

Copy link
Copy Markdown
Owner Author

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
@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.

1 participant