Skip to content

Commit

Permalink
bump tcgc and typespec-java, support api-version (#2722)
Browse files Browse the repository at this point in the history
* package.json

* allow specifying api-version

* test case

* bump version

* re-generate test code

* address comments

* fix Generate.ps1

---------

Co-authored-by: actions-user <[email protected]>
  • Loading branch information
XiaofeiCao and actions-user authored Apr 26, 2024
1 parent 77ca3a9 commit 7103f43
Show file tree
Hide file tree
Showing 19 changed files with 65 additions and 246 deletions.
7 changes: 7 additions & 0 deletions typespec-extension/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Release History

## 0.15.13 (2024-04-26)

Compatible with compiler 0.55.

- Supported `api-version` from typespec config.
- Update dependency of "typespec-client-generator-core" for bug fix.

## 0.15.12 (2024-04-20)

Compatible with compiler 0.55.
Expand Down
14 changes: 7 additions & 7 deletions typespec-extension/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions typespec-extension/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@azure-tools/typespec-java",
"version": "0.15.12",
"version": "0.15.13",
"description": "TypeSpec library for emitting Java client from the TypeSpec REST protocol binding",
"keywords": [
"TypeSpec"
Expand Down Expand Up @@ -51,7 +51,7 @@
"@typespec/openapi": ">=0.55.0 <1.0.0",
"@typespec/versioning": ">=0.55.0 <1.0.0",
"@azure-tools/typespec-azure-core": ">=0.41.0 <1.0.0",
"@azure-tools/typespec-client-generator-core": ">=0.41.4 <1.0.0"
"@azure-tools/typespec-client-generator-core": ">=0.41.6 <1.0.0"
},
"dependencies": {
"@autorest/codemodel": "~4.20.0",
Expand All @@ -73,7 +73,7 @@
"@typescript-eslint/eslint-plugin": "~7.7.0",
"eslint-plugin-deprecation": "~2.0.0",
"@azure-tools/typespec-azure-core": "0.41.0",
"@azure-tools/typespec-client-generator-core": "0.41.4",
"@azure-tools/typespec-client-generator-core": "0.41.6",
"@typespec/compiler": "0.55.0",
"@typespec/http": "0.55.0",
"@typespec/openapi": "0.55.0",
Expand Down
1 change: 1 addition & 0 deletions typespec-extension/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ options:
models-subpackage: "models"
custom-types-subpackage: "implementation.models"
custom-types: InternalModel1,InternalModel2
api-version: "2023-11-01"
```
## Convenience API
Expand Down
14 changes: 8 additions & 6 deletions typespec-extension/src/code-model-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,6 @@ export class CodeModelBuilder {
}

this.sdkContext = createSdkContext(context, "@azure-tools/typespec-java");
if (this.supportsAdvancedVersioning()) {
this.sdkContext.apiVersion = "all";
} else {
this.sdkContext.apiVersion = "latest";
}
const service = listServices(this.program)[0];
const serviceNamespace = service.type;
if (serviceNamespace === undefined) {
Expand Down Expand Up @@ -570,7 +565,14 @@ export class CodeModelBuilder {
codeModelClient.apiVersions.push(apiVersion);
}

this.apiVersion = getDefaultApiVersion(this.sdkContext, client.service);
if (!this.sdkContext.apiVersion || ["all", "latest"].includes(this.sdkContext.apiVersion)) {
this.apiVersion = getDefaultApiVersion(this.sdkContext, client.service);
} else {
this.apiVersion = versioning.getVersions().find((it: Version) => it.value === this.sdkContext.apiVersion);
if (!this.apiVersion) {
throw new Error("Unrecognized api-version: " + this.sdkContext.apiVersion);
}
}
}

// server
Expand Down
2 changes: 2 additions & 0 deletions typespec-extension/src/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export interface EmitterOptions {
"group-etag-headers"?: boolean;

"advanced-versioning"?: boolean;
"api-version"?: string;

"dev-options"?: DevOptions;
}
Expand Down Expand Up @@ -93,6 +94,7 @@ const EmitterOptionsSchema: JSONSchemaType<EmitterOptions> = {

"group-etag-headers": { type: "boolean", nullable: true },
"advanced-versioning": { type: "boolean", nullable: true, default: false },
"api-version": { type: "string", nullable: true },

"dev-options": { type: "object", additionalProperties: true, nullable: true },
},
Expand Down
7 changes: 7 additions & 0 deletions typespec-tests/Generate.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,23 @@ $generateScript = {
$tspOptions += " --option ""@azure-tools/typespec-java.namespace=com.resiliency.servicedriven.v1"""
# enable advanced versioning for resiliency test
$tspOptions += " --option ""@azure-tools/typespec-java.advanced-versioning=true"""
$tspOptions += " --option ""@azure-tools/typespec-java.api-version=all"""
} elseif ($tspFile -match "resiliency[\\/]srv-driven[\\/]main.tsp") {
# enable advanced versioning for resiliency test
$tspOptions += " --option ""@azure-tools/typespec-java.advanced-versioning=true"""
$tspOptions += " --option ""@azure-tools/typespec-java.api-version=all"""
} elseif ($tspFile -match "tsp[\\/]versioning.tsp") {
# test generating from specific api-version
$tspOptions += " --option ""@azure-tools/typespec-java.api-version=2022-09-01"""
} elseif ($tspFile -match "arm.tsp") {
# for mgmt, do not generate tests due to random mock values
$tspOptions += " --option ""@azure-tools/typespec-java.generate-tests=false"""
# also don't generate with stream-style-serialization as azure-core-management hasn't migrated to azure-json yet
$tspOptions += " --option ""@azure-tools/typespec-java.stream-style-serialization=false"""
# also generate with group-etag-headers=false since mgmt doesn't support etag grouping yet
$tspOptions += " --option ""@azure-tools/typespec-java.group-etag-headers=false"""
# also test generating from specific api-version
$tspOptions += " --option ""@azure-tools/typespec-java.api-version=2023-11-01"""
}

# Test customization for one of the TypeSpec definitions - naming.tsp
Expand Down
4 changes: 2 additions & 2 deletions typespec-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"dependencies": {
"@azure-tools/cadl-ranch-specs": "0.32.0",
"@azure-tools/typespec-java": "file:/../typespec-extension/azure-tools-typespec-java-0.15.12.tgz"
"@azure-tools/typespec-java": "file:/../typespec-extension/azure-tools-typespec-java-0.15.13.tgz"
},
"devDependencies": {
"@typespec/prettier-plugin-typespec": "~0.55.0",
Expand All @@ -25,7 +25,7 @@
"@typespec/versioning": ">=0.55.0 <1.0.0",
"@typespec/openapi": ">=0.55.0 <1.0.0",
"@azure-tools/typespec-azure-core": ">=0.41.0 <1.0.0",
"@azure-tools/typespec-client-generator-core": ">=0.41.4 <1.0.0"
"@azure-tools/typespec-client-generator-core": ">=0.41.6 <1.0.0"
},
"private": true
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,29 +106,6 @@ public ProvisioningState provisioningState() {
return this.innerProperties() == null ? null : this.innerProperties().provisioningState();
}

/**
* Get the propertyRemovedInStable property: The propertyRemovedInStable property.
*
* @return the propertyRemovedInStable value.
*/
public String propertyRemovedInStable() {
return this.innerProperties() == null ? null : this.innerProperties().propertyRemovedInStable();
}

/**
* Set the propertyRemovedInStable property: The propertyRemovedInStable property.
*
* @param propertyRemovedInStable the propertyRemovedInStable value to set.
* @return the CustomTemplateResourceInner object itself.
*/
public CustomTemplateResourceInner withPropertyRemovedInStable(String propertyRemovedInStable) {
if (this.innerProperties() == null) {
this.innerProperties = new CustomTemplateResourceProperties();
}
this.innerProperties().withPropertyRemovedInStable(propertyRemovedInStable);
return this;
}

/**
* Validates the instance.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,21 @@

package com.cadl.armresourceprovider.fluent.models;

import com.azure.core.annotation.Fluent;
import com.azure.core.util.logging.ClientLogger;
import com.azure.core.annotation.Immutable;
import com.cadl.armresourceprovider.models.ProvisioningState;
import com.fasterxml.jackson.annotation.JsonProperty;

/**
* Top Level Arm Resource Properties.
*/
@Fluent
@Immutable
public final class CustomTemplateResourceProperties {
/*
* The status of the last operation.
*/
@JsonProperty(value = "provisioningState", access = JsonProperty.Access.WRITE_ONLY)
private ProvisioningState provisioningState;

/*
* The propertyRemovedInStable property.
*/
@JsonProperty(value = "propertyRemovedInStable", required = true)
private String propertyRemovedInStable;

/**
* Creates an instance of CustomTemplateResourceProperties class.
*/
Expand All @@ -41,38 +34,11 @@ public ProvisioningState provisioningState() {
return this.provisioningState;
}

/**
* Get the propertyRemovedInStable property: The propertyRemovedInStable property.
*
* @return the propertyRemovedInStable value.
*/
public String propertyRemovedInStable() {
return this.propertyRemovedInStable;
}

/**
* Set the propertyRemovedInStable property: The propertyRemovedInStable property.
*
* @param propertyRemovedInStable the propertyRemovedInStable value to set.
* @return the CustomTemplateResourceProperties object itself.
*/
public CustomTemplateResourceProperties withPropertyRemovedInStable(String propertyRemovedInStable) {
this.propertyRemovedInStable = propertyRemovedInStable;
return this;
}

/**
* Validates the instance.
*
* @throws IllegalArgumentException thrown if the instance is not valid.
*/
public void validate() {
if (propertyRemovedInStable() == null) {
throw LOGGER.atError()
.log(new IllegalArgumentException(
"Missing required property propertyRemovedInStable in model CustomTemplateResourceProperties"));
}
}

private static final ClientLogger LOGGER = new ClientLogger(CustomTemplateResourceProperties.class);
}
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public OperationsClient getOperations() {
this.defaultPollInterval = defaultPollInterval;
this.endpoint = endpoint;
this.subscriptionId = subscriptionId;
this.apiVersion = "2023-12-01-preview";
this.apiVersion = "2023-11-01";
this.childResourcesInterfaces = new ChildResourcesInterfacesClientImpl(this);
this.topLevelArmResourceInterfaces = new TopLevelArmResourceInterfacesClientImpl(this);
this.customTemplateResourceInterfaces = new CustomTemplateResourceInterfacesClientImpl(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,6 @@ public ProvisioningState provisioningState() {
return this.innerModel().provisioningState();
}

public String propertyRemovedInStable() {
return this.innerModel().propertyRemovedInStable();
}

public Region region() {
return Region.fromName(this.regionName());
}
Expand Down Expand Up @@ -174,16 +170,6 @@ public CustomTemplateResourceImpl withIdentity(ManagedIdentityProperties identit
}
}

public CustomTemplateResourceImpl withPropertyRemovedInStable(String propertyRemovedInStable) {
if (isInCreateMode()) {
this.innerModel().withPropertyRemovedInStable(propertyRemovedInStable);
return this;
} else {
this.updateProperties.withPropertyRemovedInStable(propertyRemovedInStable);
return this;
}
}

public CustomTemplateResourceImpl withIfMatch(String ifMatch) {
this.createIfMatch = ifMatch;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,6 @@ public interface CustomTemplateResource {
*/
ProvisioningState provisioningState();

/**
* Gets the propertyRemovedInStable property: The propertyRemovedInStable property.
*
* @return the propertyRemovedInStable value.
*/
String propertyRemovedInStable();

/**
* Gets the region of the resource.
*
Expand Down Expand Up @@ -161,8 +154,7 @@ interface WithResourceGroup {
* resource to be created, but also allows for any other optional properties to be specified.
*/
interface WithCreate extends DefinitionStages.WithTags, DefinitionStages.WithIdentity,
DefinitionStages.WithPropertyRemovedInStable, DefinitionStages.WithIfMatch,
DefinitionStages.WithIfNoneMatch {
DefinitionStages.WithIfMatch, DefinitionStages.WithIfNoneMatch {
/**
* Executes the create request.
*
Expand Down Expand Up @@ -205,19 +197,6 @@ interface WithIdentity {
WithCreate withIdentity(ManagedIdentityProperties identity);
}

/**
* The stage of the CustomTemplateResource definition allowing to specify propertyRemovedInStable.
*/
interface WithPropertyRemovedInStable {
/**
* Specifies the propertyRemovedInStable property: The propertyRemovedInStable property..
*
* @param propertyRemovedInStable The propertyRemovedInStable property.
* @return the next definition stage.
*/
WithCreate withPropertyRemovedInStable(String propertyRemovedInStable);
}

/**
* The stage of the CustomTemplateResource definition allowing to specify ifMatch.
*/
Expand Down Expand Up @@ -255,7 +234,7 @@ interface WithIfNoneMatch {
/**
* The template for CustomTemplateResource update.
*/
interface Update extends UpdateStages.WithIdentity, UpdateStages.WithPropertyRemovedInStable {
interface Update extends UpdateStages.WithIdentity {
/**
* Executes the update request.
*
Expand Down Expand Up @@ -288,18 +267,5 @@ interface WithIdentity {
*/
Update withIdentity(ManagedIdentityProperties identity);
}

/**
* The stage of the CustomTemplateResource update allowing to specify propertyRemovedInStable.
*/
interface WithPropertyRemovedInStable {
/**
* Specifies the propertyRemovedInStable property: The propertyRemovedInStable property..
*
* @param propertyRemovedInStable The propertyRemovedInStable property.
* @return the next definition stage.
*/
Update withPropertyRemovedInStable(String propertyRemovedInStable);
}
}
}
Loading

0 comments on commit 7103f43

Please sign in to comment.