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
10 changes: 6 additions & 4 deletions packages/rlc-common/src/helpers/nameUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ export function normalizeName(
nameType: NameType,
shouldGuard?: boolean,
customReservedNames?: ReservedName[],
casingOverride?: CasingConvention
casingOverride?: CasingConvention,
oriName?: string
): string;
export function normalizeName(
name: string,
Expand All @@ -169,7 +170,8 @@ export function normalizeName(
nameType: NameType,
optionsOrShouldGuard?: NormalizeNameOption | boolean,
optionalCustomReservedNames?: ReservedName[],
optionalCasingOverride?: CasingConvention
optionalCasingOverride?: CasingConvention,
oriName?: string
): string {
let shouldGuard: boolean | undefined,
customReservedNames: ReservedName[],
Expand All @@ -185,8 +187,8 @@ export function normalizeName(
casingOverride = optionsOrShouldGuard?.casingOverride;
numberPrefixOverride = optionsOrShouldGuard?.numberPrefixOverride;
}
if (name.startsWith("$DO_NOT_NORMALIZE$")) {
return name.replace("$DO_NOT_NORMALIZE$", "");
if ((oriName ?? name).startsWith("$DO_NOT_NORMALIZE$")) {
return (oriName ?? name).replace("$DO_NOT_NORMALIZE$", "");
}
const casingConvention = casingOverride ?? getCasingConvention(nameType);
const parts = deconstruct(name);
Expand Down
28 changes: 25 additions & 3 deletions packages/typespec-ts/src/utils/operationUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,14 @@ export type ServiceOperation = SdkServiceMethod<SdkHttpOperation> & {
oriName?: string;
};

export type ServiceParameter = (
| SdkMethodParameter
| SdkHttpParameter
| SdkBodyParameter
) & {
oriName?: string;
};

export function getMethodHierarchiesMap(
context: SdkContext,
client: SdkClientType<SdkServiceOperation>
Expand Down Expand Up @@ -804,9 +812,23 @@ export function isTenantLevelOperation(

function resolveParameterNameConflict(
operationOrGroup: SdkServiceMethod<SdkHttpOperation>,
p: SdkMethodParameter | SdkHttpParameter | SdkBodyParameter
): SdkMethodParameter | SdkHttpParameter | SdkBodyParameter {
const paramName = normalizeName(p.name, NameType.Parameter, true);
p: ServiceParameter
): ServiceParameter {
// When the name starts with $DO_NOT_NORMALIZE$, record the original name so that
// subsequent calls (e.g. emitNonModelResponseTypes then buildApiOptions both call
// getMethodHierarchiesMap on the same TCGC object) always normalize from the
// original, not from the already-mutated value.
const paramName = normalizeName(
p.name,
NameType.Parameter,
true,
undefined,
undefined,
p.oriName
);
if (!p.oriName) {
p.oriName = p.name;
}
if (paramName === operationOrGroup.name) {
p.name = `${paramName}Parameter`;
Comment thread
kazrael2119 marked this conversation as resolved.
Comment thread
kazrael2119 marked this conversation as resolved.
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# Should keep optional query param name when $DO_NOT_NORMALIZE$ is applied to a reserved keyword

## Typespec

```tsp
import "@typespec/http";
import "@azure-tools/typespec-client-generator-core";

using TypeSpec.Http;
using Azure.ClientGenerator.Core;

@service
namespace Test;

interface Test {
@route("/test")
op patch(@query("type") type?: string): void;
}

@@clientName(Test.patch::parameters.type, "$DO_NOT_NORMALIZE$type");
```

This is the tspconfig.yaml.

```yaml
withRawContent: true
mustEmptyDiagnostic: false
experimental-extensible-enums: true
```

## Operations Options

```ts models:withOptions interface PatchOptionalParams
export interface PatchOptionalParams extends OperationOptions {
type?: string;
}
```

# Should keep optional header param name when $DO_NOT_NORMALIZE$ is applied to a reserved keyword

## Typespec

```tsp
import "@typespec/http";
import "@azure-tools/typespec-client-generator-core";

using TypeSpec.Http;
using Azure.ClientGenerator.Core;

@service
namespace Test;

interface Test {
@route("/test")
op patch(@header("type") type?: string): void;
}

@@clientName(Test.patch::parameters.type, "$DO_NOT_NORMALIZE$type");
```

This is the tspconfig.yaml.

```yaml
withRawContent: true
mustEmptyDiagnostic: false
experimental-extensible-enums: true
```

## Operations Options

```ts models:withOptions interface PatchOptionalParams
export interface PatchOptionalParams extends OperationOptions {
type?: string;
}
```

# Should keep optional body param name when $DO_NOT_NORMALIZE$ is applied to a reserved keyword

## Typespec

```tsp
import "@typespec/http";
import "@azure-tools/typespec-client-generator-core";

using TypeSpec.Http;
using Azure.ClientGenerator.Core;

@service
namespace Test;

interface Test {
@route("/test")
op patch(@body type?: string): void;
}

@@clientName(Test.patch::parameters.type, "$DO_NOT_NORMALIZE$type");
```

This is the tspconfig.yaml.

```yaml
withRawContent: true
mustEmptyDiagnostic: false
experimental-extensible-enums: true
```

## Operations Options

```ts models:withOptions interface PatchOptionalParams
export interface PatchOptionalParams extends OperationOptions {
type?: string;
}
```
Loading