Skip to content

Commit

Permalink
feat: export OpenAPI TypeScript helper types
Browse files Browse the repository at this point in the history
  • Loading branch information
johannschopplich committed May 14, 2024
1 parent d7783e7 commit 4cb4a3d
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ export default defineNuxtModule<ModuleOptions>({
config.externals.inline ||= []
config.externals.inline.push(...[
resolve('runtime/utils'),
resolve('runtime/formData'),
resolve('runtime/form-data'),
resolve('runtime/server/$api'),
])

Expand Down Expand Up @@ -249,6 +249,9 @@ ${schemaEndpointIds.map(i => `
import type { paths as ${pascalCase(i)}Paths } from '#${moduleName}/${i}'
`.trimStart()).join('').trimEnd()}
// OpenAPI helpers
export type { FetchResponseData, FetchResponseError, MethodOption, ParamsOption, RequestBodyOption, FilterMethods } from '${relativeTo('runtime/openapi')}'
// Clients
export type { ApiClient, OpenAPIClient, ApiClientFetchOptions, OpenAPIClientFetchOptions, UseApiData, UseOpenAPIData, UseApiDataOptions, UseOpenAPIDataOptions }
${endpointKeys.map(i => `
Expand Down
1 change: 1 addition & 0 deletions src/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useNuxt } from '@nuxt/kit'
import type { OpenAPI3, OpenAPITSOptions } from 'openapi-typescript'
import type { ApiEndpoint } from './module'

// Add types for compatibility between openapi-typescript v6 and v7
declare module 'openapi-typescript' {
/** @since openapi-typescript@7 */
function _astToString(ast: unknown): string
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/composables/$api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { joinURL } from 'ufo'
import type { NitroFetchOptions } from 'nitropack'
import { resolvePathParams } from '../openapi'
import { headersToObject, serializeMaybeEncodedBody } from '../utils'
import { isFormData } from '../formData'
import { isFormData } from '../form-data'
import type { ModuleOptions } from '../../module'
import { CACHE_KEY_PREFIX } from '../constants'
import type { EndpointFetchOptions } from '../types'
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/composables/useApiData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type { ModuleOptions } from '../../module'
import { CACHE_KEY_PREFIX } from '../constants'
import { resolvePathParams } from '../openapi'
import { headersToObject, serializeMaybeEncodedBody } from '../utils'
import { isFormData } from '../formData'
import { isFormData } from '../form-data'
import type { EndpointFetchOptions } from '../types'
import type { FetchResponseData, FetchResponseError, FilterMethods, ParamsOption, RequestBodyOption } from '../openapi'
import { useAsyncData, useRequestHeaders, useRuntimeConfig } from '#imports'
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/runtime/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { formDataToObject, isFormData, isSerializedFormData, objectToFormData } from './formData'
import { formDataToObject, isFormData, isSerializedFormData, objectToFormData } from './form-data'
import type { ApiClientFetchOptions } from './composables/$api'

export function headersToObject(headers: HeadersInit = {}): Record<string, string> {
Expand Down

0 comments on commit 4cb4a3d

Please sign in to comment.