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
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
changeKind: feature
packages:
- "@typespec/http-client-java"
---

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
```
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ export interface EmitterOptionsDev {
"enable-subclient"?: boolean;

// not recommended to set
"required-fields-as-ctor-args"?: boolean;
"group-etag-headers"?: boolean;
"enable-sync-stack"?: boolean;
"stream-style-serialization"?: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ public TypeSpecPlugin(EmitterOptions options, boolean sdkIntegration) {
if (options.getPartialUpdate() != null) {
SETTINGS_MAP.put("partial-update", options.getPartialUpdate());
}
if (options.getRequiredFieldsAsConstructorArgs() != null) {
SETTINGS_MAP.put("required-fields-as-ctor-args", options.getRequiredFieldsAsConstructorArgs());
}
if (!CoreUtils.isNullOrEmpty(options.getServiceVersions())) {
SETTINGS_MAP.put("service-versions", options.getServiceVersions());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class EmitterOptions implements JsonSerializable<EmitterOptions> {
private Boolean enableSyncStack = true;
private Boolean streamStyleSerialization = true;
private Boolean partialUpdate;
private Boolean requiredFieldsAsConstructorArgs;
private String customTypes;
private String customTypeSubpackage;
private String customizationClass;
Expand Down Expand Up @@ -85,6 +86,10 @@ public Boolean getPartialUpdate() {
return partialUpdate;
}

public Boolean getRequiredFieldsAsConstructorArgs() {
return requiredFieldsAsConstructorArgs;
}

public Boolean getGenerateTests() {
return generateTests;
}
Expand Down Expand Up @@ -237,6 +242,8 @@ public static EmitterOptions fromJson(JsonReader jsonReader) throws IOException
options.streamStyleSerialization = reader.getNullable(EmitterOptions::getBoolean);
} else if ("partial-update".equals(fieldName)) {
options.partialUpdate = reader.getNullable(EmitterOptions::getBoolean);
} else if ("required-fields-as-ctor-args".equals(fieldName)) {
options.requiredFieldsAsConstructorArgs = reader.getNullable(EmitterOptions::getBoolean);
} else if ("custom-types".equals(fieldName)) {
options.customTypes = emptyToNull(reader.getString());
} else if ("custom-types-subpackage".equals(fieldName)) {
Expand Down
Loading