Skip to content

feat(http-client-java): expose required-fields-as-ctor-args option to tspconfig#11380

Merged
weidongxu-microsoft merged 2 commits into
microsoft:mainfrom
weidongxu-microsoft:weidongxu-microsoft/required-fields-as-ctor-args-option
Jul 24, 2026
Merged

feat(http-client-java): expose required-fields-as-ctor-args option to tspconfig#11380
weidongxu-microsoft merged 2 commits into
microsoft:mainfrom
weidongxu-microsoft:weidongxu-microsoft/required-fields-as-ctor-args-option

Conversation

@weidongxu-microsoft

Copy link
Copy Markdown
Contributor

Expose the required-fields-as-ctor-args emitter option to tspconfig.yaml for data-plane. Previously it was hard-coded to true in TypeSpecPlugin. The default remains true; users can now opt out.

options:
  "@typespec/http-client-java":
    required-fields-as-ctor-args: false

Changes

  • emitter/src/code-model-builder.ts — add required-fields-as-ctor-args to EmitterOptionsDev so the option flows from tspconfig into the JSON passed to the Java generator.
  • generator/.../model/EmitterOptions.java — add field, getter, and JSON parsing.
  • generator/.../TypeSpecPlugin.java — override the setting only when the user sets it; the static default stays true.

… tspconfig

Expose the 'required-fields-as-ctor-args' emitter option in tspconfig.yaml
for data-plane. It controls whether required model properties are generated
as constructor arguments. The default remains true.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 042a4299-1ab4-46bf-8b66-7ce223d6272c
@weidongxu-microsoft

Copy link
Copy Markdown
Contributor Author

Validation performed

Built the emitter + Java generator, packed via Setup.ps1, then generated a model with required properties twice from the same spec — once with the default and once overriding the option — and compared the generated Widget model.

Spec used:

model Widget {
  @visibility(Lifecycle.Read)
  id: string;

  requiredName: string;
  requiredCount: int32;
  optionalDescription?: string;
}

Default (required-fields-as-ctor-args: true) — required fields become constructor args, no setters:

public Widget(String requiredName, int requiredCount) {
    this.requiredName = requiredName;
    this.requiredCount = requiredCount;
}

Override (required-fields-as-ctor-args: false) — no-arg constructor, required fields get setters:

public Widget() {
}

public Widget setRequiredName(String requiredName) { ... }

public Widget setRequiredCount(int requiredCount) { ... }

This confirms the option flows from tspconfig.yaml through the emitter into the Java generator, and that the default behavior is unchanged (true).

@microsoft-github-policy-service microsoft-github-policy-service Bot added the emitter:client:java Issue for the Java client emitter: @typespec/http-client-java label Jul 24, 2026
…commended to set'

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 042a4299-1ab4-46bf-8b66-7ce223d6272c
@github-actions

Copy link
Copy Markdown
Contributor

All changed packages have been documented.

  • @typespec/http-client-java
Show changes

@typespec/http-client-java - feature ✏️

Expose the required-fields-as-ctor-args emitter option in tspconfig.yaml. It controls whether required model properties are generated as constructor arguments. The default remains true.,> ,> yaml,> options:,> "@typespec/http-client-java":,> required-fields-as-ctor-args: false,>

@azure-sdk-automation

azure-sdk-automation Bot commented Jul 24, 2026

Copy link
Copy Markdown

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

@weidongxu-microsoft
weidongxu-microsoft marked this pull request as ready for review July 24, 2026 02:34
@weidongxu-microsoft

Copy link
Copy Markdown
Contributor Author

with the improved instruction https://github.com/microsoft/typespec/blob/main/.github/instructions/http-client-java.instructions.md#modify-the-code-generator-emitter--generator-e2e-loop
now we can just ask agent to write a tsp and test -- kind of close the loop of impl :-)

@weidongxu-microsoft
weidongxu-microsoft added this pull request to the merge queue Jul 24, 2026
Merged via the queue into microsoft:main with commit ec09e28 Jul 24, 2026
34 of 35 checks passed
@weidongxu-microsoft
weidongxu-microsoft deleted the weidongxu-microsoft/required-fields-as-ctor-args-option branch July 24, 2026 03:57
weidongxu-microsoft added a commit to Azure/typespec-azure that referenced this pull request Jul 24, 2026
…a options.ts

Document the required-fields-as-ctor-args emitter option (exposed upstream in
microsoft/typespec#11380) in the maintained Azure emitter options schema, but
keep it commented out so users do not set it unless explicitly told to. It is a
backward-compatibility option; the default (true) is unchanged.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: cd6f2e08-d6d3-42ae-affd-bc71e98086f7
weidongxu-microsoft added a commit to Azure/typespec-azure that referenced this pull request Jul 24, 2026
…typespec#11380) (#5043)

Bumps the pinned core commit to include
[microsoft/typespec#11380](microsoft/typespec#11380),
which exposes the + ' equired-fields-as-ctor-args' + emitter option to +
' spconfig.yaml' + for data-plane (default remains + ' rue' + ).

## Changes
- + 'core-commit.json' + pin: + '43ff0041' + -> + '�c09e28b' + (HEAD of
core + 'main' + , the #11380 merge commit).
- Ran + 'SyncTests.ps1' + against the new pin: no test-suite (src/tsp)
changes between the previous pin and this commit — #11380 only touches
emitter/generator source, which is copied at build time.
- Added chronus  + 'ix' +  change (next version: 0.45.10).

+ 'Generate.ps1' + / + 'Copy-Sources.ps1' + need no changes: #11380 is a
purely additive emitter option with no spec-generation impact.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: cd6f2e08-d6d3-42ae-affd-bc71e98086f7

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: cd6f2e08-d6d3-42ae-affd-bc71e98086f7
weidongxu-microsoft added a commit to Azure/typespec-azure that referenced this pull request Jul 24, 2026
Version bump for the typespec-java hotfix **0.45.10**, following the
sync in #5043.

## Included changes (consumed from  + '.chronus/changes' + )
- **fix**: Expose the + ' equired-fields-as-ctor-args' + emitter option
in + ' spconfig.yaml' + (microsoft/typespec#11380). Default remains + '
rue' + .
- **internal**: Make the + 'core-commit.json' + pin authoritative in +
'CoreCommit.ps1' + (#5016).

## Files
-  + 'packages/typespec-java/package.json' +  -> 0.45.10
-  + 'packages/typespec-java/CHANGELOG.md' + 
- + 'packages/typespec-java/emitter-tests/package.json' + -> 0.45.10
(version + + '.tgz' + dep)
- Deleted the two consumed typespec-java change files

Only + '@azure-tools/typespec-java' + is bumped. Non-java pending change
files (tcgc, benchmark, playground, website) were intentionally left
untouched. The + 'core' + submodule is unchanged.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: cd6f2e08-d6d3-42ae-affd-bc71e98086f7

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: cd6f2e08-d6d3-42ae-affd-bc71e98086f7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

emitter:client:java Issue for the Java client emitter: @typespec/http-client-java

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants