Skip to content

Conversation

hayawata3626
Copy link
Contributor

@hayawata3626 hayawata3626 commented Jul 30, 2025

Closed #311

Fixes by supporting import type syntax via useTypeImports option.

Settings

import {
  generateSchemaTypes,
  generateReactQueryComponents,
} from "@openapi-codegen/typescript";
import { defineConfig } from "@openapi-codegen/cli";

export default defineConfig({
  github: {
    from: {
      source: "url",
      url: "https://api.apis.guru/v2/specs/github.com/1.1.4/openapi.yaml",
    },
    outputDir: "src/github",
    to: async (context) => {
      const filenamePrefix = "github";
      const { schemasFiles } = await generateSchemaTypes(context, {
        filenamePrefix,
        useTypeImports: true,
      });
      await generateReactQueryComponents(context, {
        filenamePrefix,
        schemasFiles,
        useTypeImports: true,
      });
    },
  },
});

Generated files

githubComponents.ts

/**
 * Generated by @openapi-codegen
 *
 * @version 1.1.4
 */
import * as reactQuery from "@tanstack/react-query";
import {
  type GithubContext,
  useGithubContext,
  queryKeyFn,
} from "./githubContext";
import { deepMerge } from "./githubUtils";
import type * as Fetcher from "./githubFetcher";
import { githubFetch } from "./githubFetcher";
import type * as Schemas from "./githubSchemas";
import type * as Responses from "./githubResponses";

githubContext.ts

import {
  skipToken,
  type DefaultError,
  type Enabled,
  type QueryKey,
  type UseQueryOptions,
} from "@tanstack/react-query";
import type { QueryOperation } from "./githubComponents";

githubFetcher.ts

import type { GithubContext } from "./githubContext";

@hayawata3626
Copy link
Contributor Author

@fabien0102
Hi! This PR adds a useTypeImports option to address the issue discussed in #311.
I'd appreciate it if you could take a look when you have a moment 🙏 Thanks for maintaining this great tool!

Copy link
Owner

@fabien0102 fabien0102 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks amazing! So amazing that I think we should use this implem as default and bump the major version😀

@hayawata3626
Copy link
Contributor Author

@fabien0102
Thank you for the prompt review! I've made the revisions👍

@hayawata3626 hayawata3626 requested a review from fabien0102 July 31, 2025 06:44
@hayawata3626
Copy link
Contributor Author

@fabien0102
I found some other parts that needed to be fixed, so I addressed those and enabled useTypeImports by default. Please check again!

Copy link
Owner

@fabien0102 fabien0102 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good 🎉 Thanks again :)

@fabien0102 fabien0102 merged commit 6c16829 into fabien0102:main Aug 5, 2025
1 check passed
@github-actions github-actions bot mentioned this pull request Aug 5, 2025
@hayawata3626 hayawata3626 deleted the feature/use-type-imports branch August 5, 2025 09:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support type-only imports when using verbatimModuleSyntax
2 participants