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
Expand Up @@ -134,7 +134,8 @@ public FluentMethodCreateMode() {
.visibility(JavaVisibility.Private)
.methodSignature("boolean isInCreateMode()")
.method(block -> {
block.methodReturn(String.format("this.%1$s().id() == null", ModelNaming.METHOD_INNER_MODEL));
block.methodReturn(String.format("this.%1$s() == null || this.%1$s().id() == null",
ModelNaming.METHOD_INNER_MODEL));
})
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@

package com.microsoft.typespec.http.client.generator.mgmt.model.clientmodel.fluentmodel.method;

import com.microsoft.typespec.http.client.generator.core.extension.plugin.JavaSettings;
import com.microsoft.typespec.http.client.generator.core.model.clientmodel.ClassType;
import com.microsoft.typespec.http.client.generator.core.model.clientmodel.IType;
import com.microsoft.typespec.http.client.generator.core.model.clientmodel.ReturnValue;
import com.microsoft.typespec.http.client.generator.core.model.javamodel.JavaJavadocComment;
import com.microsoft.typespec.http.client.generator.core.model.javamodel.JavaVisibility;
import com.microsoft.typespec.http.client.generator.core.template.prototype.MethodTemplate;
import com.microsoft.typespec.http.client.generator.core.util.ClientModelUtil;
import com.microsoft.typespec.http.client.generator.mgmt.model.clientmodel.FluentResourceModel;
import com.microsoft.typespec.http.client.generator.mgmt.model.clientmodel.ModelNaming;
import com.microsoft.typespec.http.client.generator.mgmt.model.clientmodel.fluentmodel.LocalVariable;
Expand Down Expand Up @@ -40,8 +42,12 @@ public FluentConstructorByName(FluentResourceModel model, FluentMethodType type,
.visibility(JavaVisibility.PackagePrivate)
.methodSignature(this.getImplementationMethodSignature())
.method(block -> {
block.line(String.format("this.%1$s = new %2$s();", ModelNaming.MODEL_PROPERTY_INNER,
model.getInnerModel().getName()));
// Resource model can be immutable output-only(private-ctor), when PUT request body is not resource
// model itself.
if (!ClientModelUtil.isImmutableOutputModel(model.getInnerModel(), JavaSettings.getInstance())) {
block.line(String.format("this.%1$s = new %2$s();", ModelNaming.MODEL_PROPERTY_INNER,
model.getInnerModel().getName()));
}
block.line(String.format("this.%1$s = %2$s;", ModelNaming.MODEL_PROPERTY_MANAGER,
ModelNaming.MODEL_PROPERTY_MANAGER));
if (!constantResourceName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@
import tsptest.armresourceprovider.implementation.ChildExtensionResourceInterfacesImpl;
import tsptest.armresourceprovider.implementation.ChildResourcesInterfacesImpl;
import tsptest.armresourceprovider.implementation.CustomTemplateResourceInterfacesImpl;
import tsptest.armresourceprovider.implementation.ImmutableResourceModelsImpl;
import tsptest.armresourceprovider.implementation.ManagedMaintenanceWindowStatusOperationsImpl;
import tsptest.armresourceprovider.implementation.ModelInterfaceSameNamesImpl;
import tsptest.armresourceprovider.implementation.OperationsImpl;
import tsptest.armresourceprovider.implementation.TopLevelArmResourceInterfacesImpl;
import tsptest.armresourceprovider.models.ChildExtensionResourceInterfaces;
import tsptest.armresourceprovider.models.ChildResourcesInterfaces;
import tsptest.armresourceprovider.models.CustomTemplateResourceInterfaces;
import tsptest.armresourceprovider.models.ImmutableResourceModels;
import tsptest.armresourceprovider.models.ManagedMaintenanceWindowStatusOperations;
import tsptest.armresourceprovider.models.ModelInterfaceSameNames;
import tsptest.armresourceprovider.models.Operations;
Expand All @@ -67,6 +69,8 @@ public final class ArmResourceProviderManager {

private ModelInterfaceSameNames modelInterfaceSameNames;

private ImmutableResourceModels immutableResourceModels;

private final ArmClient clientObject;

private ArmResourceProviderManager(HttpPipeline httpPipeline, AzureProfile profile, Duration defaultPollInterval) {
Expand Down Expand Up @@ -372,6 +376,19 @@ public ModelInterfaceSameNames modelInterfaceSameNames() {
return modelInterfaceSameNames;
}

/**
* Gets the resource collection API of ImmutableResourceModels. It manages NginxConfigurationResponse.
*
* @return Resource collection API of ImmutableResourceModels.
*/
public ImmutableResourceModels immutableResourceModels() {
if (this.immutableResourceModels == null) {
this.immutableResourceModels
= new ImmutableResourceModelsImpl(clientObject.getImmutableResourceModels(), this);
}
return immutableResourceModels;
}

/**
* Gets wrapped service client ArmClient providing direct access to the underlying auto-generated API
* implementation, based on Azure REST API.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,11 @@ public interface ArmClient {
* @return the ModelInterfaceSameNamesClient object.
*/
ModelInterfaceSameNamesClient getModelInterfaceSameNames();

/**
* Gets the ImmutableResourceModelsClient object to access its operations.
*
* @return the ImmutableResourceModelsClient object.
*/
ImmutableResourceModelsClient getImmutableResourceModels();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) TypeSpec Code Generator.

package tsptest.armresourceprovider.fluent;

import com.azure.core.annotation.ReturnType;
import com.azure.core.annotation.ServiceMethod;
import com.azure.core.management.polling.PollResult;
import com.azure.core.util.Context;
import com.azure.core.util.polling.SyncPoller;
import tsptest.armresourceprovider.fluent.models.NginxConfigurationResponseInner;
import tsptest.armresourceprovider.models.NginxConfigurationRequest;

/**
* An instance of this class provides access to all the operations defined in ImmutableResourceModelsClient.
*/
public interface ImmutableResourceModelsClient {
/**
* The createOrUpdate operation.
*
* @param resourceGroupName The name of the resource group. The name is case insensitive.
* @param configurationName The name of the NginxConfigurationResponse.
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
* @return the {@link SyncPoller} for polling of concrete proxy resource types can be created by aliasing this type
* using a specific property type.
*/
@ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
SyncPoller<PollResult<NginxConfigurationResponseInner>, NginxConfigurationResponseInner>
beginCreateOrUpdate(String resourceGroupName, String configurationName);

/**
* The createOrUpdate operation.
*
* @param resourceGroupName The name of the resource group. The name is case insensitive.
* @param configurationName The name of the NginxConfigurationResponse.
* @param properties The resource properties to be updated.
* @param context The context to associate with this operation.
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
* @return the {@link SyncPoller} for polling of concrete proxy resource types can be created by aliasing this type
* using a specific property type.
*/
@ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
SyncPoller<PollResult<NginxConfigurationResponseInner>, NginxConfigurationResponseInner> beginCreateOrUpdate(
String resourceGroupName, String configurationName, NginxConfigurationRequest properties, Context context);

/**
* The createOrUpdate operation.
*
* @param resourceGroupName The name of the resource group. The name is case insensitive.
* @param configurationName The name of the NginxConfigurationResponse.
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
* @return concrete proxy resource types can be created by aliasing this type using a specific property type.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
NginxConfigurationResponseInner createOrUpdate(String resourceGroupName, String configurationName);

/**
* The createOrUpdate operation.
*
* @param resourceGroupName The name of the resource group. The name is case insensitive.
* @param configurationName The name of the NginxConfigurationResponse.
* @param properties The resource properties to be updated.
* @param context The context to associate with this operation.
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
* @return concrete proxy resource types can be created by aliasing this type using a specific property type.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
NginxConfigurationResponseInner createOrUpdate(String resourceGroupName, String configurationName,
NginxConfigurationRequest properties, Context context);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) TypeSpec Code Generator.

package tsptest.armresourceprovider.fluent.models;

import com.azure.core.annotation.Immutable;
import com.azure.core.management.ProxyResource;
import com.azure.core.management.SystemData;
import com.azure.json.JsonReader;
import com.azure.json.JsonToken;
import com.azure.json.JsonWriter;
import java.io.IOException;
import tsptest.armresourceprovider.models.NginxConfigurationResponseProperties;

/**
* Concrete proxy resource types can be created by aliasing this type using a specific property type.
*/
@Immutable
public final class NginxConfigurationResponseInner extends ProxyResource {
/*
* The resource-specific properties for this resource.
*/
private NginxConfigurationResponseProperties properties;

/*
* Azure Resource Manager metadata containing createdBy and modifiedBy information.
*/
private SystemData systemData;

/*
* The type of the resource.
*/
private String type;

/*
* The name of the resource.
*/
private String name;

/*
* Fully qualified resource Id for the resource.
*/
private String id;

/**
* Creates an instance of NginxConfigurationResponseInner class.
*/
private NginxConfigurationResponseInner() {
}

/**
* Get the properties property: The resource-specific properties for this resource.
*
* @return the properties value.
*/
public NginxConfigurationResponseProperties properties() {
return this.properties;
}

/**
* Get the systemData property: Azure Resource Manager metadata containing createdBy and modifiedBy information.
*
* @return the systemData value.
*/
public SystemData systemData() {
return this.systemData;
}

/**
* Get the type property: The type of the resource.
*
* @return the type value.
*/
@Override
public String type() {
return this.type;
}

/**
* Get the name property: The name of the resource.
*
* @return the name value.
*/
@Override
public String name() {
return this.name;
}

/**
* Get the id property: Fully qualified resource Id for the resource.
*
* @return the id value.
*/
@Override
public String id() {
return this.id;
}

/**
* Validates the instance.
*
* @throws IllegalArgumentException thrown if the instance is not valid.
*/
public void validate() {
if (properties() != null) {
properties().validate();
}
}

/**
* {@inheritDoc}
*/
@Override
public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
jsonWriter.writeStartObject();
jsonWriter.writeJsonField("properties", this.properties);
return jsonWriter.writeEndObject();
}

/**
* Reads an instance of NginxConfigurationResponseInner from the JsonReader.
*
* @param jsonReader The JsonReader being read.
* @return An instance of NginxConfigurationResponseInner if the JsonReader was pointing to an instance of it, or
* null if it was pointing to JSON null.
* @throws IllegalStateException If the deserialized JSON object was missing any required properties.
* @throws IOException If an error occurs while reading the NginxConfigurationResponseInner.
*/
public static NginxConfigurationResponseInner fromJson(JsonReader jsonReader) throws IOException {
return jsonReader.readObject(reader -> {
NginxConfigurationResponseInner deserializedNginxConfigurationResponseInner
= new NginxConfigurationResponseInner();
while (reader.nextToken() != JsonToken.END_OBJECT) {
String fieldName = reader.getFieldName();
reader.nextToken();

if ("id".equals(fieldName)) {
deserializedNginxConfigurationResponseInner.id = reader.getString();
} else if ("name".equals(fieldName)) {
deserializedNginxConfigurationResponseInner.name = reader.getString();
} else if ("type".equals(fieldName)) {
deserializedNginxConfigurationResponseInner.type = reader.getString();
} else if ("properties".equals(fieldName)) {
deserializedNginxConfigurationResponseInner.properties
= NginxConfigurationResponseProperties.fromJson(reader);
} else if ("systemData".equals(fieldName)) {
deserializedNginxConfigurationResponseInner.systemData = SystemData.fromJson(reader);
} else {
reader.skipChildren();
}
}

return deserializedNginxConfigurationResponseInner;
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import tsptest.armresourceprovider.fluent.ChildExtensionResourceInterfacesClient;
import tsptest.armresourceprovider.fluent.ChildResourcesInterfacesClient;
import tsptest.armresourceprovider.fluent.CustomTemplateResourceInterfacesClient;
import tsptest.armresourceprovider.fluent.ImmutableResourceModelsClient;
import tsptest.armresourceprovider.fluent.ManagedMaintenanceWindowStatusOperationsClient;
import tsptest.armresourceprovider.fluent.ModelInterfaceSameNamesClient;
import tsptest.armresourceprovider.fluent.OperationsClient;
Expand Down Expand Up @@ -230,6 +231,20 @@ public ModelInterfaceSameNamesClient getModelInterfaceSameNames() {
return this.modelInterfaceSameNames;
}

/**
* The ImmutableResourceModelsClient object to access its operations.
*/
private final ImmutableResourceModelsClient immutableResourceModels;

/**
* Gets the ImmutableResourceModelsClient object to access its operations.
*
* @return the ImmutableResourceModelsClient object.
*/
public ImmutableResourceModelsClient getImmutableResourceModels() {
return this.immutableResourceModels;
}

/**
* Initializes an instance of ArmClient client.
*
Expand All @@ -255,6 +270,7 @@ public ModelInterfaceSameNamesClient getModelInterfaceSameNames() {
this.childExtensionResourceInterfaces = new ChildExtensionResourceInterfacesClientImpl(this);
this.managedMaintenanceWindowStatusOperations = new ManagedMaintenanceWindowStatusOperationsClientImpl(this);
this.modelInterfaceSameNames = new ModelInterfaceSameNamesClientImpl(this);
this.immutableResourceModels = new ImmutableResourceModelsClientImpl(this);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,6 @@ public ChildResourceImpl withTags(Map<String, String> tags) {
}

private boolean isInCreateMode() {
return this.innerModel().id() == null;
return this.innerModel() == null || this.innerModel().id() == null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,6 @@ public CustomTemplateResourceImpl withIfNoneMatch(String ifNoneMatch) {
}

private boolean isInCreateMode() {
return this.innerModel().id() == null;
return this.innerModel() == null || this.innerModel().id() == null;
}
}
Loading