Skip to content

propertyNames in schema not being recognized (_heyapi_190_ instead of the enum is in the generated types) #3004

@csrs

Description

@csrs

Description

First time trying out this generator! I appreciate the great set-up instructions. My spec contains a type that uses propertyNames. I saw that this is supported (#2279) but a seemingly random array _heyapi_190_ is in the generated code instead of the enum. Do I need to use a specific plugin in order to see the enum?

Spec input file

 "objectTypes": {
            "type": "object",
            "additionalProperties": {
              "type": "number",
              "format": "double"
            },
            "example": {
              "objectType1": 1,
              "objectType2": 0.5
            },
            "propertyNames": {
              "$ref": "#components/schemas/ObjectType",
              "enum": [
                "OBJECT_TYPE1",
                "OBJECT_TYPE2",
              ]
            }
          },

  "ObjectType": {
        "$ref": "#components/schemas/ObjectType",
        "enum": [
          "OBJECT_TYPE1",
          "OBJECT_TYPE2",
        ]
      }

Generated code in schemas.gen.ts

 objectTypes: {
      type: 'object',
      additionalProperties: {
        type: 'number',
        format: 'double',
      },
      propertyNames: {
        $ref: '#components/schemas/ObjectType',
        enum: [
          'OBJECT_TYPE1',
          'OBJECT_TYPE2',
        ],
      },
    },

export const ObjectTypeSchema = {
  $ref: '#components/schemas/ObjectType',
  enum: [
    'OBJECT_TYPE1',
    'OBJECT_TYPE2',
  ],
} as const;

Output in types.gen.ts after running pnpm run openapi-ts

objectTypes?: {
   [key in _heyapi_190_]?: number;
 };

Expected correct output

objectTypes?: {
    [key in ObjectType]?: number;
  };

Reproducible example or configuration

The config file comes from the Hey-api Stackblitz example:
https://stackblitz.com/edit/hey-api-client-fetch-example?file=openapi-ts.config.ts

package.json

"scripts": {"openapi-ts": "openapi-ts",}

openapi-ts.config.ts

const auth = {
  username: the_username,
  password: the_password,
};

const credentials = Buffer.from(`${auth.username}:${auth.password}`).toString('base64');

export default defineConfig({
  input: {
    path: 'https://our-spec-url',
    fetch: {
      headers: {
        Authorization: `Basic ${credentials}`,
      },
    },
  },
  output: {
    format: 'prettier',
    lint: 'eslint',
    path: 'openapiV31/src/client',
  },
  plugins: [
    '@hey-api/schemas',
    {
      dates: true,
      name: '@hey-api/transformers',
    },
    {
      enums: 'javascript',
      name: '@hey-api/typescript',
    },
    {
      name: '@hey-api/sdk',
      transformer: true,
    },
  ],
});

OpenAPI specification (optional)

 "objectTypes": {
            "type": "object",
            "additionalProperties": {
              "type": "number",
              "format": "double"
            },
            "example": {
              "objectType1": 1,
              "objectType2": 0.5
            },
            "propertyNames": {
              "$ref": "#components/schemas/ObjectType",
              "enum": [
                "OBJECT_TYPE1",
                "OBJECT_TYPE2",
              ]
            }
          },

  "ObjectType": {
        "$ref": "#components/schemas/ObjectType",
        "enum": [
          "OBJECT_TYPE1",
          "OBJECT_TYPE2",
        ]
      }

System information (optional)

  • OpenAPI v3.1.0
  • pnpm v10.13.1
  • hey-api/openapi-ts v0.87.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug 🔥Broken or incorrect behavior.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions