Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue in genarated types #1492

Closed
csaba-veezla opened this issue Jan 7, 2025 · 1 comment
Closed

Issue in genarated types #1492

csaba-veezla opened this issue Jan 7, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@csaba-veezla
Copy link

csaba-veezla commented Jan 7, 2025

What version of kubb is running?

3.3.5

What kind of platform do you use?

None

How does your kubb.config.ts config look like

2.28.4

import { defineConfig } from '@kubb/core';
import { pluginOas } from '@kubb/plugin-oas';
import { pluginTs } from '@kubb/swagger-ts';
import { pluginTanstackQuery } from '@kubb/swagger-tanstack-query';
import { pluginZod } from '@kubb/swagger-zod';

export default defineConfig(({ config, watch, logLevel, bun })=>{
  return {
    root: '.',
    input: {
      path: './openapi.2024_01_01.json',
    },
    output: {
      path: './src/gen',
      clean: true,
    },
    plugins: [
      pluginOas({ output: false }),
      pluginTs({
        output: {
          path: './types',
        },
        unknownType: 'unknown',
      }),
      pluginZod({
        output: {
          path: './zod',
        },
        dateType: 'stringOffset',
      }),
      pluginTanstackQuery({
        framework: 'react',
        output: {
          path: './hooks',
        },
        client: {
          importPath: '../../client/client',
        },
        mutate: {
          methods: ['post', 'put', 'patch', 'delete'],
          variablesType: 'mutate',
        },
        infinite: {
          queryParam: 'nextToken',
          cursorParam: 'nextToken',
          initialPageParam: '\'\'',
        },
        
        parser: 'zod',
        suspense: {},
      }),
    ],
  };
});

3.3.5

import { defineConfig } from '@kubb/core';
import { pluginOas } from '@kubb/plugin-oas';
import { pluginTs } from '@kubb/plugin-ts';
import { pluginReactQuery } from '@kubb/plugin-react-query';
import { pluginZod } from '@kubb/plugin-zod';
import { QueryKey } from '@kubb/plugin-react-query/dist/components';
import getTransformer = QueryKey.getTransformer;

export default defineConfig(({ config, watch, logLevel, bun }) => {
  return {
    root: '.',
    input: {
      path: './openapi.2024_01_01.json',
    },
    output: {
      path: './src/gen',
      clean: true,
      extension: {
        '.ts': '',
      },
    },
    plugins: [
      pluginOas({}),
      pluginTs({
        output: {
          path: './types',
        },
        unknownType: 'unknown',
        enumType: 'asConst',
        enumSuffix: '',
      }),
      pluginZod({
        output: {
          path: './zod',
          banner: `// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-nocheck
`,
        },
        dateType: 'stringOffset',
      }),
      pluginReactQuery({
        output: {
          path: './hooks',
          banner: `// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-nocheck
`,
        },
        client: {
          importPath: '@posta/data-plane',
        },
        infinite: {
          queryParam: 'nextToken',
          cursorParam: 'nextToken',
          initialPageParam: '\'\'',
        },
        parser: 'zod',
        suspense: {},
      }),
    ],
  };
});

Swagger/OpenAPI file?

this might not be the minimal repro, but it shows the issue

{
  "openapi": "3.0.0",
  "info": {
    "title": "X",
    "version": "2025-01-01"
  },
  "tags": [],
  "paths": {},
  "components": {
    "schemas": {
      "BaseDateFilter": {
        "type": "object",
        "required": ["type", "operand"],
        "properties": {
          "type": {
            "type": "string",
            "enum": ["date"]
          },
          "operand": {
            "$ref": "#/components/schemas/DateFilterOperand"
          }
        },
        "discriminator": {
          "propertyName": "operand",
          "mapping": {
            "between": "#/components/schemas/DateBetweenFilter",
            "hasValue": "#/components/schemas/DateHasValueFilter",
            "hasNoValue": "#/components/schemas/DateHasNoValueFilter"
          }
        },
        "allOf": [
          {
            "$ref": "#/components/schemas/BaseFilter"
          }
        ]
      },
      "BaseDateFilterWithTimeZone": {
        "type": "object",
        "properties": {
          "timezone": {
            "type": "string"
          },
          "timezoneVariant": {
            "type": "string",
            "enum": ["utc", "organization", "local"]
          }
        },
        "allOf": [
          {
            "$ref": "#/components/schemas/BaseDateFilter"
          }
        ]
      },
      "BaseFilter": {
        "type": "object",
        "required": ["id", "type"],
        "properties": {
          "id": {
            "type": "string"
          },
          "type": {
            "type": "string"
          }
        },
        "discriminator": {
          "propertyName": "type",
          "mapping": {
            "multiSelect": "#/components/schemas/MultiSelectFilterValue",
            "text": "#/components/schemas/TextFilterValue",
            "metadata": "#/components/schemas/MetadataFilterValue"
          }
        }
      },
      "DateBetweenFilter": {
        "type": "object",
        "required": ["operand", "from", "to"],
        "properties": {
          "operand": {
            "type": "string",
            "enum": ["between"]
          },
          "from": {
            "type": "string",
            "format": "date-time"
          },
          "to": {
            "type": "string",
            "format": "date-time"
          }
        },
        "allOf": [
          {
            "$ref": "#/components/schemas/BaseDateFilterWithTimeZone"
          }
        ]
      },
      "DateEqualsFilter": {
        "type": "object",
        "required": ["operand"],
        "properties": {
          "operand": {
            "type": "string",
            "enum": ["equals"]
          }
        },
        "allOf": [
          {
            "$ref": "#/components/schemas/SingleDateFilter"
          }
        ]
      },
      "DateFilterOperand": {
        "type": "string",
        "enum": [
          "equals",
          "notEqualTo",
          "lessThan",
          "greaterThan",
          "lessOrEqual",
          "greaterOrEqual",
          "between",
          "hasValue",
          "hasNoValue"
        ]
      },
      "DateFilterValue": {
        "anyOf": [
          {
            "$ref": "#/components/schemas/DateEqualsFilter"
          },
          {
            "$ref": "#/components/schemas/DateNotEqualsFilter"
          },
          {
            "$ref": "#/components/schemas/DateLessThanFilter"
          },
          {
            "$ref": "#/components/schemas/DateGreaterThanFilter"
          },
          {
            "$ref": "#/components/schemas/DateLessOrEqualFilter"
          },
          {
            "$ref": "#/components/schemas/DateGreaterOrEqualFilter"
          },
          {
            "$ref": "#/components/schemas/DateBetweenFilter"
          },
          {
            "$ref": "#/components/schemas/DateHasValueFilter"
          },
          {
            "$ref": "#/components/schemas/DateHasNoValueFilter"
          }
        ]
      },
      "DateGreaterOrEqualFilter": {
        "type": "object",
        "required": ["operand"],
        "properties": {
          "operand": {
            "type": "string",
            "enum": ["greaterOrEqual"]
          }
        },
        "allOf": [
          {
            "$ref": "#/components/schemas/SingleDateFilter"
          }
        ]
      },
      "DateGreaterThanFilter": {
        "type": "object",
        "required": ["operand"],
        "properties": {
          "operand": {
            "type": "string",
            "enum": ["greaterThan"]
          }
        },
        "allOf": [
          {
            "$ref": "#/components/schemas/SingleDateFilter"
          }
        ]
      },
      "DateHasNoValueFilter": {
        "type": "object",
        "required": ["operand"],
        "properties": {
          "operand": {
            "type": "string",
            "enum": ["hasNoValue"]
          }
        },
        "allOf": [
          {
            "$ref": "#/components/schemas/BaseDateFilter"
          }
        ]
      },
      "DateHasValueFilter": {
        "type": "object",
        "required": ["operand"],
        "properties": {
          "operand": {
            "type": "string",
            "enum": ["hasValue"]
          }
        },
        "allOf": [
          {
            "$ref": "#/components/schemas/BaseDateFilter"
          }
        ]
      },
      "DateLessOrEqualFilter": {
        "type": "object",
        "required": ["operand"],
        "properties": {
          "operand": {
            "type": "string",
            "enum": ["lessOrEqual"]
          }
        },
        "allOf": [
          {
            "$ref": "#/components/schemas/SingleDateFilter"
          }
        ]
      },
      "DateLessThanFilter": {
        "type": "object",
        "required": ["operand"],
        "properties": {
          "operand": {
            "type": "string",
            "enum": ["lessThan"]
          }
        },
        "allOf": [
          {
            "$ref": "#/components/schemas/SingleDateFilter"
          }
        ]
      },
      "DateNotEqualsFilter": {
        "type": "object",
        "required": ["operand"],
        "properties": {
          "operand": {
            "type": "string",
            "enum": ["notEqualTo"]
          }
        },
        "allOf": [
          {
            "$ref": "#/components/schemas/SingleDateFilter"
          }
        ]
      },
      "MetadataFilterValue": {
        "type": "object",
        "required": ["type", "operand", "key"],
        "properties": {
          "type": {
            "type": "string",
            "enum": ["metadata"]
          },
          "operand": {
            "type": "string",
            "enum": ["equals"]
          },
          "key": {
            "type": "string"
          },
          "value": {
            "type": "string"
          }
        },
        "allOf": [
          {
            "$ref": "#/components/schemas/BaseFilter"
          }
        ]
      },
      "MultiSelectFilterOperand": {
        "type": "string",
        "enum": ["is", "isNot"]
      },
      "MultiSelectFilterValue": {
        "type": "object",
        "required": ["type", "operand", "value"],
        "properties": {
          "type": {
            "type": "string",
            "enum": ["multiSelect"]
          },
          "operand": {
            "$ref": "#/components/schemas/MultiSelectFilterOperand"
          },
          "value": {
            "type": "array",
            "items": {}
          }
        },
        "allOf": [
          {
            "$ref": "#/components/schemas/BaseFilter"
          }
        ]
      },
      "SingleDateFilter": {
        "type": "object",
        "required": ["operand", "value"],
        "properties": {
          "operand": {
            "type": "string",
            "enum": [
              "equals",
              "notEqualTo",
              "lessThan",
              "greaterThan",
              "lessOrEqual",
              "greaterOrEqual"
            ]
          },
          "value": {
            "type": "string",
            "format": "date-time"
          }
        },
        "allOf": [
          {
            "$ref": "#/components/schemas/BaseDateFilterWithTimeZone"
          }
        ]
      },
      "TextFilterOperand": {
        "type": "string",
        "enum": [
          "is",
          "isNot",
          "startsWith",
          "endsWith",
          "contains",
          "doesNotContain",
          "isEmpty",
          "isNotEmpty"
        ]
      },
      "TextFilterValue": {
        "type": "object",
        "required": ["type", "operand", "value"],
        "properties": {
          "type": {
            "type": "string",
            "enum": ["text"]
          },
          "operand": {
            "$ref": "#/components/schemas/TextFilterOperand"
          },
          "value": {
            "type": "string"
          }
        },
        "allOf": [
          {
            "$ref": "#/components/schemas/BaseFilter"
          }
        ]
      }
    }
  }
}

What version of external packages are you using(@tanstack-query, MSW, React, Vue, ...)

No response

What steps can reproduce the bug?

Generate the types with both 2.28.4 and with 3.3.5.

If you check the content of the generated BaseDateFilter.ts or DateGreaterOrEqualFilter.ts, it will change in version 3.3.5 and sadly it seems the "original" was better.

How often does this bug happen?

Every time

What is the expected behavior?

Generate the same code as 2.28.4

Additional information

I might mixed up something during the mere, please let me know if this is a config issue, but I do not think so.

@csaba-veezla csaba-veezla added the bug Something isn't working label Jan 7, 2025
@stijnvanhulle
Copy link
Collaborator

v3.4.2 of Kubb will resolve this issue, we used the required fields to add to the overall types but that is not needed anymore. I added a filter to remove keys that are already part of the properties.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants