Skip to content

Support optional path parameter for Modular #3152

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 36 commits into from
Apr 28, 2025
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
0e4ed89
update package to next
v-jiaodi Apr 3, 2025
f1aaee0
Merge branch 'main' of https://github.com/Azure/autorest.typescript i…
v-jiaodi Apr 7, 2025
3911246
Merge branch 'main' into monitor-nightly43
v-jiaodi Apr 10, 2025
7c0e9b8
Merge branch 'main' of https://github.com/Azure/autorest.typescript i…
v-jiaodi Apr 14, 2025
6fc79bf
regen
v-jiaodi Apr 14, 2025
d827904
Merge branch 'main' of https://github.com/Azure/autorest.typescript i…
v-jiaodi Apr 14, 2025
45750c1
Merge branch 'main' into monitor-nightly43
MaryGao Apr 15, 2025
199949a
Merge branch 'main' into monitor-nightly43
MaryGao Apr 21, 2025
8b593ec
update
v-jiaodi Apr 21, 2025
11dd719
revert
v-jiaodi Apr 21, 2025
5410a17
regen smoke
v-jiaodi Apr 21, 2025
c44ea2e
Fix the empty client issue
MaryGao Apr 22, 2025
edcabfc
skip case
v-jiaodi Apr 22, 2025
1d68200
Merge branch 'monitor-nightly43' of https://github.com/v-jiaodi/autor…
v-jiaodi Apr 22, 2025
193aa74
regen code
v-jiaodi Apr 22, 2025
0d97ec9
update
v-jiaodi Apr 23, 2025
acce792
update case
v-jiaodi Apr 23, 2025
c360fb0
Merge branch 'main' into monitor-nightly43
MaryGao Apr 27, 2025
2bf1c3c
update package version
v-jiaodi Apr 27, 2025
fe278ea
use latest dev for tcgc
v-jiaodi Apr 27, 2025
8e13496
update package version
v-jiaodi Apr 27, 2025
648771b
Merge branch 'main' into monitor-nightly43
v-jiaodi Apr 27, 2025
b952833
Upgrade to dev 3 version for tcgc to support optional path parameter
MaryGao Apr 27, 2025
fc7b4c8
Add test cases for optional path and remove useless codes
MaryGao Apr 27, 2025
398e84a
Format codes
MaryGao Apr 27, 2025
b2189b4
add test case for path
v-jiaodi Apr 27, 2025
9e0c260
format
v-jiaodi Apr 27, 2025
f34479a
update
v-jiaodi Apr 27, 2025
b74e6b6
Update packages/typespec-ts/test/azureModularIntegration/pathParamete…
MaryGao Apr 27, 2025
e8b9903
Update packages/typespec-ts/test/azureModularIntegration/pathParamete…
MaryGao Apr 27, 2025
c9a4eff
add ut
v-jiaodi Apr 27, 2025
9d072f0
Merge branch 'monitor-nightly43' of https://github.com/v-jiaodi/autor…
v-jiaodi Apr 27, 2025
50013b4
update case
v-jiaodi Apr 28, 2025
e26c82d
Remove the case
MaryGao Apr 28, 2025
0f7d5a1
Remove useless parameter
MaryGao Apr 28, 2025
602b213
fix ci
v-jiaodi Apr 28, 2025
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
774 changes: 473 additions & 301 deletions common/config/rush/pnpm-lock.yaml

Large diffs are not rendered by default.

