简体   繁体   中英

Java Inheritance using YAML

I want to implement Java inheritance in the generated class files using YAML config. As in I want a particular Custom class to inherit/extend from some other Custom class defined in the same YAML file.

I have tried the following changes:Here the expectation is that the generated UpdateDTO class should inherit from CreationDTO class

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

We are using the following maven config to generate the source files:

<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类。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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