Skip to content

[Typescript] discriminator property value "../event_type" fails for TWITTER.COM api #7860

Description

@WolfgangHG

Found as part of #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<FollowActivityResponsePayload | LikeWithTweetAuthor | NewsActivityResponsePayload | PostDeleteActivityResponsePayload | ProfileUpdateActivityResponsePayload | Tweet>'.
  Property 'Event_type' does not exist on type 'Partial<FollowActivityResponsePayload>'.

17510     switch (activityStreamingResponsePayload.Event_type) {

The error is in this snippet:

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<FollowActivityResponsePayload | LikeWithTweetAuthor | NewsActivityResponsePayload | PostDeleteActivityResponsePayload | ProfileUpdateActivityResponsePayload | Tweet> | 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:

"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:

/**
 * 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<string, (node: ParseNode) => void>) {
    const mappingValueNode = parseNode?.getChildNode("../event_type");
    if (mappingValueNode) {
        const mappingValue = mappingValueNode.getStringValue();
        if (mappingValue) {
            switch (mappingValue) {
                case "follow.follow":
                    return deserializeIntoFollowActivityResponsePayload;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    Status
    Needs Triage 🔍

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions