小编GHA*_*SEN的帖子

如何附加抛出异常到 openapi-generator-maven-plugin 生成的其余端点

我正在使用 openapi-generator-maven-plugin 从 springboot 应用程序中的 yaml 文件生成 java 类。我想让所有端点抛出 CustomException。

如何配置插件来做到这一点?

这是 open-ui.yaml。我定义了返回 UserDto 列表的端点“users”。我希望该方法在签名中抛出异常。

openapi: "3.0.0"
info:
  version: 1.0.0
  title: Test Api
  license:
    name: MIT
servers:
  - url: "https://{domain}/test/{basePath}"

paths:
  /users:
    get:
      summary: users
      operationId: getUsers
      tags:
        - users
      parameters:
        - name: limit
          in: query
          schema:
            type: integer

      responses:
        '200':
          description: A page of users
          content:
            application/v1+json; charset=utf-8:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/UserDto'
  
Run Code Online (Sandbox Code Playgroud)

pom.xml

     <plugin>
            <groupId>org.openapitools</groupId>
            <artifactId>openapi-generator-maven-plugin</artifactId>
            <version>5.3.1</version>
            <executions>
                <execution>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                    <configuration>
                        <inputSpec>
                            ${project.basedir}/swagger/open-ui.yaml
                        </inputSpec>
            .... …
Run Code Online (Sandbox Code Playgroud)

maven-plugin spring-boot springdoc-openui

5
推荐指数
1
解决办法
1657
查看次数