Skip to content

[Typescript] discriminator property name with underscore fails for GITHUB.COM api #7862

Description

@WolfgangHG

Found as part of #7774:

Using the source code from 2026-06-17 and this command:

.\it\generate-code.ps1 -descriptionUrl https://raw.githubusercontent.com/github/rest-api-description/refs/heads/main/descriptions/api.github.com/api.github.com.json -language typescript -dev
.\it\exec-cmd.ps1 -descriptionUrl https://raw.githubusercontent.com/github/rest-api-description/refs/heads/main/descriptions/api.github.com/api.github.com.json -language typescript

The generated client does not compile:

src/app/client/user/index.ts:130:29 - error TS2551: Property 'user_view_type' does not exist on type 'Partial<PrivateUser | PublicUser>'. Did you mean 'userViewType'?
  Property 'user_view_type' does not exist on type 'Partial<PrivateUser>'.

130     switch (userGetResponse.user_view_type) {
                                ~~~~~~~~~~~~~~

src/app/client/user/item/index.ts:77:33 - error TS2551: Property 'user_view_type' does not exist on type 'Partial<PrivateUser | PublicUser>'. Did you mean 'userViewType'?
  Property 'user_view_type' does not exist on type 'Partial<PrivateUser>'.

77     switch (account_GetResponse.user_view_type) {
                                   ~~~~~~~~~~~~~~

src/app/client/users/item/index.ts:93:33 - error TS2551: Property 'user_view_type' does not exist on type 'Partial<PrivateUser | PublicUser>'. Did you mean 'userViewType'?
  Property 'user_view_type' does not exist on type 'Partial<PrivateUser>'.

93     switch (usernameGetResponse.user_view_type) {
                                   ~~~~~~~~~~~~~~


Found 3 errors in 3 files.

Errors  Files
     1  src/app/client/user/index.ts:130
     1  src/app/client/user/item/index.ts:77
     1  src/app/client/users/item/index.ts:93

This is the snippet from the json file:

"/user": {
  "get": {
    "summary": "Get the authenticated user",
    "description": "OAuth app tokens and personal access tokens (classic) need the `user` scope in order for the response to include private profile information.",
    "tags": [
      "users"
    ],
    "operationId": "users/get-authenticated",
    "externalDocs": {
      "description": "API method documentation",
      "url": "https://docs.github.com/rest/users/users#get-the-authenticated-user"
    },
    "parameters": [],
    "responses": {
      "200": {
        "description": "Response",
        "content": {
          "application/json": {
            "schema": {
              "oneOf": [
                {
                  "$ref": "#/components/schemas/private-user"
                },
                {
                  "$ref": "#/components/schemas/public-user"
                }
              ],
              "discriminator": {
                "propertyName": "user_view_type",
                "mapping": {
                  "public": "#/components/schemas/public-user",
                  "private": "#/components/schemas/private-user"
                }
              }
            },

The generated class "PublicUser" looks like this:


/**
 * Public User
 */
export interface PublicUser extends Parsable {
    ...
    /**
     * The user_view_type property
     */
    userViewType?: string | null;
}

As the typescript compilation error says, there is a property "userViewType" instead of "user_view_type".

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