Skip to content

[Bug]: alova gen生成代码报错 #137

@LanXa7

Description

@LanXa7

这是否是一个 Bug?

  • 我已经确认我要报告的是一个 Bug

这个问题是否已经存在?

  • 我已经确认这个 Issue 没有被报告过

Alova 版本

3.4.1

前端框架

Vue

问题描述

使用alova gen通过后端提供的文档路径生成代码失败 但是手动下载接口文档后通过本地文件生成是成功的

期望的表现

alova gen 生成成功

复现链接

暂时没有 如有需要可以提供

复现步骤

1.使用 alova gen拉取后端文档即可
2.curl -o 后端文档到本地 使用alova gen通过本地文件生成代码 对比一下是成功的

系统信息

补充说明

lanxa7@Lanxa7s-Mac-mini i18n-demo % alova gen -f
⠼ Generating.../Users/lanxa7/robot_project/frontend/i18n-demo/node_modules/.pnpm/@alova+wormhole@1.5.0/node_modules/@alova/wormhole/dist/helper/logger/index.js:68
        return new DEFAULT_CONFIG.Error(this.errorMsg(error));
               ^

Error: Cannot read file from http://localhost:8080/openapi.yaml
    at Logger.throwError (/Users/lanxa7/robot_project/frontend/i18n-demo/node_modules/.pnpm/@alova+wormhole@1.5.0/node_modules/@alova/wormhole/dist/helper/logger/index.js:68:16)
    at getOpenApiData (/Users/lanxa7/robot_project/frontend/i18n-demo/node_modules/.pnpm/@alova+wormhole@1.5.0/node_modules/@alova/wormhole/dist/core/parser/openApiParser/helper.js:137:31)
    at process.processTicksAndRejections (node:internal/process/task_queues:103:5)
    at async GeneratorHelper.generate (/Users/lanxa7/robot_project/frontend/i18n-demo/node_modules/.pnpm/@alova+wormhole@1.5.0/node_modules/@alova/wormhole/dist/helper/config/GeneratorHelper.js:117:24)
    at async Promise.all (index 0)
    at async Command.actionGen (/Users/lanxa7/robot_project/frontend/i18n-demo/node_modules/.pnpm/@alova+wormhole@1.5.0/node_modules/@alova/wormhole/dist/bin/actions.js:23:25)

Node.js v24.11.1

alova配置:

import { defineConfig } from '@alova/wormhole';

// For more config detailed visit:
// https://alova.js.org/tutorial/getting-started/extension-integration

export default defineConfig({
  generator: [
    {
      /**
       * file input. support:
       * 1. openapi json file url
       * 2. local file
       */
      input: 'http://localhost:8080/openapi.yaml',

      /**
       * input file platform. Currently only swagger is supported.
       * When this parameter is specified, the input field only needs to specify the document address without specifying the openapi file
       */
      platform: 'swagger',

      /**
       * output path of interface file and type file.
       * Multiple generators cannot have the same address, otherwise the generated code will overwrite each other.
       */
      output: 'src/api'

      /**
       * the mediaType of the generated response data. default is `application/json`
       */
      // responseMediaType: 'application/json',

      /**
       * the bodyMediaType of the generated request body data. default is `application/json`
       */
      // bodyMediaType: 'application/json',

      /**
       * the generated api version. options are `2` or `3`, default is `auto`.
       */
      // version: 'auto',

      /**
       * type of generated code. The options are `auto/ts/typescript/module/commonjs`
       */
      // type: 'auto',

      /**
       * exported global api name, you can access the generated api globally through this name, default is `Apis`.
       * it is required when multiple generators are configured, and it cannot be repeated
       */
      // global: 'Apis',

      /**
       * filter or convert the generated api information, return an apiDescriptor, if this function is not specified, the apiDescriptor object is not converted
       */
      // handleApi: apiDescriptor => {
      //  return apiDescriptor;
      // }
    }
  ]

  /**
   * extension only
   * whether to automatically update the interface, enabled by default, check every 5 minutes, closed when set to `false`
   */
  // autoUpdate: true
});

下载下来的api文档:

openapi: 3.0.1
info:
  title: App Service
  description: App Service API
  version: 1.0
