Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
pshao25 committed Dec 19, 2023
1 parent b25ad60 commit fe8e180
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public static void WriteRequestCreation(CodeWriter writer, RestClientMethod clie
writer.Line($"var {uri:D} = new {Configuration.ApiTypes.RequestUriType}();");
foreach (var segment in clientMethod.Request.PathSegments)
{
var value = GetFieldReference(fields, segment.Value);
var value = segment.IsMethodParameter ? segment.Value : GetFieldReference(fields, segment.Value);
if (value.Type.IsFrameworkType && value.Type.FrameworkType == typeof(Uri))
{
writer.Append($"{uri}.Reset(");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@ namespace AutoRest.CSharp.Output.Models.Requests
{
internal class PathSegment
{
public PathSegment(ReferenceOrConstant value, bool escape, SerializationFormat format, bool isRaw = false)
public PathSegment(ReferenceOrConstant value, bool escape, SerializationFormat format, bool isRaw = false, bool isMethodParameter = false)
{
Value = value;
Escape = escape;
Format = format;
IsRaw = isRaw;
IsMethodParameter = isMethodParameter;
}

public ReferenceOrConstant Value { get; }
public bool Escape { get; }
public SerializationFormat Format { get; }
public bool IsRaw { get; }
public bool IsMethodParameter { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ private static Request BuildRequest(InputOperation operation, IReadOnlyCollectio
uriParametersMap.Add(parameterName, new PathSegment(reference, escape, serializationFormat, isRaw: true));
break;
case RequestLocation.Path:
pathParametersMap.Add(parameterName, new PathSegment(reference, escape, serializationFormat, isRaw: false));
pathParametersMap.Add(parameterName, new PathSegment(reference, escape, serializationFormat, isRaw: false, isMethodParameter: operationParameter.Kind == InputOperationParameterKind.Method));
break;
case RequestLocation.Query:
queryParameters.Add(new QueryParameter(parameterName, reference, operationParameter.ArraySerializationDelimiter, escape, serializationFormat, operationParameter.Explode, operationParameter.IsApiVersion));
Expand Down
62 changes: 29 additions & 33 deletions src/TypeSpec.Extension/Emitter.Csharp/src/lib/clientModelBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,41 +188,37 @@ export function createModelForService(
const apiVersionIndex = op.Parameters.findIndex(
(value: InputParameter) => value.IsApiVersion
);
if (apiVersionIndex !== -1) {
if (apiVersionParam === undefined) {
$lib.reportDiagnostic(program, {
code: "No-APIVersion",
format: { service: service.type.name },
target: NoTarget
});
break;
} else {
const apiVersionInOperation =
op.Parameters[apiVersionIndex];
if (!apiVersionInOperation.DefaultValue?.Value) {
apiVersionInOperation.DefaultValue =
apiVersionParam.DefaultValue;
}
/**
* replace to the global apiVersion parameter if the apiVersion defined in the operation is the same as the global service apiVersion parameter.
* Three checkpoints:
* the parameter is query parameter,
* it is client parameter
* it does not has default value, or the default value is included in the global service apiVersion.
*/
if (
apiVersions.has(
apiVersionInOperation.DefaultValue?.Value
) &&
apiVersionInOperation.Kind ===
InputOperationParameterKind.Client &&
apiVersionInOperation.Location ===
apiVersionParam.Location
) {
op.Parameters[apiVersionIndex] = apiVersionParam;
}
if (apiVersionIndex === -1) {
continue;
}
const apiVersionInOperation = op.Parameters[apiVersionIndex];
if (apiVersionParam !== undefined) {
if (!apiVersionInOperation.DefaultValue?.Value) {
apiVersionInOperation.DefaultValue =
apiVersionParam.DefaultValue;
}
/**
* replace to the global apiVersion parameter if the apiVersion defined in the operation is the same as the global service apiVersion parameter.
* Three checkpoints:
* the parameter is query parameter,
* it is client parameter
* it does not has default value, or the default value is included in the global service apiVersion.
*/
if (
apiVersions.has(
apiVersionInOperation.DefaultValue?.Value
) &&
apiVersionInOperation.Kind ===
InputOperationParameterKind.Client &&
apiVersionInOperation.Location === apiVersionParam.Location
) {
op.Parameters[apiVersionIndex] = apiVersionParam;
continue;
}
}

apiVersionInOperation.Kind = InputOperationParameterKind.Method;
apiVersionInOperation.IsApiVersion = false;
}
}

Expand Down

0 comments on commit fe8e180

Please sign in to comment.