当前位置: 首页 > 知识库问答 >
问题:

生成python-flask服务器存根时未定义模型对象

茅星华
2023-03-14
swagger: "2.0"

info:
  version: 0.0.1
  title: Blah API
  description: An API for interacting with the blah system

paths:

  /files:

    get:
      description: Retrieves information on files that match the specified criteria

      produces:
      - "application/json"

      parameters:
        - name: tags
          type: array
          description: The tags for which matching files are to be returned
          in: query
          items:
            type: string

      responses:
        '200':
          description: Successful response
          schema:
            type: array
            items:
              $ref: "#/definitions/File"

definitions:
  File:
    type: object
    properties:
      file_id:
        type: "string"
        format: "uuid"
      path:
        type: "string"
      tags:
        type: array
        items:
          type: "string"
sknick@sknick:~/Repo/Blah/Server$ java -jar /home/sknick/Misc/swagger-codegen-cli-2.3.1.jar generate -l python-flask -o ./Source -i ./api.yaml
[main] INFO io.swagger.parser.Swagger20Parser - reading from ./api.yaml
[main] WARN io.swagger.codegen.DefaultCodegen - Empty operationId found for path: GET /files. Renamed to auto-generated operationId: filesGET
[main] INFO io.swagger.codegen.DefaultGenerator - Model File not imported due to import mapping
[main] INFO io.swagger.codegen.AbstractGenerator - writing file /home/sknick/Repo/Blah/Server/./Source/swagger_server/controllers/default_controller.py
[main] INFO io.swagger.codegen.DefaultGenerator - File exists. Skipped overwriting /home/sknick/Repo/Blah/Server/./Source/swagger_server/test/test_default_controller.py
[main] INFO io.swagger.codegen.AbstractGenerator - writing file /home/sknick/Repo/Blah/Server/./Source/README.md
[main] INFO io.swagger.codegen.AbstractGenerator - writing file /home/sknick/Repo/Blah/Server/./Source/setup.py
[main] INFO io.swagger.codegen.AbstractGenerator - writing file /home/sknick/Repo/Blah/Server/./Source/tox.ini
[main] INFO io.swagger.codegen.AbstractGenerator - writing file /home/sknick/Repo/Blah/Server/./Source/test-requirements.txt
[main] INFO io.swagger.codegen.AbstractGenerator - writing file /home/sknick/Repo/Blah/Server/./Source/requirements.txt
[main] INFO io.swagger.codegen.AbstractGenerator - writing file /home/sknick/Repo/Blah/Server/./Source/git_push.sh
[main] INFO io.swagger.codegen.AbstractGenerator - writing file /home/sknick/Repo/Blah/Server/./Source/.gitignore
[main] INFO io.swagger.codegen.AbstractGenerator - writing file /home/sknick/Repo/Blah/Server/./Source/.travis.yml
[main] INFO io.swagger.codegen.AbstractGenerator - writing file /home/sknick/Repo/Blah/Server/./Source/Dockerfile
[main] INFO io.swagger.codegen.AbstractGenerator - writing file /home/sknick/Repo/Blah/Server/./Source/.dockerignore
[main] INFO io.swagger.codegen.AbstractGenerator - writing file /home/sknick/Repo/Blah/Server/./Source/swagger_server/__init__.py
[main] INFO io.swagger.codegen.AbstractGenerator - writing file /home/sknick/Repo/Blah/Server/./Source/swagger_server/__main__.py
[main] INFO io.swagger.codegen.AbstractGenerator - writing file /home/sknick/Repo/Blah/Server/./Source/swagger_server/encoder.py
[main] INFO io.swagger.codegen.AbstractGenerator - writing file /home/sknick/Repo/Blah/Server/./Source/swagger_server/util.py
[main] INFO io.swagger.codegen.AbstractGenerator - writing file /home/sknick/Repo/Blah/Server/./Source/swagger_server/controllers/__init__.py
[main] INFO io.swagger.codegen.AbstractGenerator - writing file /home/sknick/Repo/Blah/Server/./Source/swagger_server/models/__init__.py
[main] INFO io.swagger.codegen.AbstractGenerator - writing file /home/sknick/Repo/Blah/Server/./Source/swagger_server/models/base_model_.py
[main] INFO io.swagger.codegen.AbstractGenerator - writing file /home/sknick/Repo/Blah/Server/./Source/swagger_server/test/__init__.py
[main] INFO io.swagger.codegen.AbstractGenerator - writing file /home/sknick/Repo/Blah/Server/./Source/swagger_server/swagger/swagger.yaml
[main] INFO io.swagger.codegen.AbstractGenerator - writing file /home/sknick/Repo/Blah/Server/./Source/.swagger-codegen/VERSION

共有1个答案

鲜于海
2023-03-14

它看起来像是python-flask生成器中的一个bug,它不能生成与某些Java类名匹配的模型,例如文件日期等。“忽略模型”行为是通过importmappingdefaultcodegen类中配置的,这里是

一些生成器(如C#)清除importmapping,因为它们不使用Java类映射:
https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/main/Java/io/swagger/codegen/languages/abstractcSharpcodegen.Java#l56

importMapping.clear();

但是python-flask generator没有做到这一点。它可能还应该清除importmapping,但我不是Python/Flask开发人员,所以我不确定。

我建议您在Swagger Codegen存储库中打开一个问题,和/或提交一个PR。

与此同时,一些可能的变通办法是:

    null
 类似资料:
  • 我正在使用openapi生成器生成服务器存根python代码。一切正常,但是,每次我修改OpenAPI规范(yaml文件),代码生成器都会覆盖整个代码,甚至是定制的代码(控制器)。我想开发一个增量工作流,如果我对规范进行了更改,生成器将只修改处理该部分代码的代码。 如果我能够执行规范并拥有一个增量工作流,那就太好了。 我使用的是openapi生成器版本3.3。4. 我试图修改控制器并删除,但每次我

  • 我有基于Spring启动的应用程序和协议代理在我们的环境中运行。所以我要添加一些合同测试。我已经在groovy dsl上放置了一些联系人到项目中。我想为协议代理生成客户端存根。根据留档,我必须将spring.factories文件放入META-INF并添加StubGenerator接口的实现。但是我的自定义存根生成器在GenerateClientStubs任务执行期间不运行。我尝试过在调试模式下运

  • 我刚刚开始玩google proto。当我尝试编译proto java示例中的proto文件时,它不会生成任何grpc文件。 原型文件,https://github.com/grpc/grpc-java/blob/master/examples/src/main/proto/hello_world.proto 终端输出, rsonkhla@raman-OptiPlex-9020:~/sandbox

  • 是否有方法重写build方法返回SampleClass以避免执行build.build?

  • 我添加了maven配置,如下所示。 我正在通过“mvn proc-jar: run”执行它,但是它跳过了grpc服务存根,只将“消息”转换为java代码。 输出为 我有一个简单的proto文件定义为 我只输出生成为HelloReply、HelloReplyOrBuilder、HelloRequest、HelloRequestOrBuilder、HelloWorldProto的文件。缺少迎宾Grpc