Skip to content

Model definitions with allOf #2486

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
ivanignatiev opened this issue Apr 1, 2016 · 0 comments
Open

Model definitions with allOf #2486

ivanignatiev opened this issue Apr 1, 2016 · 0 comments

Comments

@ivanignatiev
Copy link

It's seems that model compositions in Swagger CodeGen doe not work well.

For example, we can take a model from https://github.com/Azure/azure-rest-api-specs/blob/master/arm-network/2016-03-30/swagger/network.json :

"ApplicationGatewayIPConfiguration": {
      "properties": {
        "properties": {
          "x-ms-client-flatten": true,
          "$ref": "#/definitions/ApplicationGatewayIPConfigurationPropertiesFormat"
        },
        "name": {
          "type": "string",
          "description": "Gets name of the resource that is unique within a resource group. This name can be used to access the resource"
        },
        "etag": {
          "type": "string",
          "description": "A unique read-only string that changes whenever the resource is updated"
        }
      },
      "allOf": [
        {
          "$ref": "#/definitions/SubResource"
        }
      ],
      "description": "IP configuration of application gateway"
    }

Swagger CodeGen will generate following incorrect code for Java :

@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2016-04-01T18:37:32.629+02:00")
public class ApplicationGatewayIPConfiguration extends SubResource  {

  private String id = null;

  /**
   * Resource Id
   **/

  @ApiModelProperty(value = "Resource Id")
  @JsonProperty("id")
  public String getId() {
    return id;
  }
  public void setId(String id) {
    this.id = id;
  }

/// Methodes 
/// ...

And if we will use model definition below :

     "ApplicationGatewayIPConfiguration": {
            "allOf": [{
                "$ref": "#/definitions/SubResource"
            },
            {
                "type": "object",
                "properties": {
                    "properties": {
                        "$ref": "#/definitions/ApplicationGatewayIPConfigurationPropertiesFormat"
                    },
                    "name": {
                        "type": "string",
                        "description": "Gets name of the resource that is unique within a resource group. This name can be used to access the resource"
                    },
                    "etag": {
                        "type": "string",
                        "description": "A unique read-only string that changes whenever the resource is updated"
                    }
                }
            }],
            "description": "IP configuration of application gateway"
        }

We will get the expected result :

@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2016-04-01T18:40:11.781+02:00")
public class ApplicationGatewayIPConfiguration extends SubResource  {

  private String name = null;
  private String etag = null;
  private String id = null;
  private ApplicationGatewayIPConfigurationPropertiesFormat properties = null;


  /**
   * Gets name of the resource that is unique within a resource group. This name can be used to access the resource
   **/

  @ApiModelProperty(value = "Gets name of the resource that is unique within a resource group. This name can be used to access the resource")
  @JsonProperty("name")
  public String getName() {
    return name;
  }
  public void setName(String name) {
    this.name = name;
  }

I have opened an issue in OpenAPI-Specification repository as well to get more information #OAI/OpenAPI-Specification#619

@ivanignatiev ivanignatiev changed the title Question, Specification Ambiguity: Using of "allOf: []" Model definitions with allOf Apr 4, 2016
@wing328 wing328 added this to the Future milestone Apr 6, 2016
@wing328 wing328 modified the milestones: Future, v2.3.0 Jul 7, 2016
@wing328 wing328 modified the milestones: v2.2.1, v2.2.2 Aug 8, 2016
@wing328 wing328 modified the milestones: v2.2.2, v2.2.3 Feb 22, 2017
@wing328 wing328 modified the milestones: v2.2.3, v2.3.0 Jul 16, 2017
@wing328 wing328 modified the milestones: v2.3.0, v2.4.0 Dec 15, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants