3

I am generating a JavaClient using an OpenAPISpec document. I have used swagger-codegen 3.0 to generate the code. The OpenAPISpec version is 3.0.1.

Below is the OpenAPI snippet I am facing problems with:

"RequestWithInsuranceInfo": {
        "type": "object",
        "description": "This request schema will produce a response containing an out of pocket estimate for the given service using the patient's insurance information.",
        "additionalProperties": false,
        "properties": {
          "insuranceInfo": {
            "$ref": "#/components/schemas/InsuranceInfo"
          },
          "service": {
            "type": "object",
            "additionalProperties": false,
            "description": "Schema to use when the patient's benefit info is not given in the request.",
            "properties": {
              "codes": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/ServiceCode"
                }
              },
              "provider": {
                "$ref": "#/components/schemas/Provider"
              },
              "costs": {
                "$ref": "#/components/schemas/ServiceCosts"
              }
            },
            "required": [
              "codes",
              "provider",
              "costs"
            ]
          }
        }
      },
"InsuranceInfo": {
        "description": "Information about the payer, plan, and members.",
        "additionalProperties": false,
        "oneOf": [
          {
            "type": "object",
            "additionalProperties": false,
            "title": "Option 1: Patient Is Policy Holder",
            "description": "Schema to use when the patient the primary on the insurance plan.",
            "properties": {
              "payer": {
                "$ref": "#/components/schemas/Payer"
              },
              "policyHolderInfo": {
                "$ref": "#/components/schemas/PolicyHolderInfo"
              }
            },
            "required": [
              "payer",
              "policyHolderInfo"
            ]
          },
          {
            "type": "object",
            "additionalProperties": false,
            "title": "Option 2: Patient Is Dependent",
            "description": "Schema to use when the patient is a dependent on the insurance plan.",
            "properties": {
              "payer": {
                "$ref": "#/components/schemas/Payer"
              },
              "dependentMemberInfo": {
                "$ref": "#/components/schemas/DependentMemberInfo"
              },
              "policyHolderInfo": {
                "$ref": "#/components/schemas/PolicyHolderInfo"
              }
            },
            "required": [
              "payer",
              "dependentMemberInfo",
              "policyHolderInfo"
            ]
          }
        ]
      },

Below is the code which gets generated:

public class InsuranceInfo implements OneOfInsuranceInfo {

  @Override
  public boolean equals(java.lang.Object o) {..}

  @Override
  public int hashCode() {..}

  @Override
  public String toString() {..}

  private String toIndentedString(java.lang.Object o) {..}
}


public interface OneOfInsuranceInfo {

}


public class RequestWithInsuranceInfo implements OneOfRequest {
  @SerializedName("insuranceInfo")
  private InsuranceInfo insuranceInfo = null;

  @SerializedName("service")
  private RequestWithInsuranceInfoService service = null;
 ..

}

public class Payer {
  @SerializedName("id")
  private String id = null;
  
  ..
}

public class PolicyHolderInfo {
  @SerializedName("memberId")
  private String memberId = null;

  @SerializedName("firstName")
  private String firstName = null;

  @SerializedName("lastName")
  private String lastName = null;

  @SerializedName("dateOfBirth")
  private LocalDate dateOfBirth = null;

  ..
}

public class DependentMemberInfo {
  @SerializedName("memberId")
  private String memberId = null;

  @SerializedName("firstName")
  private String firstName = null;

  @SerializedName("lastName")
  private String lastName = null;

  @SerializedName("dateOfBirth")
  private LocalDate dateOfBirth = null;

  ..

}

As shown, the InsuranceInfo object implements the OneOfInsuranceInfo interface but has no variables. Payer, PolicyHolderInfo and dependentMemberInfo class are generated but they are not linked to the InsuranceInfo class anyhow. How do I populate the InsuranceInfo class?

Ayushi Puri
  • 31
  • 1
  • 2

1 Answers1

1

The issue is probably that the InsuranceInfo schema

"InsuranceInfo": {
  "description": "Information about the payer, plan, and members.",

  "additionalProperties": false,
  "oneOf": [
    { ... },
    { ... }
  ]
}

effectively disallows ALL properties. This is because additionalProperties: false only knows about the properties defined directly alongside it and has no visibility into oneOf subschemas.


To resolve the issue, you can rewrite the InsuranceInfo schema without oneOf, as follows. This schema is basically "Option 2" from the original schema, except the dependentMemberInfo property is defined as optional.

"InsuranceInfo": {
  "description": "Information about the payer, plan, and members.",
  "additionalProperties": false,
  "type": "object",
  "required": [
    "payer",
    "policyHolderInfo"
  ],
  "properties": {
    "payer": {
      "$ref": "#/components/schemas/Payer"
    },
    "dependentMemberInfo": {
      "$ref": "#/components/schemas/DependentMemberInfo"
    },
    "policyHolderInfo": {
      "$ref": "#/components/schemas/PolicyHolderInfo"
    }
  }
}
Helen
  • 87,344
  • 17
  • 243
  • 314