首页 > 解决方案 > 如何运行 Swagger Codegen 生成的 Kotlin 服务器?

问题描述

我无法运行kotlin-serverSwagger Codegen v. 3 生成的文件。

.yaml文件是:

openapi: 3.0.0
info:
  title: Experiement with Swagger
  description: Test
  version: 1.0.0
servers:
  - url: 'http://localhost:8080'
    description: production server's url
tags:
  - name: Test
    description: Test
    externalDocs:
      description: Find out more
      url: 'http://localhost:8080'
paths:
  /testURI:
    post:
      tags:
        - Test
      summary: Test
      description: Test
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Test'
      responses:
        '200':
          description: Test success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TestSuccessResponse'
        '404':
          description: >-
            Only a signed in user can add a question. This response means that
            the user isn't signed in.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/UnauthorisedErrorResponse'
        '500':
          description: >-
            means some internal error occur on the server while doing the
            operation. The state of the operation if un-determined and the
            operation could be succesful, failed or partially successful
            (because some database operations are not rolled back if error
            occurs!
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/InternalServerErrorResponse'


components:
  schemas:
    Test:
      type: object
      properties:
        some-input:
          type: string

    TestSuccessResponse:
      type: object
      properties:
        result:
          type: string
          enum:
            - success
        additional-info:
          type: string
          enum:
            - Test successful
      required:
        - result
        - additional-info
    UnauthorisedErrorResponse:
      type: object
      properties:
        result:
          type: string
          enum:
            - error
        additional-info:
          type: string
          enum:
            - Not authorised
      required:
        - result
        - additional-info
    InternalServerErrorResponse:
      type: object
      properties:
        result:
          type: string
          enum:
            - error
        additional-info:
          type: string
          enum:
            - Internal Server Error
      required:
        - result
        - additional-info

我将它粘贴到 Swagger 编辑器中,下载kotlin-server kotlin-server-server-generated.zip,解压缩C:\Users\manu\Documents\manu\kotlin-server-server-generated,打开Readme.MD文件并按照其中的说明进行操作。

在使用 WindowscmdC:\Users\manu\Documents\manu\kotlin-server-server-generated
我首先运行了gradle wrapper.

我得到了这个输出:

启动一个 Gradle 守护程序,1 个不兼容的和 2 个停止的守护程序无法重用,使用 --status 了解详细信息
构建缓存是一个孵化功能。

在 17 秒内构建成功
1 个可操作的任务:1 个已执行

然后我跑了gradlew check assemble

C:\Users\manu\Documents\manu\kotlin-server-server-generated>gradlew check assemble
启动一个 Gradle 守护进程,1 个不兼容和 2 个停止的守护进程无法重用,详细信息使用 --status
构建缓存是一个孵化功能.
w: C:\Users\manu\Documents\manu\kotlin-server-server-generated\src\main\kotlin\io\swagger\server\apis\TestApi.kt: (51, 9): 变量 'gson' 是从未使用
w: C:\Users\manu\Documents\manu\kotlin-server-server-generated\src\main\kotlin\io\swagger\server\apis\TestApi.kt: (52, 9): 变量 'empty ' 从未使用过

任务 :startShadowScripts
将 TaskInputs.file() 与无法解析为 File 对象的内容一起使用已被弃用,并计划在 Gradle 5.0 中删除。请改用 TaskInputs.files()。

在 36 秒内构建成功
10 个可操作的任务:10 个已执行

然后我跑了java -jar ./build/libs/kotlin-server.jar

但是当我将浏览器指向 时localhost:8080,我看到了Page Not Found

我究竟做错了什么?

标签: kotlinswagger-codegen

解决方案


推荐阅读