Skip to content

Commit

Permalink
Remove extraneous changes
Browse files Browse the repository at this point in the history
  • Loading branch information
markcowl committed Sep 7, 2024
1 parent f4da592 commit 92c2c34
Show file tree
Hide file tree
Showing 5 changed files with 267 additions and 39 deletions.
9 changes: 9 additions & 0 deletions .chronus/changes/async-header-result-2024-7-22-23-19-8.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
# Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking
changeKind: fix
packages:
- "@azure-tools/typespec-azure-core"
- "@azure-tools/typespec-azure-resource-manager"
---

Fix #1180 Return StatusMonitor result field for non-resource PUT operations in getLroMetadata.finalResult
121 changes: 88 additions & 33 deletions packages/typespec-azure-core/src/lro-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ export interface OperationReference {
parameterMap?: Map<string, ParameterSource>;

parameters?: Map<string, PropertyMap>;

/** headers linking to the operation */
link?: OperationLink;
}

/**
Expand Down Expand Up @@ -310,15 +313,18 @@ export function getLroMetadata(program: Program, operation: Operation): LroMetad
if (context === undefined) return undefined;
processFinalReference(program, operation, context);
processFinalLink(program, operation, context);
const nextReference: NextOperationReference | undefined = processStatusMonitorReference(
program,
operation,
context
);
const nextReference:
| NextOperationReference
| (NextOperationLink & { operation: Operation })
| undefined = processStatusMonitorReference(program, operation, context);
if (nextReference !== undefined && nextReference.responseModel.kind === "Model") {
context.statusMonitorStep = nextReference;
processFinalReference(program, nextReference.target.operation, context);
processFinalLink(program, nextReference.target.operation, context);
const linkedOperation =
nextReference.kind === "nextOperationLink"
? nextReference.operation
: nextReference.target.operation;
processFinalReference(program, linkedOperation, context);
processFinalLink(program, linkedOperation, context);
context.pollingStep = getPollingStep(program, nextReference.responseModel, context);
return createLroMetadata(program, operation, context);
}
Expand Down Expand Up @@ -463,8 +469,10 @@ function createOperationLink(program: Program, modelProperty: ModelProperty): Op
};
}

function createOperationReference(metadata: OperationLinkMetadata): OperationReference | undefined {
if (!metadata.parameterMap) return undefined;
function createOperationReferenceOrLink(
metadata: OperationLinkMetadata
): OperationReference | OperationLink | undefined {
if (!metadata.parameterMap && !metadata.link) return undefined;
const map = new Map<string, ParameterSource>();
if (metadata.parameterMap) {
for (const [name, parameters] of metadata.parameterMap) {
Expand All @@ -487,6 +495,13 @@ function createOperationReference(metadata: OperationLinkMetadata): OperationRef
parameters: metadata.parameterMap,
};
}
if (metadata.link) {
return {
kind: "link",
location: metadata.link.location,
property: metadata.link.property,
};
}

return undefined;
}
Expand Down Expand Up @@ -554,9 +569,6 @@ function getLogicalResourceOperation(
case "delete":
resultOp = "delete";
break;
case "put":
resultOp = "createOrReplace";
break;
default:
return undefined;
}
Expand Down Expand Up @@ -602,6 +614,12 @@ function getFinalStateVia(
break;
case "nextOperationReference":
finalState = FinalStateValue.customOperationReference;
if (context.statusMonitorStep.target.link?.location === "ResponseHeader") {
finalState = getLroStatusFromHeaderProperty(
program,
context.statusMonitorStep.target.link.property
);
}
}
} else {
finalState = getStatusFromLinkOrReference(program, operation, context.finalStep.target);
Expand Down Expand Up @@ -700,7 +718,6 @@ function getPollingStep(
PollingOperationKey
);
}
if (context.pollingOperationLink?.parameterMap === undefined) return undefined;
const statusMonitorOverride = context.pollingOperationLink?.result?.statusMonitor;
if (statusMonitorOverride !== undefined && statusMonitorOverride.monitorType !== undefined) {
info = {
Expand Down Expand Up @@ -754,6 +771,8 @@ function getStatusFromLinkOrReference(
finalState = FinalStateValue.customOperationReference;
if (isMatchingGetOperation(program, sourceOperation, target.operation)) {
finalState = FinalStateValue.originalUri;
} else if (target.link !== undefined && target.link.location === "ResponseHeader") {
finalState = getLroStatusFromHeaderProperty(program, target.link.property);
}
}
break;
Expand Down Expand Up @@ -802,6 +821,7 @@ function GetStatusMonitorInfoFromOperation(
program: Program,
operation: HttpOperation
): StatusMonitorInfo | undefined {
if (operation.verb === "get" || operation.verb === "head") return undefined;
const models = filterResponseModels(
operation,
(model) =>
Expand Down Expand Up @@ -971,16 +991,31 @@ function processFinalReference(program: Program, operation: Operation, context:
if (context.finalStep !== undefined) return;
// looks for operation marked with @finalOperation
const link = getOperationLink(program, operation, "final");
if (link === undefined || link.parameterMap === undefined || link.result?.type === undefined)
if (
link === undefined ||
link.result?.type === undefined ||
(link.link === undefined && link.parameterMap === undefined)
)
return;
context.finalOperationLink = link;
const reference = createOperationReference(link);
const reference = createOperationReferenceOrLink(link);
if (reference === undefined) return;
context.finalStep = {
kind: "finalOperationReference",
responseModel: link.result?.type,
target: reference,
};
switch (reference.kind) {
case "reference":
context.finalStep = {
kind: "finalOperationReference",
responseModel: link.result?.type,
target: reference,
};
break;
case "link":
context.finalStep = {
kind: "finalOperationLink",
responseModel: link.result?.type,
target: reference,
};
break;
}
}

function createStatusMonitorPollingData(data: StatusMonitorMetadata): StatusMonitorInfo {
Expand Down Expand Up @@ -1063,7 +1098,7 @@ function processStatusMonitorReference(
program: Program,
referencedOperation: Operation,
context: LroContext
): NextOperationReference | undefined {
): NextOperationReference | (NextOperationLink & { operation: Operation }) | undefined {
const references: Map<string, OperationLinkMetadata> | undefined = getOperationLinks(
program,
referencedOperation
Expand All @@ -1073,19 +1108,29 @@ function processStatusMonitorReference(
const pollingData: OperationLinkMetadata | undefined = references.get(PollingOperationKey);
if (pollingData === undefined) return undefined;
context.pollingOperationLink = pollingData;
const pollingReference = createOperationReference(pollingData);
const pollingReference = createOperationReferenceOrLink(pollingData);
if (pollingReference === undefined) return undefined;
context.statusMonitorInfo = pollingData.result?.statusMonitor;
const finalData: OperationLinkMetadata | undefined = references.get(FinalOperationKey);
if (context.finalStep === undefined && finalData !== undefined) {
const finalReference = createOperationReference(finalData);
const finalReference = createOperationReferenceOrLink(finalData);
const finalModel = finalData?.result?.type;
if (finalReference !== undefined && finalModel !== undefined) {
context.finalStep = {
kind: "finalOperationReference",
responseModel: finalModel,
target: finalReference,
};
switch (finalReference.kind) {
case "reference":
context.finalStep = {
kind: "finalOperationReference",
responseModel: finalModel,
target: finalReference,
};
break;
case "link":
context.finalStep = {
kind: "finalOperationLink",
responseModel: finalModel,
target: finalReference,
};
}
}
}
if (
Expand All @@ -1102,11 +1147,21 @@ function processStatusMonitorReference(
}
const responseModel = pollingData.result?.type;
if (responseModel === undefined) return undefined;
return {
kind: "nextOperationReference",
responseModel: responseModel,
target: pollingReference,
};
switch (pollingReference.kind) {
case "reference":
return {
kind: "nextOperationReference",
responseModel: responseModel,
target: pollingReference,
};
case "link":
return {
kind: "nextOperationLink",
responseModel: responseModel,
target: pollingReference,
operation: pollingData.linkedOperation,
};
}
}

function resolveOperationLocation(
Expand Down
2 changes: 1 addition & 1 deletion packages/typespec-azure-core/src/lro-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export function getLroOperationInfo(
for (const response of targetResponses) {
visitResponse(program, response, (model) => {
if (!isErrorType(model) && resultModel === undefined) {
resultModel = model;
resultModel = getEffectiveModelType(program, model, (p) => !isMetadata(program, p));
}
});
}
Expand Down
Loading

0 comments on commit 92c2c34

Please sign in to comment.