Skip to content

Commit

Permalink
Fix imports
Browse files Browse the repository at this point in the history
  • Loading branch information
G4brym committed Jun 18, 2024
1 parent 8351eff commit 9c23342
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 34 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
},
"plugins": ["@typescript-eslint"],
"rules": {
"@typescript-eslint/ban-types": "off",
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/no-explicit-any": "off",
"linebreak-style": ["error", "unix"],
Expand Down
8 changes: 3 additions & 5 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
name: Publish
on:
workflow_run:
workflows: [CI]
branches: [main]
types: [completed]
push:
branches:
- "**"

concurrency: ${{ github.workflow }}-${{ github.ref }}

Expand All @@ -13,7 +12,6 @@ permissions:

jobs:
publish:
if: ${{ github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand Down
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "chanfana",
"version": "2.0.0",
"version": "2.0.2",
"description": "OpenAPI 3 and 3.1 schema generator and validator for Hono, itty-router and more!",
"main": "dist/index.js",
"module": "dist/index.mjs",
Expand Down Expand Up @@ -74,7 +74,7 @@
"wrangler": "^3.60.1"
},
"dependencies": {
"@asteasolutions/zod-to-openapi": "^7.0.0",
"@asteasolutions/zod-to-openapi": "^7.1.1",
"js-yaml": "^4.1.0",
"openapi3-ts": "^4.3.2",
"zod": "^3.23.8"
Expand Down
4 changes: 2 additions & 2 deletions src/openapi.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getReDocUI, getSwaggerUI } from './ui'
import { type RouterOptions } from './types'
import { type OpenAPIRouteSchema, type RouterOptions } from './types'
import {
OpenApiGeneratorV3,
OpenApiGeneratorV31,
Expand Down Expand Up @@ -135,7 +135,7 @@ export class OpenAPIHandler {
const parsedRoute = this.parseRoute(params.path)

// @ts-ignore
let schema: RouteConfig = undefined
let schema: OpenAPIRouteSchema = undefined
// @ts-ignore
let operationId: string = undefined

Expand Down
2 changes: 1 addition & 1 deletion src/parameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import {
type RegexParameterType,
type EnumerationParameterType,
type ParameterType,
type RouteParameter,
} from './types'
import { z } from 'zod'
import { isSpecificZodType, legacyTypeIntoZod } from './zod/utils'
import { type RouteParameter } from '@asteasolutions/zod-to-openapi/dist/openapi-registry'
import { extendZodWithOpenApi } from '@asteasolutions/zod-to-openapi'

extendZodWithOpenApi(z)
Expand Down
9 changes: 3 additions & 6 deletions src/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ import {
} from './types'
import { coerceInputs } from './parameters'
import { type AnyZodObject, z } from 'zod'
import {
extendZodWithOpenApi,
type RouteConfig,
} from '@asteasolutions/zod-to-openapi'
import { extendZodWithOpenApi } from '@asteasolutions/zod-to-openapi'
import { jsonResp } from './utils'
extendZodWithOpenApi(z)

Expand Down Expand Up @@ -46,7 +43,7 @@ export class OpenAPIRoute {
return this.schema
}

getSchemaZod(): RouteConfig {
getSchemaZod(): OpenAPIRouteSchema {
// Deep copy
const schema = { ...this.getSchema() }

Expand Down Expand Up @@ -104,7 +101,7 @@ export class OpenAPIRoute {
}

async validateRequest(request: Request) {
const schema: RouteConfig = this.getSchemaZod()
const schema: OpenAPIRouteSchema = this.getSchemaZod()
const unvalidatedData: any = {}

const rawSchema: any = {}
Expand Down
56 changes: 49 additions & 7 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,56 @@
import { type AnyZodObject, z, ZodType } from 'zod'
import { type AnyZodObject, z, type ZodEffects, ZodType } from 'zod'
import {
type ResponseConfig,
type ZodRequestBody,
} from '@asteasolutions/zod-to-openapi/dist/openapi-registry'
import { type RouteConfig } from '@asteasolutions/zod-to-openapi'
import { type OpenAPIObjectConfigV31 } from '@asteasolutions/zod-to-openapi/dist/v3.1/openapi-generator'
import { type OpenAPIObjectConfig } from '@asteasolutions/zod-to-openapi/dist/v3.0/openapi-generator'
type RouteConfig,
type ZodMediaTypeObject,
} from '@asteasolutions/zod-to-openapi'
import {
type HeadersObject as HeadersObject30,
type LinksObject as LinksObject30,
type OpenAPIObject,
} from 'openapi3-ts/oas30'
import {
type HeadersObject as HeadersObject31,
type LinksObject as LinksObject31,
} from 'openapi3-ts/oas31'

export type Simplify<T> = { [KeyType in keyof T]: T[KeyType] } & {}

// The following types are copied from @asteasolutions/zod-to-openapi as they are not exported
export type OpenAPIObjectConfig = Omit<
OpenAPIObject,
'paths' | 'components' | 'webhooks'
>
export type OpenAPIObjectConfigV31 = Omit<
OpenAPIObject,
'paths' | 'components' | 'webhooks'
>

type HeadersObject = HeadersObject30 | HeadersObject31
type LinksObject = LinksObject30 | LinksObject31

export type ZodMediaType =
| 'application/json'
| 'text/html'
| 'text/plain'
| 'application/xml'
| (string & {})
export type ZodContentObject = Partial<Record<ZodMediaType, ZodMediaTypeObject>>
export interface ZodRequestBody {
description?: string
content: ZodContentObject
required?: boolean
}
export interface ResponseConfig {
description: string
headers?: AnyZodObject | HeadersObject
links?: LinksObject
content?: ZodContentObject
}
export type RouteParameter =
| AnyZodObject
| ZodEffects<AnyZodObject, unknown, unknown>
| undefined

export interface RouterOptions {
base?: string
schema?: Partial<OpenAPIObjectConfigV31 | OpenAPIObjectConfig>
Expand Down
3 changes: 1 addition & 2 deletions src/zod/registry.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { OpenAPIRegistry } from '@asteasolutions/zod-to-openapi'
import { type OpenAPIDefinitions } from '@asteasolutions/zod-to-openapi/dist/openapi-registry'

// @ts-ignore
export class OpenAPIRegistryMerger extends OpenAPIRegistry {
public _definitions: OpenAPIDefinitions[] = []
public _definitions: object[] = []

merge(registry: OpenAPIRegistryMerger): void {
if (!registry || !registry._definitions) return
Expand Down

0 comments on commit 9c23342

Please sign in to comment.