Skip to content

Commit

Permalink
refine the wording
Browse files Browse the repository at this point in the history
  • Loading branch information
tadelesh committed Dec 13, 2024
1 parent fb322c4 commit d325525
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 32 deletions.
6 changes: 3 additions & 3 deletions packages/typespec-client-generator-core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -446,11 +446,11 @@ model Bar {}
#### `@isApiVersion`

Use to override default assumptions on whether a parameter is an api-version parameter or not.
By default, we do matches with the `api-version` string in the parameter name. Since api versions are
a client parameter, we will also elevate this parameter up onto the client
By default, we do matches with the `api-version` or `apiversion` string in the parameter name. Since api versions are
a client parameter, we will also elevate this parameter up onto the client.

```typespec
@Azure.ClientGenerator.Core.isApiVersion(value: valueof boolean, scope?: valueof string)
@Azure.ClientGenerator.Core.isApiVersion(value?: valueof boolean, scope?: valueof string)
```

##### Target
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -535,8 +535,8 @@ export type ClientNamespaceDecorator = (

/**
* Use to override default assumptions on whether a parameter is an api-version parameter or not.
* By default, we do matches with the `api-version` string in the parameter name. Since api versions are
* a client parameter, we will also elevate this parameter up onto the client
* By default, we do matches with the `api-version` or `apiversion` string in the parameter name. Since api versions are
* a client parameter, we will also elevate this parameter up onto the client.
*
* @example
* ```typespec
Expand Down
4 changes: 2 additions & 2 deletions packages/typespec-client-generator-core/lib/decorators.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -516,8 +516,8 @@ extern dec clientNamespace(

/**
* Use to override default assumptions on whether a parameter is an api-version parameter or not.
* By default, we do matches with the `api-version` string in the parameter name. Since api versions are
* a client parameter, we will also elevate this parameter up onto the client
* By default, we do matches with the `api-version` or `apiversion` string in the parameter name. Since api versions are
* a client parameter, we will also elevate this parameter up onto the client.
*
* @example
* ```typespec
Expand Down
20 changes: 5 additions & 15 deletions packages/typespec-client-generator-core/src/decorators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1014,13 +1014,13 @@ export function getClientInitialization(

const paramAliasKey = createStateSymbol("paramAlias");

export const paramAliasDecorator: ParamAliasDecorator = (
export const $paramAlias: ParamAliasDecorator = (
context: DecoratorContext,
original: ModelProperty,
paramAlias: string,
scope?: LanguageScopes,
) => {
setScopedDecoratorData(context, paramAliasDecorator, paramAliasKey, original, paramAlias, scope);
setScopedDecoratorData(context, $paramAlias, paramAliasKey, original, paramAlias, scope);
};

export function getParamAlias(context: TCGCContext, original: ModelProperty): string | undefined {
Expand All @@ -1029,26 +1029,16 @@ export function getParamAlias(context: TCGCContext, original: ModelProperty): st

const isApiVersionKey = createStateSymbol("isApiVersion");

export const isApiVersionDecorator: IsApiVersionDecorator = (
export const $isApiVersion: IsApiVersionDecorator = (
context: DecoratorContext,
param: ModelProperty,
value?: boolean,
scope?: LanguageScopes,
) => {
setScopedDecoratorData(
context,
isApiVersionDecorator,
isApiVersionKey,
param,
value ?? true,
scope,
);
setScopedDecoratorData(context, $isApiVersion, isApiVersionKey, param, value ?? true, scope);
};

export function getIsApiVersionDecorator(
context: TCGCContext,
param: ModelProperty,
): boolean | undefined {
export function getIsApiVersion(context: TCGCContext, param: ModelProperty): boolean | undefined {
return getScopedDecoratorData(context, isApiVersionKey, param);
}

Expand Down
4 changes: 2 additions & 2 deletions packages/typespec-client-generator-core/src/public-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { pascalCase } from "change-case";
import pluralize from "pluralize";
import {
getClientNameOverride,
getIsApiVersionDecorator,
getIsApiVersion,
listClients,
listOperationGroups,
listOperationsInOperationGroup,
Expand Down Expand Up @@ -80,7 +80,7 @@ function isModelProperty(type: any): type is ModelProperty {
*/
export function isApiVersion(context: TCGCContext, type: { name: string }): boolean {
if (isModelProperty(type)) {
const override = getIsApiVersionDecorator(context, type);
const override = getIsApiVersion(context, type);
if (override !== undefined) {
return override;
}
Expand Down
8 changes: 4 additions & 4 deletions packages/typespec-client-generator-core/src/tsp-index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import {
$clientNamespace,
$convenientAPI,
$flattenProperty,
$isApiVersion,
$operationGroup,
$override,
$paramAlias,
$protocolAPI,
$usage,
$useSystemTextJsonConverter,
isApiVersionDecorator,
paramAliasDecorator,
} from "./decorators.js";

export { $lib } from "./lib.js";
Expand All @@ -33,8 +33,8 @@ export const $decorators = {
override: $override,
useSystemTextJsonConverter: $useSystemTextJsonConverter,
clientInitialization: $clientInitialization,
paramAlias: paramAliasDecorator,
isApiVersion: isApiVersionDecorator,
paramAlias: $paramAlias,
isApiVersion: $isApiVersion,
clientNamespace: $clientNamespace,
} as AzureClientGeneratorCoreDecorators,
};
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ describe("@isApiVersion", () => {
ok(apiVersionParam);
strictEqual(apiVersionParam.isApiVersionParam, true);
});
it("overidden api version param defaults to latest api version", async () => {

it("override api version param defaults to latest api version", async () => {
await runner.compile(`
@service({
title: "Contoso Widget Manager",
Expand Down Expand Up @@ -70,6 +71,7 @@ describe("@isApiVersion", () => {
strictEqual(apiVersionOpParam.isApiVersionParam, true);
strictEqual(apiVersionOpParam.correspondingMethodParams[0], apiVersionClientParam);
});

it("override parameter to not be api version", async () => {
await runner.compile(`
@service({})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,11 +368,11 @@ model Bar {}
### `@isApiVersion` {#@Azure.ClientGenerator.Core.isApiVersion}

Use to override default assumptions on whether a parameter is an api-version parameter or not.
By default, we do matches with the `api-version` string in the parameter name. Since api versions are
a client parameter, we will also elevate this parameter up onto the client
By default, we do matches with the `api-version` or `apiversion` string in the parameter name. Since api versions are
a client parameter, we will also elevate this parameter up onto the client.

```typespec
@Azure.ClientGenerator.Core.isApiVersion(value: valueof boolean, scope?: valueof string)
@Azure.ClientGenerator.Core.isApiVersion(value?: valueof boolean, scope?: valueof string)
```

#### Target
Expand Down

0 comments on commit d325525

Please sign in to comment.