paths:
  /book:
    post:
      tags:
        - BookController
      operationId: createBook
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/BookSaveInput'
        required: true
      responses:
        200:
          description: OK
  /book/list:
    get:
      tags:
        - BookController
      operationId: listBook
      responses:
        200:
          description: OK
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Dynamic_Book'
  /book/{id}:
    put:
      tags:
        - BookController
      operationId: updateBook
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: integer
            format: int64
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/BookSaveInput'
        required: true
      responses:
        200:
          description: OK
    delete:
      tags:
        - BookController
      operationId: deleteBook
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: integer
            format: int64
      responses:
        200:
          description: OK
  /dict:
    post:
      tags:
        - DictController
      operationId: createDict
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/DictSaveInput'
        required: true
      responses:
        200:
          description: OK
  /dict/page:
    get:
      tags:
        - DictController
      operationId: pageDict
      parameters:
        - name: pageIndex
          in: query
          required: true
          schema:
            type: integer
            format: int32
            default: 0
        - name: pageSize
          in: query
          required: true
          schema:
            type: integer
            format: int32
            default: 10
        - name: categoryCode
          in: query
          schema:
            type: string
        - name: description
          in: query
          schema:
            type: string
      responses:
        200:
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Page_Dynamic_DictCategory'
  /dict/{categoryCode}:
    get:
      tags:
        - DictController
      operationId: getDictTreeByCategoryCode
      parameters:
        - name: categoryCode
          in: path
          required: true
          schema:
            type: string
        - name: languageCode
          in: query
          required: true
          schema:
            type: string
            enum:
              - EN
              - ZH
              - JA
      responses:
        200:
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Dynamic_DictCategory'
  /dict/{id}:
    put:
      tags:
        - DictController
      operationId: updateDict
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: integer
            format: int64
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/DictSaveInput'
        required: true
      responses:
        200:
          description: OK
  /dict/{id}/dict_item:
    get:
      tags:
        - DictController
      operationId: getDictById
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: integer
            format: int64
      responses:
        200:
          description: OK
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Dynamic_DictItem'
components:
  schemas:
    BookSaveInput:
      type: object
      properties:
        name:
          type: string
        price:
          type: number
          format: double
        publishTime:
          type: string
    Dynamic_Book:
      type: object
      properties:
        id:
          type: integer
          format: int64
        name:
          type: string
        price:
          type: number
          format: double
        publishTime:
          type: string
        createdTime:
          type: string
    DictSaveInput:
      type: object
      properties:
        categoryCode:
          type: string
        description:
          type: string
        dictItems:
          type: array
          items:
            $ref: '#/components/schemas/DictSaveInput_TargetOf_dictItems'
    Page_Dynamic_DictCategory:
      type: object
      properties:
        rows:
          type: array
          items:
            $ref: '#/components/schemas/Dynamic_DictCategory'
        totalPageCount:
          type: integer
          format: int64
        totalRowCount:
          type: integer
          format: int64
    Dynamic_DictCategory:
      type: object
      properties:
        id:
          type: integer
          format: int64
        createdTime:
          description: 创建时间
          type: string
        categoryCode:
          type: string
        description:
          type: string
        dictItems:
          type: array
          items:
            $ref: '#/components/schemas/Dynamic_DictItem'
        dictItemCount:
          type: integer
          format: int32
    Dynamic_DictItem:
      type: object
      properties:
        id:
          type: integer
          format: int64
        createdTime:
          description: 创建时间
          type: string
        itemCode:
          type: string
        dictCategory:
          $ref: '#/components/schemas/Dynamic_DictCategory'
        translations:
          type: array
          items:
            $ref: '#/components/schemas/Dynamic_DictTranslation'
    DictSaveInput_TargetOf_dictItems:
      type: object
      properties:
        itemCode:
          type: string
        translations:
          type: array
          items:
            $ref: '#/components/schemas/DictSaveInput_TargetOf_dictItems_TargetOf_translations'
    Dynamic_DictTranslation:
      type: object
      properties:
        id:
          type: integer
          format: int64
        createdTime:
          description: 创建时间
          type: string
        value:
          type: string
        dictItem:
          $ref: '#/components/schemas/Dynamic_DictItem'
        languageCode:
          type: string
          enum:
            - EN
            - ZH
            - JA
    DictSaveInput_TargetOf_dictItems_TargetOf_translations:
      type: object
      properties:
        value:
          type: string
        languageCode:
          type: string
          enum:
            - EN
            - ZH
            - JA

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions