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

Hono: zod output file is not defined.($ref schemas) #1810

Open
manabu0926 opened this issue Jan 13, 2025 · 1 comment
Open

Hono: zod output file is not defined.($ref schemas) #1810

manabu0926 opened this issue Jan 13, 2025 · 1 comment
Labels
enhancement New feature or request hono Hono related issue zod Zod related issue

Comments

@manabu0926
Copy link

manabu0926 commented Jan 13, 2025

This plugin is very useful! Thanks for making it!
The following sample writing style works well. (And without hono with zod is works well.)

https://github.com/orval-labs/orval/blob/master/samples/hono/hono-with-fetch-client/petstore.yaml

But Our project, splitted schema files like this.
openapi/
openapi/schemas/
openapi/paths/
openapi/openapi.yml

What are the steps to reproduce this issue?

  1. Define splitted openapi.yml
  2. command yarn orval
  3. output file but, not define petstore.zod.ts

What happens?

1 define like this.
openapi/openapi.yml

openapi: 3.0.0
info:
  title: API
  description: swagger API
  version: v1

servers:
  - url: "http://localhost:8082/"

paths:
  /api/current_user:
    $ref: "./resources/paths/api/current_user.yml"

openapi/resources/paths/api/current_user.yml

get:
  tags:
    - CurrentUser
  summary: get current user
  operationId: getCurrentUser
  security:
    - bearerAuth: []
  responses:
    '200':
      description: "OK"
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/current_user"
    '401':
      description: "Unauthorized"
      content:
        application/json:
          schema:
            $ref: "../../components/schemas/responses.yml#/unauthorized"
    "500":
      description: "Internal Server Error"
      content:
        application/json:
          schema:
            $ref: "../../components/schemas/responses.yml#/internal_server_error"
components:
  schemas:
    current_user:
      type: object
      required:
        - name
      properties:
        name:
          type: string
          description: name
          example: "username"
        

orval.config.ts

import { defineConfig } from "orval";

export default defineConfig({
  ...(fe donfig)
  backend: {
    input: {
      target: "./openapi/openapi.yml",
    },
    output: {
      mode: "split",
      client: "hono",
      schemas: "./hono/src/schemas",
      target: "./hono/src/index.ts",
      override: {
        hono: {
          handlers: "hono/src/handlers",
        },
      },
    },
  },
});

2 command yarn orval

3 output this empty file
hono/src/index.zod.ts

/**
 * Generated by orval v7.4.1 🍺
 * Do not edit manually.
 * API
 * Petstore API
 * OpenAPI spec version: v1
 */
import { z as zod } from 'zod';

What were you expecting to happen?

3 output this file
hono/src/index.zod.ts

/**
 * Generated by orval v7.4.1 🍺
 * Do not edit manually.
 * API
 * Petstore API
 * OpenAPI spec version: v1
 */
import { z as zod } from 'zod';
import { CurrentUser } from './schemas/resources-paths-api-current_user.yml';

export const getCurrentUserResponse: zod.ZodType<CurrentUser> = zod.object({
    name: zod.string(),
    email: zod.string(),
});

Any logs, error output, etc?

yarn run v1.22.22
$ /Users/manabu/devbase/power_ageless/node_modules/.bin/orval
🍻 Start orval v7.4.1 - A swagger client generator for typescript
(node:60513) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
fe: Cleaning output folder
⚠️  SyntaxError: Swagger schema validation failed.
  #/paths/~1api~1current_user must NOT have additional properties

🎉 fe - Your OpenAPI spec has been converted into ready to use orval!
⚠️  SyntaxError: Swagger schema validation failed.
  #/paths/~1api~1current_user must NOT have additional properties

🎉 be - Your OpenAPI spec has been converted into ready to use orval!
✨  Done in 0.63s.

Any other comments?

Any ideas, even workarounds, would be appreciated!

What versions are you using?

Please execute npx envinfo --system --npmPackages orval,zod,axios,msw,swr,@tanstack/react-query,@tanstack/vue-query,react,vue and paste the results here.

System:
OS: macOS 15.2
CPU: (12) arm64 Apple M4 Pro
Memory: 2.43 GB / 48.00 GB
Shell: 5.9 - /bin/zsh
npmPackages:
@tanstack/react-query: ^5.63.0 => 5.63.0
axios: ^1.7.9 => 1.7.9
orval: ^7.4.1 => 7.4.1
react: ^18.3.1 => 18.3.1
zod: ^3.24.1 => 3.24.1

@soartec-lab soartec-lab added enhancement New feature or request zod Zod related issue hono Hono related issue labels Jan 15, 2025
@soartec-lab
Copy link
Member

Hi @manabu0926 thanks for made this issue.
I understand that ref of OpenAPI is not resolved with zod.
Until the issue is resolved, use another tool to merge into a single OpenAPI definition and specify it as input.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request hono Hono related issue zod Zod related issue
Projects
None yet
Development

No branches or pull requests

2 participants