Git Product home page Git Product logo

oneapi's Introduction

OneAPI

npm ci codecov

🇨🇳 中文文档

🐝 An API production tool that can replace Swagger/SpringFox 💯 without modifying the back-end code or starting the application

Features

  • Zero cost: Based on AST to identify the APIs that conform to the specifications in the project, neither the back-end code needs to be modified nor the application needs to be started.
  • Code is Document: Automatically identify JavaDoc defined in methods & fields as description information of API documents (compatible with Swagger annotations)
  • Easy to extend: In addition to the RESTFul API, Node can be extended to identify custom protocols within the enterprise, such as RPC, GraphQL, etc.
  • Focus on API production: Compared with other tools in the industry, OneAPI focuses on API production, and also supports the export of OpenAPI protocol format data, which is convenient for consumption in other tools

Install

npm install -g oneapi-cli

Usage

oneapi analysis

Parse the OneAPI schema from the Spring project, parameters:

  • -p: Required, backend project path
  • -o: Required, the parsing result oneapi.json is saved in the directory

Example:

oneapi analysis -p /Users/admin/workspace/mall -o /Users/admin/demo

oneapi service

Generate service file from OneAPI schema, parameters:

  • -s: Required, the oneapi.json file path of the parsing result in the previous step
  • -r: Required, Request import string (request imported in service method)
  • -o: Required, Servies output directory (the files in the directory will be emptied during execution)

Example:

oneapi service -s /Users/admin/demo/oneapi.json -r 'import request from "@/utils/request";' -o /Users/admin/workspace/mall-web/src

oneapi openapi

Generate OpeAPI 3.0 schema

  • -s: Required, the oneapi.json file path of the parsing result in the previous step
  • -o: Required, OpenAPI schema output directory

Example:

oneapi openapi -s /Users/admin/demo/oneapi.json -o /Users/admin/demo

Other

  • Welcome to submit an issue to report the bad case of failed parsing

oneapi's People

Contributors

tudou527 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

oneapi's Issues

umijs插件安装报错,提示react版本冲突

npm i oneapi-umijs-plugin --save
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! Found: [email protected]
npm ERR! node_modules/react
npm ERR!   peer react@">=16.0.0" from @ant-design/[email protected]
npm ERR!   node_modules/@ant-design/cssinjs
npm ERR!     @ant-design/cssinjs@"^1.11.1" from @ant-design/[email protected]
npm ERR!     node_modules/@ant-design/pro-provider
npm ERR!       @ant-design/pro-provider@"2.13.3" from @ant-design/[email protected]
npm ERR!       node_modules/@ant-design/pro-card
npm ERR!         @ant-design/pro-card@"2.5.24" from @ant-design/[email protected]
npm ERR!         node_modules/@ant-design/pro-components
npm ERR!         2 more (@ant-design/pro-list, @ant-design/pro-table)
npm ERR!       6 more (@ant-design/pro-components, @ant-design/pro-field, ...)
npm ERR!     @ant-design/cssinjs@"^1.9.1" from @umijs/[email protected]
npm ERR!     node_modules/@umijs/plugins
npm ERR!       @umijs/plugins@"4.0.87" from @umijs/[email protected]
npm ERR!       node_modules/@umijs/max
npm ERR!         @umijs/max@"^4.0.87" from the root project
npm ERR!     1 more (antd)
npm ERR!   peer react@">=16.0.0" from @ant-design/[email protected]
npm ERR!   node_modules/@ant-design/icons
npm ERR!     @ant-design/icons@"^5.0.0" from @ant-design/[email protected]
npm ERR!     node_modules/@ant-design/pro-card
npm ERR!       @ant-design/pro-card@"2.5.24" from @ant-design/[email protected]
npm ERR!       node_modules/@ant-design/pro-components
npm ERR!         @ant-design/pro-components@"^2.0.1" from @umijs/[email protected]
npm ERR!         node_modules/@umijs/plugins
npm ERR!         1 more (the root project)
npm ERR!       2 more (@ant-design/pro-list, @ant-design/pro-table)
npm ERR!     @ant-design/icons@"^5.0.0" from @ant-design/[email protected]
npm ERR!     node_modules/@ant-design/pro-field
npm ERR!       @ant-design/pro-field@"2.13.5" from @ant-design/[email protected]
npm ERR!       node_modules/@ant-design/pro-components
npm ERR!         @ant-design/pro-components@"^2.0.1" from @umijs/[email protected]
npm ERR!         node_modules/@umijs/plugins
npm ERR!         1 more (the root project)
npm ERR!       4 more (@ant-design/pro-descriptions, @ant-design/pro-form, ...)
npm ERR!     7 more (@ant-design/pro-form, @ant-design/pro-layout, ...)
npm ERR!   112 more (@ant-design/pro-card, @ant-design/pro-components, ...)
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! oneapi-umijs-plugin@"*" from the root project
npm ERR!
npm ERR! Conflicting peer dependency: [email protected]
npm ERR! node_modules/react
npm ERR!   peer react@"^16.x" from [email protected]
npm ERR!   node_modules/oneapi-umijs-plugin
npm ERR!     oneapi-umijs-plugin@"*" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!

