Skip to content

Commit

Permalink
feat(http-client-csharp): adopt TCGC getAllOperations (#3867)
Browse files Browse the repository at this point in the history
- update emitter logic to derive operation definitions from TCGC instead
of raw compiler output
- temporarily work around the mis-use of `InputParameter.DefaultValue`
for constant values
- add conversion from `InputLiteralType.Value` to
`InputParameter.DefaultValue` in converter
- add implicit conversion operation from `InputLiteralType` to
`InputConstant`
- update unit test cases
- minor error message improvement

part of Azure/autorest.csharp#3994

---------

Co-authored-by: Mingzhe Huang (from Dev Box) <[email protected]>
  • Loading branch information
archerzz and Mingzhe Huang (from Dev Box) committed Jul 31, 2024
1 parent 12a8ddb commit 72d544c
Show file tree
Hide file tree
Showing 19 changed files with 1,110 additions and 1,535 deletions.
361 changes: 145 additions & 216 deletions packages/http-client-csharp/emitter/src/lib/client-model-builder.ts

Large diffs are not rendered by default.

12 changes: 9 additions & 3 deletions packages/http-client-csharp/emitter/src/lib/converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export function fromSdkType(
} as InputNullableType;
}
if (sdkType.kind === "model") return fromSdkModelType(sdkType, context, models, enums);
if (sdkType.kind === "endpoint") return fromSdkEndpointType();
if (sdkType.kind === "enum") return fromSdkEnumType(sdkType, context, enums);
if (sdkType.kind === "enumvalue")
return fromSdkEnumValueTypeToConstantType(sdkType, context, enums, literalTypeContext);
Expand All @@ -64,10 +65,9 @@ export function fromSdkType(
return fromSdkDateTimeType(sdkType);
if (sdkType.kind === "duration") return fromSdkDurationType(sdkType as SdkDurationType);
if (sdkType.kind === "tuple") return fromTupleType();
// TODO -- only in operations we could have these types, considering we did not adopt getAllOperations from TCGC yet, this should be fine.
// we need to resolve these conversions when we adopt getAllOperations
// TODO -- endpoint and credential are handled separately in emitter, since we have specific locations for them in input model.
// We can handle unify the way we handle them in the future, probably by chaning the input model schema and do the conversion in generator.
if (sdkType.kind === "credential") throw new Error("Credential type is not supported yet.");
if (sdkType.kind === "endpoint") throw new Error("Endpoint type is not supported yet.");

return fromSdkBuiltInType(sdkType);
}
Expand Down Expand Up @@ -368,3 +368,9 @@ function fromSdkArrayType(
CrossLanguageDefinitionId: arrayType.crossLanguageDefinitionId,
};
}

function fromSdkEndpointType(): InputPrimitiveType {
return {
Kind: "string",
};
}
Loading

0 comments on commit 72d544c

Please sign in to comment.