Skip to content

feat(generate): accept type and crud options on the resource schematic#3402

Merged
kamilmysliwiec merged 1 commit intonestjs:v12.0.0from
yogeshwaran-c:feat/generate-type-crud-v12
Apr 17, 2026
Merged

feat(generate): accept type and crud options on the resource schematic#3402
kamilmysliwiec merged 1 commit intonestjs:v12.0.0from
yogeshwaran-c:feat/generate-type-crud-v12

Conversation

@yogeshwaran-c
Copy link
Copy Markdown
Contributor

What kind of change does this PR introduce?

Bug-fix backport from master to v12.0.0, with added unit tests.

What is the current behavior?

The @nestjs/schematics resource generator defines --type and --crud options in its schema.json. On master the CLI registers and forwards them (see #3275, which closed #3229). On v12.0.0 neither flag is wired up, so:

nest g resource users --type rest --crud

exits with error: unknown option '--type' even though the schematic itself would consume both flags correctly.

What is the new behavior?

  • Register --type [type] and --crud on the generate command
  • Forward both into GenerateCommandContext and on to the schematic
  • Only forward --crud when explicitly passed so users who never opted in aren't affected

After this PR:

nest g resource users --type rest --crud
# Generates src/users/{users.module.ts, users.controller.ts, users.service.ts, dto/, entities/}

Additional context

The original master PR noted "No automated tests were added because there are no existing e2e tests for generate resource." This PR adds a focused unit spec (test/actions/generate.action.spec.ts) covering the new option wiring end-to-end at the action layer — forwarded when set, omitted when undefined/false.

Files changed:

  • commands/generate.command.ts — register --type / --crud, populate context
  • commands/context/generate.context.ts — extend GenerateCommandContext
  • actions/generate.action.ts — push type / crud schematic options
  • test/actions/generate.action.spec.ts — new unit spec (6 cases)

Closes #3229 for the v12 line.

Test plan

Backports the master-branch fix for nestjs#3229 (PR nestjs#3275) to v12.0.0. The
`@nestjs/schematics` resource generator defines `--type` and `--crud`
options in its schema.json, but the v12 CLI does not register either
flag on the `generate` command. Running:

    nest g resource users --type rest --crud

exits with "error: unknown option '--type'" even though the schematic
itself would handle both flags correctly.

- register `--type [type]` and `--crud` on the generate command
- forward both into the generate action and on to the schematic
- only forward `--crud` when explicitly passed (avoid toggling default
  behavior on users who never opted in)

The master-branch PR noted that "no automated tests were added because
there are no existing e2e tests for generate resource" — this PR adds a
focused unit spec for `GenerateAction` covering forwarding of the new
options individually and together.
@kamilmysliwiec kamilmysliwiec merged commit 8c97b63 into nestjs:v12.0.0 Apr 17, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants