Skip to content

support-non-exhaustive-enum#2584

Merged
qiaozha merged 6 commits intoAzure:mainfrom
qiaozha:support-non-exhaustive-enum
Jun 19, 2024
Merged

support-non-exhaustive-enum#2584
qiaozha merged 6 commits intoAzure:mainfrom
qiaozha:support-non-exhaustive-enum

Conversation

@qiaozha
Copy link
Copy Markdown
Member

@qiaozha qiaozha commented Jun 14, 2024

fixes #2476
fixes #2420

Comment thread packages/typespec-ts/test/integration/generated/type/union/src/responses.ts Outdated
Comment thread packages/typespec-ts/src/modular/helpers/operationHelpers.ts Outdated
Comment thread packages/typespec-ts/src/modular/helpers/operationHelpers.ts Outdated
Comment on lines +1204 to +1222
case "enum":
if (!type.isFixed && !type.isNonExhaustive) {
return `${restValue} as ${type.name}`;
}
return restValue;
case "model":
if (type.discriminator) {
const discriminatorProp = type.properties?.filter(
(p) => p.restApiName === type.discriminator
);
if (
discriminatorProp?.length === 1 &&
discriminatorProp[0]?.type.isFixed === false &&
discriminatorProp[0].type.isNonExhaustive === false
) {
return `${restValue} as ${type.name}`;
}
}
return restValue;
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joheredi @dgetu this is a new logic related with the deserialization caused by we are not treating exhaustive enum the same in both RLC and Modular layer.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! We'll use this as a guide when porting to the new serializers

@qiaozha qiaozha marked this pull request as ready for review June 17, 2024 02:06
@qiaozha qiaozha merged commit fb91d96 into Azure:main Jun 19, 2024
@qiaozha qiaozha deleted the support-non-exhaustive-enum branch June 19, 2024 12:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Known* definitions mission in TS Generation [JS] Redesign Extensible Enum generation

2 participants