Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
- property `wrongMethodBehavior` (number) changed to `hintAllowedMethods` (boolean);
- property `methodLikeRouteBehavior` (string literal) changed to `recognizeMethodDependentRoutes` (boolean);
- Breaking change to the `Documentation` constructor argument (object):
- property `hasSummaryFromDescription` (boolean) renamed to `hasSummary` (boolean);
- property `hasSummaryFromDescription` renamed to `hasSummary`;
- Breaking change to the `Integration` constructor argument (object):
- property `noContent` renamed to `noBodySchema`;
- Consider using [the automated migration](https://www.npmjs.com/package/@express-zod-api/migration).

```diff
Expand All @@ -28,6 +30,13 @@
});
```

```diff
new Integration({
- noContent: z.undefined(),
+ noBodySchema: z.undefined(),
});
```

## Version 27

### v27.2.0
Expand Down
8 changes: 4 additions & 4 deletions express-zod-api/src/integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ interface IntegrationParams {
* @desc The schema to use for responses without body such as 204
* @default z.undefined()
* */
noContent?: z.ZodType;
noBodySchema?: z.ZodType;
/**
* @desc Depict the HEAD method for each Endpoint supporting the GET method (feature of Express)
* @default true
Expand Down Expand Up @@ -88,7 +88,7 @@ export class Integration extends IntegrationBase {
clientClassName = "Client",
subscriptionClassName = "Subscription",
serverUrl = "https://example.com",
noContent = z.undefined(),
noBodySchema = z.undefined(),
hasHeadMethod = true,
}: IntegrationParams) {
super(typescript, serverUrl);
Expand All @@ -109,10 +109,10 @@ export class Integration extends IntegrationBase {
(agg, responseVariant) => {
const responses = endpoint.getResponses(responseVariant);
const props = R.chain(([idx, { schema, mimeTypes, statusCodes }]) => {
const hasContent = shouldHaveContent(method, mimeTypes);
const hasBody = shouldHaveContent(method, mimeTypes);
const variantType = this.api.makeType(
entitle(responseVariant, "variant", `${idx + 1}`),
zodToTs(hasContent ? schema : noContent, ctxOut),
zodToTs(hasBody ? schema : noBodySchema, ctxOut),
{ comment: request },
);
this.#program.push(variantType);
Expand Down
31 changes: 31 additions & 0 deletions migration/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ describe("Migration", async () => {
`createConfig({ hintAllowedMethods: false });`,
`createConfig({ recognizeMethodDependentRoutes: true });`,
`new Documentation({ hasSummary: false });`,
`new Integration({ noBodySchema: z.undefined() });`,
],
invalid: [
{
Expand Down Expand Up @@ -163,6 +164,36 @@ describe("Migration", async () => {
},
],
},
{
name: "noContent=z.undefined()",
code: `new Integration({ noContent: z.undefined() });`,
output: `new Integration({ noBodySchema: z.undefined() });`,
errors: [
{
messageId: "change",
data: {
subject: "property",
from: "noContent",
to: "noBodySchema",
},
},
],
},
{
name: "noContent=undefined",
code: `new Integration({ noContent: undefined });`,
output: `new Integration({ noBodySchema: undefined });`,
errors: [
{
messageId: "change",
data: {
subject: "property",
from: "noContent",
to: "noBodySchema",
},
},
],
},
],
});
});
16 changes: 15 additions & 1 deletion migration/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ interface Queries {
wrongMethodBehavior: NamedProp;
methodLikeRouteBehavior: NamedProp;
hasSummaryFromDescription: NamedProp;
noContent: NamedProp;
}

type Listener = keyof Queries;
Expand All @@ -30,6 +31,10 @@ const queries: Record<Listener, string> = {
`${NT.NewExpression}[callee.name="Documentation"] > ` +
`${NT.ObjectExpression} > ` +
`${NT.Property}[key.name="hasSummaryFromDescription"]`,
noContent:
`${NT.NewExpression}[callee.name="Integration"] > ` +
`${NT.ObjectExpression} > ` +
`${NT.Property}[key.name="noContent"]`,
};

const listen = <
Expand Down Expand Up @@ -119,7 +124,16 @@ const theRule = ESLintUtils.RuleCreator.withoutDocs({
from: "hasSummaryFromDescription",
to: newKey,
},
fix: (fixer) => [fixer.replaceText(node.key, newKey)],
fix: (fixer) => fixer.replaceText(node.key, newKey),
});
},
noContent: (node) => {
const newKey = "noBodySchema";
ctx.report({
node,
messageId: "change",
data: { subject: "property", from: "noContent", to: newKey },
fix: (fixer) => fixer.replaceText(node.key, newKey),
});
},
}),
Expand Down
Loading