提示:npm ERR! Conflicting peer dependency: [email protected]
我用的是umi max v4版本,react使用的版本是18

参数中同时包含RequestParam和RequestBody,解析后会丢失信息

像是这样同时有RequestParam和RequestBody的注解,解析到oneapi.json就会丢失了是query还是body的信息,openapi.json中就是都在requestBody里了

    @RequestMapping("/check")
    public RestResp<xxxxxO> check(@RequestParam("xxid") String xxid, @RequestBody xxxxxParam param) {
        param.setUid(xxid);
        return RestResp.buildDataResp(checkxxxxInfo(param));
    }
          "parameter": [
            {
              "name": "xxid",
              "isRequired": false,
              "isPathVariable": false,
              "type": { "name": "String", "classPath": "java.lang.String" },
              "jsType": "string"
            },
            {
              "name": "param",
              "isRequired": false,
              "isPathVariable": false,
              "type": {
                "name": "xxxParam",
                "classPath": "xxxxParam"
              },
              "jsType": "xxxxParam"
            }
          ],

nested class not support

@SpringBootApplication
public class Application {
	@RestController
	@RequestMapping("/")
        class Controller {
       		public String index(){
			return "Hello";
		}
        }
	
	public static void main(String[] args) {
		SpringApplication.run(Chapter1Application.class, args);
	}
}

当Controller上面的注解RequestMapping有多个value的时候,openapi会有问题

当Controller上面的注解RequestMapping有多个value的时候

@RestController
@RequestMapping({"/xxx/a","/xxx/b"})
public class GroupApproveController {

}

解析出来的oneapi.json会像是这样

"annotations": [
        { "name": "Slf4j", "classPath": "lombok.extern.slf4j.Slf4j", "fields": [] },
        {
          "name": "RestController",
          "classPath": "org.springframework.web.bind.annotation.RestController",
          "fields": []
        },
        {
          "name": "RequestMapping",
          "classPath": "org.springframework.web.bind.annotation.RequestMapping",
          "fields": [
            {
              "name": "value",
              "type": "Constant",
              "array": true,
              "value": ["/xxx/a", "/xxx/b"]
            }
          ]
        }
      ],

使用openapi转成swagger格式时,因为baseURI是个数组,导致path.join方法报异常
image

是不是不支持 ModelAttribute 和 Post同时使用

例如


    /**
     * 更新密码
     *
     * @param adminUpdatePwdForm
     * @return
     * @throws BussException
     */
    @PostMapping(value = "/pwd", produces = "application/json; charset=utf-8")
    public void updatePwd(@ModelAttribute @Valid AdminUpdatePwdForm adminUpdatePwdForm) throws BussException {
        adminService.updatePwd(adminUpdatePwdForm);
    }

openApi 的结果显示是

        "/bAdmin/v1/admins/pwd": {
            "post": {
                "tags": [
                    "AdminRest"
                ],
                "operationId": "updatePwd",
                "summary": "更新密码",
                "description": "更新密码",
                "requestBody": {
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {}
                            }
                        }
                    }
                },
                "responses": {
                    "200": {
                        "description": "",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/void"
                                }
                            }
                        }
                    }
                }
            }
        },

图片

正确的应该为 modelAttribete & post 代表 `x-www-form-urlencoded`

oneapi analysis出错

[09:12:56] class: com.ruoyi.web.domain.Vehicle
[09:12:56]   field count: 49
[09:12:56]     addressName: String
[09:12:56]     platformName: String
[09:12:56]     fullName: String
[09:12:56]     vehicleId: Long
[09:12:56]     operationType: String
[09:12:56]     merchantCode: String
[09:12:56]     plateNumber: String
[09:12:56]     plateColor: String
[09:12:56]     energyType: String
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0
        at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64)
        at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70)
        at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:266)
        at java.base/java.util.Objects.checkIndex(Objects.java:361)
        at java.base/java.util.ArrayList.get(ArrayList.java:427)
        at com.oneapi.spring.utils.ClassUtil.lambda$getAnnotation$3(ClassUtil.java:123)
        at java.base/java.util.LinkedHashMap.forEach(LinkedHashMap.java:721)
        at com.oneapi.spring.utils.ClassUtil.lambda$getAnnotation$4(ClassUtil.java:62)
        at java.base/java.lang.Iterable.forEach(Iterable.java:75)
        at com.oneapi.spring.utils.ClassUtil.getAnnotation(ClassUtil.java:46)
        at com.oneapi.spring.analysis.BasicAnalysis.lambda$getFieldList$3(BasicAnalysis.java:226)
        at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
        at com.oneapi.spring.analysis.BasicAnalysis.getFieldList(BasicAnalysis.java:211)
        at com.oneapi.spring.analysis.BasicAnalysis.analysisClass(BasicAnalysis.java:198)
        at com.oneapi.spring.analysis.BasicAnalysis.analysisFromResource(BasicAnalysis.java:123)
        at com.oneapi.spring.analysis.BasicAnalysis.analysis(BasicAnalysis.java:62)
        at com.oneapi.spring.Application.lambda$analysisClassReference$3(Application.java:147)
        at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
        at com.oneapi.spring.Application.analysisClassReference(Application.java:146)
        at com.oneapi.spring.Application.run(Application.java:114)
        at com.oneapi.spring.Application.main(Application.java:178)

Bad Case

/org/apache/commons/commons-pool2/2.11.1/commons-pool2-2.11.1-sources.jar

org.apache.commons.pool2.impl.GenericObjectPool#L104,IdentityWrapper 类型来自于继承类 BaseGenericObjectPool 中的定义

TypeError: Cannot read properties of undefined (reading 'classPath')

错误复现操作:
步骤 1 :

# 1
pnpm dlx create-umi@latest

# 2 出现选项后,选择antd-pro

步骤 2:
配置 .umirc.ts 文件

  plugins: [
    // 开启插件
    'oneapi-umijs-plugin',
  ],
  
  oneapi: {
    // services 中导入的 request 配置
    requestLibPath: "import { request } from 'umi';",
    // 使用相对路径或在线地址
    // schemaPath: "https://oneapi.app/docs/oneapi.json",
    schemaPath: "https://gw.alipayobjects.com/os/antfincdn/M%24jrzTTYJN/oneapi.json",
    // schemaPath: "../oneapi-site/docs/oneapi.json",
  },

步骤3:
执行 pnpm dev , 然后访问 http://localhost:8000/umi/plugin/oneapi

即可出现上述错误。

本次操作的目标时想执行步骤1,步骤2以及步骤3后,能够正常在页面(http://localhost:8000)上体验table 的 crud,没想到报错了。

大佬, 有空帮忙看一下了,任何帮助,都感激不尽。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.