-
Notifications
You must be signed in to change notification settings - Fork 78
Issue found in DPG modular generation - apiVersion parameter missing #3437
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
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
a4b375a
add smoke case for @azure-rest/purview-datamap
v-jiaodi 1dfbb2f
add ut
v-jiaodi fd26c17
add ut
v-jiaodi ca5b535
regen code
v-jiaodi d7a0a3f
regen code
v-jiaodi 3bb09ab
Merge branch 'main' of https://github.com/Azure/autorest.typescript i…
v-jiaodi 4adf2ce
fix
v-jiaodi 2d1f038
regen code
v-jiaodi 839de80
Merge branch 'main' of https://github.com/Azure/autorest.typescript i…
v-jiaodi cbeda3b
regen code
v-jiaodi a44cea1
Merge branch 'main' of https://github.com/Azure/autorest.typescript i…
v-jiaodi 54bb1a5
update typespec
v-jiaodi 1070c64
add ut
v-jiaodi 2fb8185
Merge branch 'main' into test8123
v-jiaodi c7a4025
remove smoke case
v-jiaodi 46211d6
update ut
v-jiaodi 4e6388d
update ut
v-jiaodi 4b9b549
Merge branch 'main' into test8123
v-jiaodi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
...ages/typespec-ts/test/modularUnit/scenarios/clientContext/optionalApiVersion.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| # handle with optional api-version parameter via custom VersionParameterTrait | ||
|
|
||
| ## TypeSpec | ||
|
|
||
| ```tsp | ||
| import "@typespec/http"; | ||
| import "@typespec/rest"; | ||
| import "@typespec/versioning"; | ||
| import "@azure-tools/typespec-azure-core"; | ||
|
|
||
| using TypeSpec.Http; | ||
| using TypeSpec.Rest; | ||
| using TypeSpec.Versioning; | ||
| using Azure.Core; | ||
| using Azure.Core.Traits; | ||
|
|
||
| @service(#{ | ||
| title: "DataMapClient", | ||
| }) | ||
| @versioned(DataMapService.Versions) | ||
| @server( | ||
| "{endpoint}", | ||
| "DataMap Service", | ||
| { | ||
| @doc("Service endpoint") | ||
| endpoint: url, | ||
| } | ||
| ) | ||
| namespace DataMapService; | ||
|
|
||
| enum Versions { | ||
| @doc("API Version 2023-09-01") | ||
| `2023-09-01`, | ||
| } | ||
|
|
||
| @route("/entities") | ||
| @get | ||
| op listEntities( | ||
| @doc("The API version to use for this operation.") | ||
| @query("api-version") | ||
| @minLength(1) | ||
| apiVersion?: string, | ||
| ): { | ||
| @statusCode statusCode: 200; | ||
| @body entities: string[]; | ||
| }; | ||
| ``` | ||
|
|
||
| The config would be like: | ||
|
|
||
| ```yaml | ||
| withRawContent: true | ||
| ignoreWeirdLine: false | ||
| ``` | ||
|
|
||
| ## clientContext | ||
|
|
||
| ```ts clientContext | ||
| import { logger } from "../logger.js"; | ||
| import { KnownVersions } from "../models/models.js"; | ||
| import { Client, ClientOptions, getClient } from "@azure-rest/core-client"; | ||
|
|
||
| export interface DataMapServiceContext extends Client { | ||
| /** The API version to use for this operation. */ | ||
| /** Known values of {@link KnownVersions} that the service accepts. */ | ||
| apiVersion: string; | ||
| } | ||
|
|
||
| /** Optional parameters for the client. */ | ||
| export interface DataMapServiceClientOptionalParams extends ClientOptions { | ||
| /** The API version to use for this operation. */ | ||
| /** Known values of {@link KnownVersions} that the service accepts. */ | ||
| apiVersion?: string; | ||
| } | ||
|
|
||
| export function createDataMapService( | ||
| endpointParam: string, | ||
| options: DataMapServiceClientOptionalParams = {}, | ||
| ): DataMapServiceContext { | ||
| const endpointUrl = options.endpoint ?? String(endpointParam); | ||
| const prefixFromOptions = options?.userAgentOptions?.userAgentPrefix; | ||
| const userAgentPrefix = prefixFromOptions | ||
| ? `${prefixFromOptions} azsdk-js-api` | ||
| : `azsdk-js-api`; | ||
| const { apiVersion: _, ...updatedOptions } = { | ||
| ...options, | ||
| userAgentOptions: { userAgentPrefix }, | ||
| loggingOptions: { logger: options.loggingOptions?.logger ?? logger.info }, | ||
| }; | ||
| const clientContext = getClient(endpointUrl, undefined, updatedOptions); | ||
| clientContext.pipeline.removePolicy({ name: "ApiVersionPolicy" }); | ||
| const apiVersion = options.apiVersion ?? "2023-09-01"; | ||
| clientContext.pipeline.addPolicy({ | ||
| name: "ClientApiVersionPolicy", | ||
| sendRequest: (req, next) => { | ||
| // Use the apiVersion defined in request url directly | ||
| // Append one if there is no apiVersion and we have one at client options | ||
| const url = new URL(req.url); | ||
| if (!url.searchParams.get("api-version")) { | ||
| req.url = `${req.url}${ | ||
| Array.from(url.searchParams.keys()).length > 0 ? "&" : "?" | ||
| }api-version=${apiVersion}`; | ||
| } | ||
|
|
||
| return next(req); | ||
| }, | ||
| }); | ||
| return { ...clientContext, apiVersion } as DataMapServiceContext; | ||
| } | ||
| ``` |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.