[Typescript] discriminator property value "../event_type" fails for TWITTER.COM api
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 3.8k
- Forks
- 333
- Avg merge
- 16h 29m
- Merged PRs (30d)
- 116
Description
Found as part of https://github.com/microsoft/kiota/pull/7774:
Using the source code from 2026-06-17 and this command:
```
.\it\generate-code.ps1 -descriptionUrl https://api.twitter.com/2/openapi.json -language Typescript -Dev
.\it\exec-cmd.ps1 -descriptionUrl https://api.twitter.com/2/openapi.json -language Typescript
```
The generated client does not compile:
```
src/app/client/models/index.ts:17510:46 - error TS2339: Property 'Event_type' does not exist on type 'Partial'.
Property 'Event_type' does not exist on type 'Partial'.
17510 switch (activityStreamingResponsePayload.Event_type) {
```
The error is in this snippet:
```typescript
export type ActivityStreamingResponsePayload = FollowActivityResponsePayload | LikeWithTweetAuthor | NewsActivityResponsePayload | PostDeleteActivityResponsePayload | ProfileUpdateActivityResponsePayload | Tweet;
...
/**
* Serializes information the current object
* @param ActivityStreamingResponsePayload The instance to serialize from.
* @param isSerializingDerivedType A boolean indicating whether the serialization is for a derived type.
* @param writer Serialization writer to use to serialize this model
*/
// @ts-ignore
export function serializeActivityStreamingResponsePayload(writer: SerializationWriter, activityStreamingResponsePayload: Partial | undefined | null = {}, isSerializingDerivedType: boolean = false) : void {
if (activityStreamingResponsePayload === undefined || activityStreamingResponsePayload === null) return;
switch (activityStreamingResponsePayload.Event_type) {
case "follow.follow":
serializeFollowActivityResponsePayload(writer, activityStreamingResponsePayload as FollowActivityResponsePayload);
break;
...
}
}
```
This is the snippet from the api spec:
```json
"ActivityStreamingResponsePayload" : {
"oneOf" : [
{
"$ref" : "#/components/schemas/ProfileUpdateActivityResponsePayload"
},
{
"$ref" : "#/components/schemas/NewsActivityResponsePayload"
},
{
"$ref" : "#/components/schemas/FollowActivityResponsePayload"
},
{
"$ref" : "#/components/schemas/Tweet"
},
{
"$ref" : "#/components/schemas/PostDeleteActivityResponsePayload"
},
{
"$ref" : "#/components/schemas/LikeWithTweetAuthor"
}
],
"discriminator" : {
"propertyName" : "../event_type",
"mapping" : {
"follow.follow" : "#/components/schemas/FollowActivityResponsePayload",
"follow.unfollow" : "#/components/schemas/FollowActivityResponsePayload",
"like.create" : "#/components/schemas/LikeWithTweetAuthor",
"news.new" : "#/components/schemas/NewsActivityResponsePayload",
...
}
}
},
```
Might be caused by the discriminator propertyName value "../event_type"?
Another function handles the mapping value like this:
```typescript
/**
* Creates a new instance of the appropriate class based on discriminator value
* @param parseNode The parse node to use to read the discriminator value and create the object
* @returns {FollowActivityResponsePayload | LikeWithTweetAuthor | NewsActivityResponsePayload | PostDeleteActivityResponsePayload | ProfileUpdateActivityResponsePayload | Tweet}
*/
// @ts-ignore
export function createActivityStreamingResponsePayloadFromDiscriminatorValue(parseNode: ParseNode | undefined) : ((instance?: Parsable) => Record void>) {
const mappingValueNode = parseNode?.getChildNode("../event_type");
if (mappingValueNode) {
const mappingValue = mappingValueNode.getStringValue();
if (mappingValue) {
switch (mappingValue) {
case "follow.follow":
return deserializeIntoFollowActivityResponsePayload;
```
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the failure with it/generate-code.ps1 and it/exec-cmd.ps1 using the Twitter OpenAPI URL and Typescript. Inspect the generated src/app/client/models/index.ts, especially serializeActivityStreamingResponsePayload and createActivityStreamingResponsePayloadFromDiscriminatorValue, then trace discriminator handling in the generator. Done means the generated TypeScript client compiles and correctly handles the ../event_type discriminator mapping.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 56/100