简体   繁体   English

使用YAML的Java继承

[英]Java Inheritance using YAML

I want to implement Java inheritance in the generated class files using YAML config. 我想使用YAML配置在生成的类文件中实现Java继承。 As in I want a particular Custom class to inherit/extend from some other Custom class defined in the same YAML file. 如我所希望的那样,一个特定的Custom类可以从同一YAML文件中定义的其他其他Custom类继承/扩展。

I have tried the following changes:Here the expectation is that the generated UpdateDTO class should inherit from CreationDTO class 我尝试了以下更改:在这里期望的是生成的UpdateDTO类应该从CreationDTO类继承

UpdateDTO:
type: CreationDTO
properties:
  id:
    type: integer
    format: int64
    description: the annotation ID
  category:
    type: string
    description: The annotation or adjustment category

Also the second approach that i have tried is as below: 我尝试过的第二种方法如下:

UpdateDTO:
type: 
  $ref: '#/definitions/CreationDTO'
properties:
  id:
    type: integer
    format: int64
    description: the annotation ID
  category:
    type: string
    description: The annotation or adjustment category

Both the approaches are not working for me. 两种方法都不适合我。 UpdateDTO does not extend CreationDTO UpdateDTO不会扩展CreationDTO

We are using the following maven config to generate the source files: 我们正在使用以下maven配置生成源文件:

<plugin>
    <groupId>io.swagger</groupId>
    <artifactId>swagger-codegen-maven-plugin</artifactId>
    <version>2.2.1</version>
    <executions>
      <execution>
        <phase>generate-sources</phase>
        <id>source</id>
        <goals>
          <goal>generate</goal>
        </goals>
        <configuration>
          <inputSpec>${basedir}/src/main/resources/swagger/daa.yaml</inputSpec>
          <language>xx.xxx.xxx.swagger.codegen.languages.JavaResteasyServerApisCodegen</language>
          <output>${project.build.directory}/generated-sources/swagger</output>
          <addCompileSourceRoot>false</addCompileSourceRoot>
          <apiPackage>xx.xxx.xxx.daa.rest</apiPackage>
          <modelPackage>xx.xxx.xxx.daa.rest.model</modelPackage>
        </configuration>
      </execution>
    </executions>
    <dependencies>
      <dependency>
        <groupId>xx.xxx.xxx</groupId>
        <artifactId>abs-swagger-codegen</artifactId>
        <version>1.0.2</version>
      </dependency>
    </dependencies>
  </plugin>

根据这个这个 ,招摇,代码生成还不支持继承了生成的Java类。

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

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