24 changes: 12 additions & 12 deletions packages/typespec-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
"type": "module",
"dependencies": {
"@azure-tools/typespec-ts": "workspace:^0.38.6",
"@typespec/openapi": "^1.0.0-0",
"@azure-tools/typespec-autorest": ">=0.54.0 <1.0.0",
"@typespec/openapi3": "^1.0.0-0",
"@azure-tools/typespec-azure-core": ">=0.54.0 <1.0.0",
"@azure-tools/typespec-client-generator-core": ">=0.54.0 <1.0.0",
"@azure-tools/typespec-azure-resource-manager": ">=0.54.0 <1.0.0",
"@azure-tools/typespec-azure-rulesets": ">=0.54.0 <1.0.0",
"@typespec/compiler": "^1.0.0-0",
"@typespec/http": "^1.0.0-0",
"@typespec/rest": ">=0.68.0 <1.0.0",
"@typespec/versioning": ">=0.68.0 <1.0.0",
"@typespec/json-schema": "^1.0.0-0",
"@typespec/openapi": "^1.0.0-1",
"@azure-tools/typespec-autorest": ">=0.55.0 <1.0.0",
"@typespec/openapi3": "^1.0.0-1",
"@azure-tools/typespec-azure-core": ">=0.55.0 <1.0.0",
"@azure-tools/typespec-client-generator-core": "0.56.0-dev.3",
"@azure-tools/typespec-azure-resource-manager": ">=0.55.0 <1.0.0",
"@azure-tools/typespec-azure-rulesets": ">=0.55.0 <1.0.0",
"@typespec/compiler": "^1.0.0-1",
"@typespec/http": "^1.0.0-1",
"@typespec/rest": ">=0.69.0 <1.0.0",
"@typespec/versioning": ">=0.69.0 <1.0.0",
"@typespec/json-schema": "^1.0.0-1",
"prettier": "^3.1.0"
},
"devDependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,7 @@
},
"Azure.Core.Foundations.InnerError": {
"type": "object",
"description": "An object containing more specific information about the error. As per Microsoft One API guidelines - https://github.com/Microsoft/api-guidelines/blob/vNext/Guidelines.md#7102-error-condition-responses.",
"description": "An object containing more specific information about the error. As per Microsoft One API guidelines - https://github.com/microsoft/api-guidelines/blob/vNext/azure/Guidelines.md#handling-errors.",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jiaodi could you help investigate why this appears?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"properties": {
"code": {
"type": "string",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@
},
"Azure.Core.Foundations.InnerError": {
"type": "object",
"description": "An object containing more specific information about the error. As per Microsoft One API guidelines - https://github.com/Microsoft/api-guidelines/blob/vNext/Guidelines.md#7102-error-condition-responses.",
"description": "An object containing more specific information about the error. As per Microsoft One API guidelines - https://github.com/microsoft/api-guidelines/blob/vNext/azure/Guidelines.md#handling-errors.",
"properties": {
"code": {
"type": "string",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@
},
"Azure.Core.Foundations.InnerError": {
"type": "object",
"description": "An object containing more specific information about the error. As per Microsoft One API guidelines - https://github.com/Microsoft/api-guidelines/blob/vNext/Guidelines.md#7102-error-condition-responses.",
"description": "An object containing more specific information about the error. As per Microsoft One API guidelines - https://github.com/microsoft/api-guidelines/blob/vNext/azure/Guidelines.md#handling-errors.",
"properties": {
"code": {
"type": "string",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@
},
"Azure.Core.Foundations.InnerError": {
"type": "object",
"description": "An object containing more specific information about the error. As per Microsoft One API guidelines - https://github.com/Microsoft/api-guidelines/blob/vNext/Guidelines.md#7102-error-condition-responses.",
"description": "An object containing more specific information about the error. As per Microsoft One API guidelines - https://github.com/microsoft/api-guidelines/blob/vNext/azure/Guidelines.md#handling-errors.",
"properties": {
"code": {
"type": "string",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@
},
"Azure.Core.Foundations.InnerError": {
"type": "object",
"description": "An object containing more specific information about the error. As per Microsoft One API guidelines - https://github.com/Microsoft/api-guidelines/blob/vNext/Guidelines.md#7102-error-condition-responses.",
"description": "An object containing more specific information about the error. As per Microsoft One API guidelines - https://github.com/microsoft/api-guidelines/blob/vNext/azure/Guidelines.md#handling-errors.",
"properties": {
"code": {
"type": "string",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@
},
"Azure.Core.Foundations.InnerError": {
"type": "object",
"description": "An object containing more specific information about the error. As per Microsoft One API guidelines - https://github.com/Microsoft/api-guidelines/blob/vNext/Guidelines.md#7102-error-condition-responses.",
"description": "An object containing more specific information about the error. As per Microsoft One API guidelines - https://github.com/microsoft/api-guidelines/blob/vNext/azure/Guidelines.md#handling-errors.",
"properties": {
"code": {
"type": "string",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@
},
"Azure.Core.Foundations.InnerError": {
"type": "object",
"description": "An object containing more specific information about the error. As per Microsoft One API guidelines - https://github.com/Microsoft/api-guidelines/blob/vNext/Guidelines.md#7102-error-condition-responses.",
"description": "An object containing more specific information about the error. As per Microsoft One API guidelines - https://github.com/microsoft/api-guidelines/blob/vNext/azure/Guidelines.md#handling-errors.",
"properties": {
"code": {
"type": "string",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@
},
"Azure.Core.Foundations.InnerError": {
"type": "object",
"description": "An object containing more specific information about the error. As per Microsoft One API guidelines - https://github.com/Microsoft/api-guidelines/blob/vNext/Guidelines.md#7102-error-condition-responses.",
"description": "An object containing more specific information about the error. As per Microsoft One API guidelines - https://github.com/microsoft/api-guidelines/blob/vNext/azure/Guidelines.md#handling-errors.",
"properties": {
"code": {
"type": "string",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@
},
"Azure.Core.Foundations.InnerError": {
"type": "object",
"description": "An object containing more specific information about the error. As per Microsoft One API guidelines - https://github.com/Microsoft/api-guidelines/blob/vNext/Guidelines.md#7102-error-condition-responses.",
"description": "An object containing more specific information about the error. As per Microsoft One API guidelines - https://github.com/microsoft/api-guidelines/blob/vNext/azure/Guidelines.md#handling-errors.",
"properties": {
"code": {
"type": "string",
Expand Down
38 changes: 19 additions & 19 deletions packages/typespec-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@
"license": "MIT",
"devDependencies": {
"@azure-rest/core-client": "^2.3.1",
"@typespec/http-specs": "0.1.0-alpha.17",
"@typespec/spector": "0.1.0-alpha.11",
"@typespec/spec-api": "0.1.0-alpha.3",
"@azure-tools/azure-http-specs": "0.1.0-alpha.13",
"@azure-tools/typespec-autorest": ">=0.54.0 <1.0.0",
"@azure-tools/typespec-azure-core": ">=0.54.0 <1.0.0",
"@azure-tools/typespec-azure-resource-manager": ">=0.54.0 <1.0.0",
"@azure-tools/typespec-client-generator-core": ">=0.54.0 <1.0.0",
"@typespec/http-specs": "0.1.0-alpha.20",
"@typespec/spector": "0.1.0-alpha.12",
"@typespec/spec-api": "0.1.0-alpha.4",
"@azure-tools/azure-http-specs": "0.1.0-alpha.15",
"@azure-tools/typespec-autorest": ">=0.55.0 <1.0.0",
"@azure-tools/typespec-azure-core": ">=0.55.0 <1.0.0",
"@azure-tools/typespec-azure-resource-manager": ">=0.55.0 <1.0.0",
"@azure-tools/typespec-client-generator-core": "0.56.0-dev.3",
"@azure/abort-controller": "^2.1.2",
"@azure/core-auth": "^1.6.0",
"@azure/core-lro": "^3.1.0",
Expand All @@ -86,12 +86,12 @@
"@types/node": "^18.0.0",
"@typescript-eslint/eslint-plugin": "^8.28.0",
"@typescript-eslint/parser": "^8.28.0",
"@typespec/compiler": "^1.0.0-0",
"@typespec/http": "^1.0.0-0",
"@typespec/openapi": "^1.0.0-0",
"@typespec/rest": ">=0.68.0 <1.0.0",
"@typespec/compiler": "^1.0.0-1",
"@typespec/http": "^1.0.0-1",
"@typespec/openapi": "^1.0.0-1",
"@typespec/rest": ">=0.69.0 <1.0.0",
"@typespec/ts-http-runtime": "0.1.0",
"@typespec/versioning": ">=0.68.0 <1.0.0",
"@typespec/versioning": ">=0.69.0 <1.0.0",
"chai": "^4.3.6",
"chalk": "^4.0.0",
"cross-env": "^7.0.3",
Expand All @@ -113,12 +113,12 @@
"js-yaml": "^4.1.0"
},
"peerDependencies": {
"@azure-tools/typespec-azure-core": ">=0.54.0 <1.0.0",
"@azure-tools/typespec-client-generator-core": ">=0.54.0 <1.0.0",
"@typespec/compiler": "^1.0.0-0",
"@typespec/http": "^1.0.0-0",
"@typespec/rest": ">=0.68.0 <1.0.0",
"@typespec/versioning": ">=0.68.0 <1.0.0"
"@azure-tools/typespec-azure-core": ">=0.55.0 <1.0.0",
"@azure-tools/typespec-client-generator-core": "0.56.0-dev.3",
"@typespec/compiler": "^1.0.0-1",
"@typespec/http": "^1.0.0-1",
"@typespec/rest": ">=0.69.0 <1.0.0",
"@typespec/versioning": ">=0.69.0 <1.0.0"
},
"dependencies": {
"@azure-tools/rlc-common": "workspace:^0.38.6",
Expand Down
6 changes: 0 additions & 6 deletions packages/typespec-ts/src/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -426,12 +426,6 @@ const libDef = {
default: paramMessage`Property name ${"propertyName"} is normalized to ${"normalizedName"}.`
}
},
"optional-path-param": {
severity: "error",
messages: {
default: paramMessage`Path parameter '${"paramName"}' cannot be optional.`
}
},
"un-supported-format-cases": {
severity: "warning",
messages: {
Expand Down
13 changes: 1 addition & 12 deletions packages/typespec-ts/src/modular/helpers/operationHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ import {
SdkModelPropertyType,
SdkModelType,
SdkPagingServiceMethod,
SdkPathParameter,
SdkServiceParameter,
SdkType
} from "@azure-tools/typespec-client-generator-core";
Expand Down Expand Up @@ -1006,7 +1005,7 @@ function getDefaultValue(param: SdkServiceParameter) {
* Extracts the path parameters
*/
function getPathParameters(
dpgContext: SdkContext,
_dpgContext: SdkContext,
operation: ServiceOperation,
optionalParamName: string = "options"
) {
Expand All @@ -1017,16 +1016,6 @@ function getPathParameters(
const pathParams: string[] = [];
for (const param of operation.operation.parameters) {
if (param.kind === "path") {
// Path parameters cannot be optional
if (param.optional) {
reportDiagnostic(dpgContext.program, {
code: "optional-path-param",
target: NoTarget,
format: {
paramName: (param as SdkPathParameter).name
}
});
}
pathParams.push(
`"${param.serializedName}": ${getPathParamExpr(param, getDefaultValue(param) as string, optionalParamName)}`
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ describe("Azure Core Page Rest Client", () => {
.post({
body: validBody,
queryParameters: {
"api-version": "2022-12-01-preview",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new change?

another: "Second"
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ export declare type AzureCorePageClient = Client & {
};

export declare interface AzureCorePageClientOptions extends ClientOptions {
apiVersion?: string;
}

declare function createClient({ apiVersion, ...options }?: AzureCorePageClientOptions): AzureCorePageClient;
declare function createClient(options?: AzureCorePageClientOptions): AzureCorePageClient;
export default createClient;

export declare interface FirstItemOutput {
Expand Down Expand Up @@ -58,7 +57,15 @@ export declare interface ListFirstItemDefaultResponse extends HttpResponse {
headers: RawHttpHeaders & ListFirstItemDefaultHeaders;
}

export declare type ListFirstItemParameters = RequestParameters;
export declare type ListFirstItemParameters = ListFirstItemQueryParam & RequestParameters;

export declare interface ListFirstItemQueryParam {
queryParameters: ListFirstItemQueryParamProperties;
}

export declare interface ListFirstItemQueryParamProperties {
"api-version": string;
}

export declare interface ListItemInputBody {
inputName: string;
Expand All @@ -85,7 +92,15 @@ export declare interface ListSecondItemDefaultResponse extends HttpResponse {
headers: RawHttpHeaders & ListSecondItemDefaultHeaders;
}

export declare type ListSecondItemParameters = RequestParameters;
export declare type ListSecondItemParameters = ListSecondItemQueryParam & RequestParameters;

export declare interface ListSecondItemQueryParam {
queryParameters: ListSecondItemQueryParamProperties;
}

export declare interface ListSecondItemQueryParamProperties {
"api-version": string;
}

export declare interface ListWithCustomPageModel {
get(options?: ListWithCustomPageModelParameters): StreamableMethod<ListWithCustomPageModel200Response | ListWithCustomPageModelDefaultResponse>;
Expand All @@ -106,7 +121,15 @@ export declare interface ListWithCustomPageModelDefaultResponse extends HttpResp
headers: RawHttpHeaders & ListWithCustomPageModelDefaultHeaders;
}

export declare type ListWithCustomPageModelParameters = RequestParameters;
export declare type ListWithCustomPageModelParameters = ListWithCustomPageModelQueryParam & RequestParameters;

export declare interface ListWithCustomPageModelQueryParam {
queryParameters: ListWithCustomPageModelQueryParamProperties;
}

export declare interface ListWithCustomPageModelQueryParamProperties {
"api-version": string;
}

export declare interface ListWithPage {
get(options?: ListWithPageParameters): StreamableMethod<ListWithPage200Response | ListWithPageDefaultResponse>;
Expand All @@ -127,7 +150,15 @@ export declare interface ListWithPageDefaultResponse extends HttpResponse {
headers: RawHttpHeaders & ListWithPageDefaultHeaders;
}

export declare type ListWithPageParameters = RequestParameters;
export declare type ListWithPageParameters = ListWithPageQueryParam & RequestParameters;

export declare interface ListWithPageQueryParam {
queryParameters: ListWithPageQueryParamProperties;
}

export declare interface ListWithPageQueryParamProperties {
"api-version": string;
}

export declare interface ListWithParameters {
post(options: ListWithParametersParameters): StreamableMethod<ListWithParameters200Response | ListWithParametersDefaultResponse>;
Expand Down Expand Up @@ -155,10 +186,11 @@ export declare interface ListWithParametersDefaultResponse extends HttpResponse
export declare type ListWithParametersParameters = ListWithParametersQueryParam & ListWithParametersBodyParam & RequestParameters;

export declare interface ListWithParametersQueryParam {
queryParameters?: ListWithParametersQueryParamProperties;
queryParameters: ListWithParametersQueryParamProperties;
}

export declare interface ListWithParametersQueryParamProperties {
"api-version": string;
another?: ListItemInputExtensibleEnum;
}

Expand Down Expand Up @@ -197,16 +229,26 @@ export declare type PaginateReturn<TResult> = TResult extends {
body: {
items?: infer TPage;
};
} | {
body: {
values?: infer TPage;
};
} ? GetArrayType<TPage> : Array<unknown>;

export declare interface PagingOptions<TResponse> {
customGetPage?: GetPage<PaginateReturn<TResponse>[]>;
}

export declare interface ParameterizedNextLinkPagingResultOutput {
values: Array<UserOutput>;
nextLink: string;
}

export declare interface Routes {
(path: "/azure/core/page/page"): ListWithPage;
(path: "/azure/core/page/parameters"): ListWithParameters;
(path: "/azure/core/page/custom-page"): ListWithCustomPageModel;
(path: "/azure/core/page/with-parameterized-next-link"): WithParameterizedNextLink;
(path: "/azure/core/page/first-item"): ListFirstItem;
(path: "/azure/core/page/second-item"): ListSecondItem;
}
Expand All @@ -233,4 +275,24 @@ export declare interface UserOutput {
readonly etag: string;
}

export declare interface WithParameterizedNextLink {
get(options: WithParameterizedNextLinkParameters): StreamableMethod<WithParameterizedNextLink200Response>;
}

export declare interface WithParameterizedNextLink200Response extends HttpResponse {
status: "200";
body: ParameterizedNextLinkPagingResultOutput;
}

export declare type WithParameterizedNextLinkParameters = WithParameterizedNextLinkQueryParam & RequestParameters;

export declare interface WithParameterizedNextLinkQueryParam {
queryParameters: WithParameterizedNextLinkQueryParamProperties;
}

export declare interface WithParameterizedNextLinkQueryParamProperties {
includePending?: boolean;
select: string;
}

export { }
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export declare class PageClient {
constructor(options?: PageClientOptionalParams);
listSecondItem(options?: ListSecondItemOptionalParams): PagedAsyncIterableIterator<SecondItem>;
listFirstItem(options?: ListFirstItemOptionalParams): PagedAsyncIterableIterator<FirstItem>;
withParameterizedNextLink(select: string, options?: WithParameterizedNextLinkOptionalParams): PagedAsyncIterableIterator<User>;
listWithCustomPageModel(options?: ListWithCustomPageModelOptionalParams): PagedAsyncIterableIterator<User>;
listWithParameters(bodyInput: ListItemInputBody, options?: ListWithParametersOptionalParams): PagedAsyncIterableIterator<User>;
listWithPage(options?: ListWithPageOptionalParams): PagedAsyncIterableIterator<User>;
Expand Down Expand Up @@ -78,4 +79,8 @@ export declare interface UserOrder {
detail: string;
}

export declare interface WithParameterizedNextLinkOptionalParams extends OperationOptions {
includePending?: boolean;
}

export { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
!/src
/src/**
!/src/index.d.ts
!/.gitignore
!/tspconfig.yaml
Loading