Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
- property `methodLikeRouteBehavior` (string literal) changed to `recognizeMethodDependentRoutes` (boolean);
- Breaking change to the `Documentation` constructor argument (object):
- property `hasSummaryFromDescription` (boolean) renamed to `hasSummary` (boolean);
- 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,11 @@
});
```

```diff
- new Integration({ noContent: z.undefined() });
+ new Integration({ 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",
},
},
],
},
],
});
});
14 changes: 14 additions & 0 deletions 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 @@ -122,6 +127,15 @@ const theRule = ESLintUtils.RuleCreator.withoutDocs({
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