Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/304.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Swagger Codegen:继承和组合未按预期工作_Java_Inheritance_Swagger_Swagger Codegen - Fatal编程技术网

Java Swagger Codegen:继承和组合未按预期工作

Java Swagger Codegen:继承和组合未按预期工作,java,inheritance,swagger,swagger-codegen,Java,Inheritance,Swagger,Swagger Codegen,我有以下简短的YAML: # Transaction Request object with minimal information that we need Parent: required: - a - b - c properties: a: type: number format: double b: type: string c: type: string # Full transaction Child: requ

我有以下简短的YAML:

# Transaction Request object with minimal information that we need
  Parent:
    required:
  - a
  - b
  - c
properties:
  a:
    type: number
    format: double
  b:
    type: string
  c:
    type: string

# Full transaction
Child:
required:
  - a 
  - b
  - c
allOf:
  - $ref: "#/definitions/Parent"
properties:    
  date: 
    type: string 
    format: date-time
  state: 
    type: string 
    enum: 
      - 1
      - 2
      - 3
在Swagger UI和编辑器中,这些对象按照我的意愿显示:
Child
继承了
a
b
c
字段,并且还有一些附加字段

我原以为:

public class Parent {

  private Double a;
  private String b;
  private String c;

  ...}

然而,虽然
父类
看起来与预期一致,但我的
子类
包含以下内容:

public class Child   {



@Override
public boolean equals(Object o) {
if (this == o) {
  return true;
}
if (o == null || getClass() != o.getClass()) {
  return false;
}
Child child = (Child) o;
return true;
}

... }
它甚至缺少
扩展
。当使用
鉴别器时,它可以工作,但我并不真正想要多态性——只是简单的继承。我怎样才能用大摇大摆的Codegen做到这一点


相关
pom.xml
条目:

            <plugin>
                <groupId>io.swagger</groupId>
                <artifactId>swagger-codegen-maven-plugin</artifactId>
                <version>2.2.2-SNAPSHOT</version>

                <configuration>
                    <inputSpec>${project.basedir}/src/main/resources/test.yaml</inputSpec>
                    <language>jaxrs-resteasy</language>
                    <output>${project.build.directory}/generated-sources/payment</output>

                    <configOptions>
                        <sourceFolder>src/java/main</sourceFolder>
                        <dateLibrary>java8</dateLibrary>
                    </configOptions>

                    <groupId>net.product</groupId>
                    <artifactId>product_api</artifactId>
                    <modelPackage>net.product.product_api.model</modelPackage>
                    <invokerPackage>net.product.product_api</invokerPackage>
                    <apiPackage>net.product.product_api</apiPackage>
                </configuration>

                <executions>

                    <execution>
                        <id>generate-server-stubs</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                        </configuration>
                    </execution>

                </executions>

            </plugin>

昂首阔步
swagger codegen maven插件
2.2.2-快照
${project.basedir}/src/main/resources/test.yaml
jaxrs resteasy
${project.build.directory}/generated sources/payment
src/java/main
爪哇8
净产品
产品api
net.product.product\u api.model
net.product.product_api
net.product.product_api
生成服务器存根
生成
您需要在父类中添加代码

required:
    - "className"

您使用的是哪个版本?在2.2.2-SNAPSHOT上,它可以很好地用于java,使用这个yaml时,我使用了2.1.6,然后还尝试了使用2.2.1。我没有尝试最新的开发版本,因为我们真的希望使用稳定的版本而不是
快照来构建存根。不仅如此,当我尝试输入
2.2.2-SNAPSHOT
作为一个版本时,maven也给了我一个错误,说它的POM丢失了。我只是尝试手动将
2.2.2-SNAPSHOT
jar安装到本地存储库中。然而,用它生成存根产生了与上面完全相同的结果。你能告诉我你用什么语言/框架生成存根吗?同时,我将用我的
pom.xml
条目更新我的帖子。我检查了你提到的版本和当前主分支的版本,我得到了你的结果。出于某种原因,我在三个月前从大师那里克隆的那个几乎可以正常工作。但github上有一个问题可能与您的问题有关。
Cat:
  allOf:
  - $ref: "#/definitions/Animal"
  - type: "object"
    properties:
      declawed:
        type: "boolean"
Animal:
  type: "object"
  required:
  - "className"
  discriminator: "className"
  properties:
    className:
      type: "string"
    color:
      type: "string"
      default: "red"
required:
    - "className"