Skip to content

[http-client-java] mgmt, if resource model is immutable output, innerModel can't be initialized in fluent model implementation ctor #7492

Description

@XiaofeiCao

https://github.com/Azure/azure-rest-api-specs/pull/34322/checks?check_run_id=42881265079

The XXInner model is only used in output, since PUT request is using another model.
https://github.com/Azure/azure-rest-api-specs/blob/8ab62e07ff4f8966e00072b2a634c817a2b57971/specification/nginx/Nginx.Management/NginxConfigurationResponse.tsp#L40-L53

createOrUpdate is Azure.ResourceManager.Legacy.UpdateOperation<
  ResourceInstanceParameters<
    NginxConfigurationResponse,
    Azure.ResourceManager.Foundations.DefaultBaseParameters<NginxConfigurationResponse>
  >,
  NginxConfigurationRequest,
  NginxConfigurationResponse | ArmResourceCreatedResponse<
    NginxConfigurationResponse,
    LroHeaders = ArmAsyncOperationHeader<FinalResult = NginxConfigurationResponse>
  >,
  ErrorResponse,
  OptionalRequestBody = true
>;

In current resource model implementation, we'll initialize innerModel in ctor by name:

NginxConfigurationResponseImpl(String name, com.azure.resourcemanager.nginx.NginxManager serviceManager) {
    this.innerObject = new NginxConfigurationResponseInner();
    this.serviceManager = serviceManager;
    this.configurationName = name;
    this.createBody = new NginxConfigurationRequest();
}

NginxConfigurationResponseInner is output immutable model and only has private ctor, which cannot be initialized.

Possible solution would be,

  1. Do not initialize it in ctor by name, and in simple property methods, check innerModel() != null before returning, e.g.
if (this.innerModel() != null) {
  return this.innerModel().systemData();
}

Though should check other references.

  1. When model is used as fluent response(xxInner), make the ctor public. This is probably not good, since output only model shouldn't be initialized by client(either us or user).

Metadata

Metadata

Assignees

Labels

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

Type

Fields

No fields configured for Bug.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions