简体   繁体   English

swagger-codegen简单模型缺失

[英]swagger-codegen simple models missing

I'm realizing my second API with swagger/swagger-codegen. 我正在用swagger / swagger-codegen实现我的第二个API。 After having a really good start with my first one I'm somewhat stuck with the following problem: I'm having multiple definitions like the following: 在我的第一个开端非常好之后,我就陷入了以下问题:我有如下多个定义:

TopIssueReference:
  description: Id of a top issue
  type: string
  example:
    itemid: 'd32c1213-4773-442e-9c5f-f5d516358869'

All those definitions only are aliases for type string, some with format date-time, some naked like the one above. 所有这些定义仅是字符串类型的别名,有些具有日期时间格式,有些则像上面的那样是裸露的。

The swagger editor is fine with those definitions. swagger编辑器可以很好地使用这些定义。

When I use one of them in a $ref clause within some object definition the generator produces a reference to a class named like my definition, TopIssueReference in this case. 当我在某个对象定义的$ref子句中使用其中之一时,生成器将生成对类似于我的定义的类的引用,在本例中为TopIssueReference

The generated TopIssueReference class is the following (in java): 生成的TopIssueReference类如下(在Java中):

@ApiModel(description = "Id of a top issue")
public class TopIssueReference  {
  @Override
  public String toString()  {
    StringBuilder sb = new StringBuilder();
    sb.append("class TopIssueReference {");
    sb.append("}");
    return sb.toString();
  }
}

which is not really useful. 这不是真的有用。

Does anybody have an idea what's going wrong here? 有人知道这里出了什么问题吗? Shouldn't the generator either produce a reference to a String or at least make TopIssueReference derive from a string (however useful that may be)? 生成器不应该生成对String的引用,或者至少不使TopIssueReference从字符串派生(可能有用)?

For some of those definitions, the generator does not generate any class at all - but the references are still there, so the resulting code does not even compile. 对于其中的一些定义,生成器根本不会生成任何类-但是引用仍然存在,因此生成的代码甚至不会编译。

I tried generating servers and clients with java and python, and both are having the same problem. 我尝试使用java和python生成服务器和客户端,但两者都存在相同的问题。

Try Bellow code to your swagger file to generate code. 将贝娄代码尝试到您的swagger文件以生成代码。

TopIssueReference:
    description: Id of a top issue
    type: object
    properties:
      itemid:
        type: string

i hope it's useful to you ...! 我希望它对您有用...!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM