laufend: < /p>
Code: Select all
java -jar swagger-codegen-cli-3.0.68.jar generate -i swagger.yaml -l java -o ./_swagger
< /code>
mit: < /p>
components:
schemas:
Pet:
discriminator: petType
required:
- name
- petType # required for inheritance to work
properties:
name:
type: string
petType:
type: string
Cat:
allOf:
- $ref: '#/definitions/Pet' # Cat has all properties of a Pet
- properties: # extra properties only for cats
huntingSkill:
type: string
default: lazy
enum:
- lazy
- aggressive
Dog:
allOf:
- $ref: '#/definitions/Pet' # Dog has all properties of a Pet
- properties: # extra properties only for dogs
packSize:
description: The size of the pack the dog is from
type: integer
openapi: 3.0.3
security: []
servers: []
paths:
< /code>
Erzeugt < /p>
public class Dog { ...}
Code: Select all
swagger: "2.0"
basePath: "/v2"
definitions:
Pet:
discriminator: petType
required:
- name
- petType # required for inheritance to work
properties:
name:
type: string
petType:
type: string
Cat:
allOf:
- $ref: '#/definitions/Pet' # Cat has all properties of a Pet
- properties: # extra properties only for cats
huntingSkill:
type: string
default: lazy
enum:
- lazy
- aggressive
Dog:
allOf:
- $ref: '#/definitions/Pet' # Dog has all properties of a Pet
- properties: # extra properties only for dogs
packSize:
description: The size of the pack the dog is from
type: integer
< /code>
Ich erhalte: < /p>
public class Dog extends Pet { }
< /code>
Wie generiere ich die Vererbung in OpenAPI3?public class Dog extends Pet { }
< /code>
components:
schemas:
Store:
type: object
properties:
pet:
oneOf:
- $ref: "#/components/schemas/Cat"
- $ref: "#/components/schemas/Dog"
discriminator:
propertyName: petType
mapping:
Cat: "#/components/schemas/Cat"
Dog: "#/components/schemas/Dog"
Pet:
discriminator:
propertyName: petType
required:
- name
- petType # required for inheritance to work
properties:
name:
type: string
petType:
type: string
Cat:
allOf:
- $ref: '#/components/schemas/Pet' # Cat has all properties of a Pet
- properties: # extra properties only for cats
huntingSkill:
type: string
default: lazy
enum:
- lazy
- aggressive
Dog:
allOf:
- $ref: '#/components/schemas/Pet' # Dog has all properties of a Pet
- properties: # extra properties only for dogs
packSize:
description: The size of the pack the dog is from
type: integer
openapi: 3.0.3
security: []
servers: []
paths: {}
info:
version: 1.0.0
title: Swagger Petstore
< /code>
With the Dart client, there's a class StorePet
Code: Select all
// java -jar openapi-generator-cli.jar generate -i swagger.yaml -g dart -o ./_swagger
class Store {
StorePet? pet; // Could have been Pet? Or Object?
...
}
class Pet {
String name;
String petType;
...
}
class Dog { // "extends Pet" is missing !!!
...
}
class StorePet {
...
String name;
String petType;
StorePetHuntingSkillEnum huntingSkill;
int? packSize;
...
}
< /code>
With a Java client target and the same specification, it looks a little better...
// java -jar openapi-generator-cli.jar generate -i swagger.yaml -g java -o ./_swagger
public class Store {
public static final String SERIALIZED_NAME_PET = "pet";
@SerializedName(SERIALIZED_NAME_PET)
private StorePet pet; ///