Skip to content

Commit 6490e80

Browse files
authored
tsp - Added suppport for rfc7231 and fixed an issue related to operationId (#1522)
1 parent 69685d6 commit 6490e80

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

packages/typespec-powershell/src/convertor/convertor.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,11 @@ function getOperationGroups(program: Program, client: SdkClient, psContext: SdkC
137137
continue;
138138
}
139139
const operationId = resolveOperationId(psContext, op);
140-
let group = operationGroupsMap.get(operationId.split("_")[0] || "");
140+
let group = operationGroupsMap.get(operationId.includes('_') ? operationId.split("_")[0] : "");
141141
if (!group) {
142142
group = new OperationGroup("");
143-
group.language.default.name = group.$key = operationId.split("_")[0] || "";
144-
operationGroupsMap.set(operationId.split("_")[0] || "", group);
143+
group.language.default.name = group.$key = operationId.includes('_') ? operationId.split("_")[0] : "";
144+
operationGroupsMap.set(operationId.includes('_') ? operationId.split("_")[0] : "", group);
145145
}
146146
addOperation(psContext, op, group, model, emitterOptions);
147147
}

packages/typespec-powershell/src/utils/modelUtils.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ export function getSchemaForType(
197197
const program = dpgContext.program;
198198
const { usage } = options ?? {};
199199
const type = getEffectiveModelFromType(program, typeInput);
200+
200201
if (schemaCache.has(type)) {
201202
return schemaCache.get(type);
202203
}
@@ -213,7 +214,20 @@ export function getSchemaForType(
213214

214215
if (type.kind === "ModelProperty") {
215216
const typeSchema: Schema = getSchemaForType(dpgContext, type.type, options);
216-
if (isStringType(program, type.type) || isNumericType(program, type.type)) {
217+
const encodeData = getEncode(program, type);
218+
if (encodeData && typeSchema.type === SchemaType.DateTime) {
219+
const propertySchema = { ...typeSchema };
220+
switch (encodeData.encoding) {
221+
case "rfc1123":
222+
case "rfc7231":
223+
(<any>propertySchema).format = "date-time-rfc1123";
224+
break;
225+
default:
226+
break;
227+
}
228+
schemaCache.set(type, <Schema>propertySchema);
229+
return propertySchema;
230+
} else if (isStringType(program, type.type) || isNumericType(program, type.type)) {
217231
// applyIntrinsicDecorators for string and numeric types
218232
// unlike m4, min/max length and pattern, secrets, etc. are not part of the schema
219233
let propertySchema = { ...typeSchema };
@@ -395,7 +409,16 @@ function mergeFormatAndEncoding(
395409
case undefined:
396410
return encodeAsFormat ?? encoding;
397411
case "date-time":
398-
return encoding;
412+
switch (encoding) {
413+
case "rfc3339":
414+
return "date-time";
415+
case "unixTimestamp":
416+
return "unixtime";
417+
case "rfc7231":
418+
return "date-time-rfc7231";
419+
default:
420+
return encoding;
421+
}
399422
case "duration":
400423
default:
401424
return encodeAsFormat ?? encoding;

0 commit comments

Comments
 (0)