Forum Discussion

lodhi_bhkr's avatar
lodhi_bhkr
Frequent Visitor
2 years ago

Unable to generate Discriminator class as Interface

I want to create an Interface  as abstract (sampleObjectResponse.class) class using this schema and have subclasses as(Object1, Object2 : 

something like : 

public interface SampleObjectResponse {

    String getObjectType();
}


public class Object1 implements SampleObjectResponse {
@SerializedName("objectType")
private String objectType = null;

public Object1 objectType(String objectType) {
this.objectType = objectType;
return this;
}


public class Object2 implements SampleObjectResponse {
@SerializedName("objectType")
private String objectType = null;

public Object2 objectType(String objectType) {
this.objectType = objectType;
return this;
}

 

using schema : 

components:
schemas:
Pet:
type: object
required:
- id
- name
properties:
id:
type: integer
format: int64
name:
type: string
x-constraints: "@Capitalized(required = true)"

sampleObjectResponse:
discriminator:
propertyName: objectType
mapping:
obj1: '#/components/schemas/Object1'
obj2: '#/components/schemas/Object2'
oneOf:
- $ref: '#/components/schemas/Object1'
- $ref: '#/components/schemas/Object2'
Object1:
required:
- objectType
type: object
properties:
objectType:
type: string
Object2:
required:
- objectType
type: object
properties:
objectType:
type: string
No RepliesBe the first to reply