diff --git a/CHANGELOG.md b/CHANGELOG.md index c0cd70617..287f17016 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 @@ -28,6 +30,13 @@ }); ``` +```diff + new Integration({ +- noContent: z.undefined(), ++ noBodySchema: z.undefined(), + }); +``` + ## Version 27 ### v27.2.0 diff --git a/express-zod-api/src/integration.ts b/express-zod-api/src/integration.ts index 9f58bffe7..f4ccdb9ab 100644 --- a/express-zod-api/src/integration.ts +++ b/express-zod-api/src/integration.ts @@ -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 @@ -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); @@ -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); diff --git a/migration/index.spec.ts b/migration/index.spec.ts index 94f23ab14..f4729e26e 100644 --- a/migration/index.spec.ts +++ b/migration/index.spec.ts @@ -26,6 +26,7 @@ describe("Migration", async () => { `createConfig({ hintAllowedMethods: false });`, `createConfig({ recognizeMethodDependentRoutes: true });`, `new Documentation({ hasSummary: false });`, + `new Integration({ noBodySchema: z.undefined() });`, ], invalid: [ { @@ -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", + }, + }, + ], + }, ], }); }); diff --git a/migration/index.ts b/migration/index.ts index 42af10232..67f5de649 100644 --- a/migration/index.ts +++ b/migration/index.ts @@ -13,6 +13,7 @@ interface Queries { wrongMethodBehavior: NamedProp; methodLikeRouteBehavior: NamedProp; hasSummaryFromDescription: NamedProp; + noContent: NamedProp; } type Listener = keyof Queries; @@ -30,6 +31,10 @@ const queries: Record = { `${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 = < @@ -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), }); }, }),