IDRef equivalent in swagger

15 Views Asked by At

I am trying to generate java models from swagger.json. In the legacy project, XSDs were used to generate pojos. Now the xsd_pojos has IDRef property added to the XML element. So when a get action is performed an object is returned. While with swagger I see the property as a String and now IDREF annotation. I understand IDREF is xml related. But my question is how do I fix,

  1. String to an Object of definition.
  2. IDREF equivalent in json.

XML model:

    @XmlElement(name="VehicleRef")
    @XmlIDREF 
    @XmlSchemaType(name="IDREF")
private VehicleID vehicleRef;

public VehicleID getVehicleRef() {
     return vehicleRef;
}

JSON model:

@JsonProperty("VehicleRef")
private String vehicleRef= null;

public Vehicle vehicleRef(String vehicleRef) {
  this.vehicleRef= vehicleRef;
  return this;
}

  public String getVehicleRef() {
  return vehicleRef;
}

Similarly I have issues with IDREFS too..

       @XmlElement(name="BottleRef")
       @XmlIDREF 
       @XmlList 
       @XmlSchemaType(name="IDREFS")
    private List<BottleID> bottleRef;

    public List<BottleID> getBottleRef() {
        if (bottleRef== null) {
            bottleRef= new ArrayList<com.demo.sample.BottleID>();
        }
         return bottleRef;
    }
    

 @JsonProperty("BottleRef")
  @Valid
  private java.util.List<String> bottleRef= null;

  public Receipt addBottleRefItem(String bottleRefItem) {
    if (this.bottleRef == null) {
      this.bottleRef= new java.util.ArrayList<String>();
    }
    this.bottleRef.add(bottleRefItem);
    return this;
  }

Swagger used:
            "VehicleID": {
                "allOf": [
                    {
                        "$ref": "#/components/schemas/Vehicle"
                    },
                    {
                        "properties": {
                            "VehicleRef": {
                                "type": "string",
                                "description": "A pointer to the vehicle id"
                            }
                        }
                    }
                ]
            }
0

There are 0 best solutions below