fix(swift3): multi-level inheritance support

Supports multi-level inheritance to avoid having the variables from
the parents of level > 2

This commit also fixes the comparison of the variables when skipping
the variables in the children classes by only comparing their names
(in some cases some parent variables were present in children classes)

Signed-off-by: Vincent Giersch <vincent@giersch.fr>
This commit is contained in:
Vincent Giersch 2016-11-16 18:49:16 +01:00
parent 88227e08e3
commit bd06a629c6
5 changed files with 142 additions and 134 deletions

View File

@ -427,10 +427,18 @@ public class Swift3Codegen extends DefaultCodegen implements CodegenConfig {
if(codegenModel.description != null) { if(codegenModel.description != null) {
codegenModel.imports.add("ApiModel"); codegenModel.imports.add("ApiModel");
} }
if (allDefinitions != null && codegenModel.parentSchema != null) { if (allDefinitions != null) {
final Model parentModel = allDefinitions.get(codegenModel.parentSchema); String parentSchema = codegenModel.parentSchema;
final CodegenModel parentCodegenModel = super.fromModel(codegenModel.parent, parentModel);
// multilevel inheritance: reconcile properties of all the parents
while (parentSchema != null) {
final Model parentModel = allDefinitions.get(parentSchema);
final CodegenModel parentCodegenModel = super.fromModel(codegenModel.parent, parentModel, allDefinitions);
codegenModel = Swift3Codegen.reconcileProperties(codegenModel, parentCodegenModel); codegenModel = Swift3Codegen.reconcileProperties(codegenModel, parentCodegenModel);
// get the next parent
parentSchema = parentCodegenModel.parentSchema;
}
} }
return codegenModel; return codegenModel;
@ -582,7 +590,7 @@ public class Swift3Codegen extends DefaultCodegen implements CodegenConfig {
Iterator<CodegenProperty> iterator = codegenProperties.iterator(); Iterator<CodegenProperty> iterator = codegenProperties.iterator();
while (iterator.hasNext()) { while (iterator.hasNext()) {
CodegenProperty codegenProperty = iterator.next(); CodegenProperty codegenProperty = iterator.next();
if (codegenProperty.equals(parentModelCodegenProperty)) { if (codegenProperty.baseName == parentModelCodegenProperty.baseName) {
// We found a property in the child class that is // We found a property in the child class that is
// a duplicate of the one in the parent, so remove it. // a duplicate of the one in the parent, so remove it.
iterator.remove(); iterator.remove();

View File

@ -26,9 +26,9 @@ open class FakeAPI: APIBase {
/** /**
To test \"client\" model To test \"client\" model
- PATCH /fake - PATCH /fake
- examples: [{example={ - examples: [{contentType=application/json, example={
"client" : "aeiou" "client" : "aeiou"
}, contentType=application/json}] }}]
- parameter body: (body) client model - parameter body: (body) client model

View File

@ -117,7 +117,7 @@ open class PetAPI: APIBase {
- OAuth: - OAuth:
- type: oauth2 - type: oauth2
- name: petstore_auth - name: petstore_auth
- examples: [{example=<Pet> - examples: [{contentType=application/xml, example=<Pet>
<id>123456</id> <id>123456</id>
<name>doggie</name> <name>doggie</name>
<photoUrls> <photoUrls>
@ -126,21 +126,21 @@ open class PetAPI: APIBase {
<tags> <tags>
</tags> </tags>
<status>string</status> <status>string</status>
</Pet>, contentType=application/xml}, {example=[ { </Pet>}, {contentType=application/json, example=[ {
"tags" : [ { "photoUrls" : [ "aeiou" ],
"id" : 123456789, "name" : "doggie",
"name" : "aeiou"
} ],
"id" : 123456789, "id" : 123456789,
"category" : { "category" : {
"id" : 123456789, "name" : "aeiou",
"name" : "aeiou" "id" : 123456789
}, },
"status" : "aeiou", "tags" : [ {
"name" : "doggie", "name" : "aeiou",
"photoUrls" : [ "aeiou" ] "id" : 123456789
} ], contentType=application/json}] } ],
- examples: [{example=<Pet> "status" : "aeiou"
} ]}]
- examples: [{contentType=application/xml, example=<Pet>
<id>123456</id> <id>123456</id>
<name>doggie</name> <name>doggie</name>
<photoUrls> <photoUrls>
@ -149,20 +149,20 @@ open class PetAPI: APIBase {
<tags> <tags>
</tags> </tags>
<status>string</status> <status>string</status>
</Pet>, contentType=application/xml}, {example=[ { </Pet>}, {contentType=application/json, example=[ {
"tags" : [ { "photoUrls" : [ "aeiou" ],
"id" : 123456789, "name" : "doggie",
"name" : "aeiou"
} ],
"id" : 123456789, "id" : 123456789,
"category" : { "category" : {
"id" : 123456789, "name" : "aeiou",
"name" : "aeiou" "id" : 123456789
}, },
"status" : "aeiou", "tags" : [ {
"name" : "doggie", "name" : "aeiou",
"photoUrls" : [ "aeiou" ] "id" : 123456789
} ], contentType=application/json}] } ],
"status" : "aeiou"
} ]}]
- parameter status: (query) Status values that need to be considered for filter - parameter status: (query) Status values that need to be considered for filter
@ -205,7 +205,7 @@ open class PetAPI: APIBase {
- OAuth: - OAuth:
- type: oauth2 - type: oauth2
- name: petstore_auth - name: petstore_auth
- examples: [{example=<Pet> - examples: [{contentType=application/xml, example=<Pet>
<id>123456</id> <id>123456</id>
<name>doggie</name> <name>doggie</name>
<photoUrls> <photoUrls>
@ -214,21 +214,21 @@ open class PetAPI: APIBase {
<tags> <tags>
</tags> </tags>
<status>string</status> <status>string</status>
</Pet>, contentType=application/xml}, {example=[ { </Pet>}, {contentType=application/json, example=[ {
"tags" : [ { "photoUrls" : [ "aeiou" ],
"id" : 123456789, "name" : "doggie",
"name" : "aeiou"
} ],
"id" : 123456789, "id" : 123456789,
"category" : { "category" : {
"id" : 123456789, "name" : "aeiou",
"name" : "aeiou" "id" : 123456789
}, },
"status" : "aeiou", "tags" : [ {
"name" : "doggie", "name" : "aeiou",
"photoUrls" : [ "aeiou" ] "id" : 123456789
} ], contentType=application/json}] } ],
- examples: [{example=<Pet> "status" : "aeiou"
} ]}]
- examples: [{contentType=application/xml, example=<Pet>
<id>123456</id> <id>123456</id>
<name>doggie</name> <name>doggie</name>
<photoUrls> <photoUrls>
@ -237,20 +237,20 @@ open class PetAPI: APIBase {
<tags> <tags>
</tags> </tags>
<status>string</status> <status>string</status>
</Pet>, contentType=application/xml}, {example=[ { </Pet>}, {contentType=application/json, example=[ {
"tags" : [ { "photoUrls" : [ "aeiou" ],
"id" : 123456789, "name" : "doggie",
"name" : "aeiou"
} ],
"id" : 123456789, "id" : 123456789,
"category" : { "category" : {
"id" : 123456789, "name" : "aeiou",
"name" : "aeiou" "id" : 123456789
}, },
"status" : "aeiou", "tags" : [ {
"name" : "doggie", "name" : "aeiou",
"photoUrls" : [ "aeiou" ] "id" : 123456789
} ], contentType=application/json}] } ],
"status" : "aeiou"
} ]}]
- parameter tags: (query) Tags to filter by - parameter tags: (query) Tags to filter by
@ -293,7 +293,7 @@ open class PetAPI: APIBase {
- API Key: - API Key:
- type: apiKey api_key - type: apiKey api_key
- name: api_key - name: api_key
- examples: [{example=<Pet> - examples: [{contentType=application/xml, example=<Pet>
<id>123456</id> <id>123456</id>
<name>doggie</name> <name>doggie</name>
<photoUrls> <photoUrls>
@ -302,21 +302,21 @@ open class PetAPI: APIBase {
<tags> <tags>
</tags> </tags>
<status>string</status> <status>string</status>
</Pet>, contentType=application/xml}, {example={ </Pet>}, {contentType=application/json, example={
"tags" : [ { "photoUrls" : [ "aeiou" ],
"id" : 123456789, "name" : "doggie",
"name" : "aeiou"
} ],
"id" : 123456789, "id" : 123456789,
"category" : { "category" : {
"id" : 123456789, "name" : "aeiou",
"name" : "aeiou" "id" : 123456789
}, },
"status" : "aeiou", "tags" : [ {
"name" : "doggie", "name" : "aeiou",
"photoUrls" : [ "aeiou" ] "id" : 123456789
}, contentType=application/json}] } ],
- examples: [{example=<Pet> "status" : "aeiou"
}}]
- examples: [{contentType=application/xml, example=<Pet>
<id>123456</id> <id>123456</id>
<name>doggie</name> <name>doggie</name>
<photoUrls> <photoUrls>
@ -325,20 +325,20 @@ open class PetAPI: APIBase {
<tags> <tags>
</tags> </tags>
<status>string</status> <status>string</status>
</Pet>, contentType=application/xml}, {example={ </Pet>}, {contentType=application/json, example={
"tags" : [ { "photoUrls" : [ "aeiou" ],
"id" : 123456789, "name" : "doggie",
"name" : "aeiou"
} ],
"id" : 123456789, "id" : 123456789,
"category" : { "category" : {
"id" : 123456789, "name" : "aeiou",
"name" : "aeiou" "id" : 123456789
}, },
"status" : "aeiou", "tags" : [ {
"name" : "doggie", "name" : "aeiou",
"photoUrls" : [ "aeiou" ] "id" : 123456789
}, contentType=application/json}] } ],
"status" : "aeiou"
}}]
- parameter petId: (path) ID of pet to return - parameter petId: (path) ID of pet to return
@ -467,11 +467,11 @@ open class PetAPI: APIBase {
- OAuth: - OAuth:
- type: oauth2 - type: oauth2
- name: petstore_auth - name: petstore_auth
- examples: [{example={ - examples: [{contentType=application/json, example={
"message" : "aeiou",
"code" : 123, "code" : 123,
"type" : "aeiou" "type" : "aeiou",
}, contentType=application/json}] "message" : "aeiou"
}}]
- parameter petId: (path) ID of pet to update - parameter petId: (path) ID of pet to update
- parameter additionalMetadata: (form) Additional data to pass to server (optional) - parameter additionalMetadata: (form) Additional data to pass to server (optional)

View File

@ -67,9 +67,9 @@ open class StoreAPI: APIBase {
- API Key: - API Key:
- type: apiKey api_key - type: apiKey api_key
- name: api_key - name: api_key
- examples: [{example={ - examples: [{contentType=application/json, example={
"key" : 123 "key" : 123
}, contentType=application/json}] }}]
- returns: RequestBuilder<[String:Int32]> - returns: RequestBuilder<[String:Int32]>
*/ */
@ -105,36 +105,36 @@ open class StoreAPI: APIBase {
Find purchase order by ID Find purchase order by ID
- GET /store/order/{orderId} - GET /store/order/{orderId}
- For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions - For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions
- examples: [{example=<Order> - examples: [{contentType=application/xml, example=<Order>
<id>123456</id> <id>123456</id>
<petId>123456</petId> <petId>123456</petId>
<quantity>0</quantity> <quantity>0</quantity>
<shipDate>2000-01-23T04:56:07.000Z</shipDate> <shipDate>2000-01-23T04:56:07.000Z</shipDate>
<status>string</status> <status>string</status>
<complete>true</complete> <complete>true</complete>
</Order>, contentType=application/xml}, {example={ </Order>}, {contentType=application/json, example={
"id" : 123456789,
"petId" : 123456789, "petId" : 123456789,
"complete" : true,
"status" : "aeiou",
"quantity" : 123, "quantity" : 123,
"shipDate" : "2000-01-23T04:56:07.000+00:00" "id" : 123456789,
}, contentType=application/json}] "shipDate" : "2000-01-23T04:56:07.000+00:00",
- examples: [{example=<Order> "complete" : true,
"status" : "aeiou"
}}]
- examples: [{contentType=application/xml, example=<Order>
<id>123456</id> <id>123456</id>
<petId>123456</petId> <petId>123456</petId>
<quantity>0</quantity> <quantity>0</quantity>
<shipDate>2000-01-23T04:56:07.000Z</shipDate> <shipDate>2000-01-23T04:56:07.000Z</shipDate>
<status>string</status> <status>string</status>
<complete>true</complete> <complete>true</complete>
</Order>, contentType=application/xml}, {example={ </Order>}, {contentType=application/json, example={
"id" : 123456789,
"petId" : 123456789, "petId" : 123456789,
"complete" : true,
"status" : "aeiou",
"quantity" : 123, "quantity" : 123,
"shipDate" : "2000-01-23T04:56:07.000+00:00" "id" : 123456789,
}, contentType=application/json}] "shipDate" : "2000-01-23T04:56:07.000+00:00",
"complete" : true,
"status" : "aeiou"
}}]
- parameter orderId: (path) ID of pet that needs to be fetched - parameter orderId: (path) ID of pet that needs to be fetched
@ -173,36 +173,36 @@ open class StoreAPI: APIBase {
Place an order for a pet Place an order for a pet
- POST /store/order - POST /store/order
- -
- examples: [{example=<Order> - examples: [{contentType=application/xml, example=<Order>
<id>123456</id> <id>123456</id>
<petId>123456</petId> <petId>123456</petId>
<quantity>0</quantity> <quantity>0</quantity>
<shipDate>2000-01-23T04:56:07.000Z</shipDate> <shipDate>2000-01-23T04:56:07.000Z</shipDate>
<status>string</status> <status>string</status>
<complete>true</complete> <complete>true</complete>
</Order>, contentType=application/xml}, {example={ </Order>}, {contentType=application/json, example={
"id" : 123456789,
"petId" : 123456789, "petId" : 123456789,
"complete" : true,
"status" : "aeiou",
"quantity" : 123, "quantity" : 123,
"shipDate" : "2000-01-23T04:56:07.000+00:00" "id" : 123456789,
}, contentType=application/json}] "shipDate" : "2000-01-23T04:56:07.000+00:00",
- examples: [{example=<Order> "complete" : true,
"status" : "aeiou"
}}]
- examples: [{contentType=application/xml, example=<Order>
<id>123456</id> <id>123456</id>
<petId>123456</petId> <petId>123456</petId>
<quantity>0</quantity> <quantity>0</quantity>
<shipDate>2000-01-23T04:56:07.000Z</shipDate> <shipDate>2000-01-23T04:56:07.000Z</shipDate>
<status>string</status> <status>string</status>
<complete>true</complete> <complete>true</complete>
</Order>, contentType=application/xml}, {example={ </Order>}, {contentType=application/json, example={
"id" : 123456789,
"petId" : 123456789, "petId" : 123456789,
"complete" : true,
"status" : "aeiou",
"quantity" : 123, "quantity" : 123,
"shipDate" : "2000-01-23T04:56:07.000+00:00" "id" : 123456789,
}, contentType=application/json}] "shipDate" : "2000-01-23T04:56:07.000+00:00",
"complete" : true,
"status" : "aeiou"
}}]
- parameter body: (body) order placed for purchasing the pet - parameter body: (body) order placed for purchasing the pet

View File

@ -167,7 +167,7 @@ open class UserAPI: APIBase {
Get user by user name Get user by user name
- GET /user/{username} - GET /user/{username}
- -
- examples: [{example=<User> - examples: [{contentType=application/xml, example=<User>
<id>123456</id> <id>123456</id>
<username>string</username> <username>string</username>
<firstName>string</firstName> <firstName>string</firstName>
@ -176,17 +176,17 @@ open class UserAPI: APIBase {
<password>string</password> <password>string</password>
<phone>string</phone> <phone>string</phone>
<userStatus>0</userStatus> <userStatus>0</userStatus>
</User>, contentType=application/xml}, {example={ </User>}, {contentType=application/json, example={
"id" : 123456789,
"lastName" : "aeiou",
"phone" : "aeiou",
"username" : "aeiou",
"email" : "aeiou",
"userStatus" : 123,
"firstName" : "aeiou", "firstName" : "aeiou",
"password" : "aeiou" "lastName" : "aeiou",
}, contentType=application/json}] "password" : "aeiou",
- examples: [{example=<User> "userStatus" : 123,
"phone" : "aeiou",
"id" : 123456789,
"email" : "aeiou",
"username" : "aeiou"
}}]
- examples: [{contentType=application/xml, example=<User>
<id>123456</id> <id>123456</id>
<username>string</username> <username>string</username>
<firstName>string</firstName> <firstName>string</firstName>
@ -195,16 +195,16 @@ open class UserAPI: APIBase {
<password>string</password> <password>string</password>
<phone>string</phone> <phone>string</phone>
<userStatus>0</userStatus> <userStatus>0</userStatus>
</User>, contentType=application/xml}, {example={ </User>}, {contentType=application/json, example={
"id" : 123456789,
"lastName" : "aeiou",
"phone" : "aeiou",
"username" : "aeiou",
"email" : "aeiou",
"userStatus" : 123,
"firstName" : "aeiou", "firstName" : "aeiou",
"password" : "aeiou" "lastName" : "aeiou",
}, contentType=application/json}] "password" : "aeiou",
"userStatus" : 123,
"phone" : "aeiou",
"id" : 123456789,
"email" : "aeiou",
"username" : "aeiou"
}}]
- parameter username: (path) The name that needs to be fetched. Use user1 for testing. - parameter username: (path) The name that needs to be fetched. Use user1 for testing.
@ -246,8 +246,8 @@ open class UserAPI: APIBase {
- -
- responseHeaders: [X-Rate-Limit(Int32), X-Expires-After(Date)] - responseHeaders: [X-Rate-Limit(Int32), X-Expires-After(Date)]
- responseHeaders: [X-Rate-Limit(Int32), X-Expires-After(Date)] - responseHeaders: [X-Rate-Limit(Int32), X-Expires-After(Date)]
- examples: [{example=string, contentType=application/xml}, {example="aeiou", contentType=application/json}] - examples: [{contentType=application/xml, example=string}, {contentType=application/json, example="aeiou"}]
- examples: [{example=string, contentType=application/xml}, {example="aeiou", contentType=application/json}] - examples: [{contentType=application/xml, example=string}, {contentType=application/json, example="aeiou"}]
- parameter username: (query) The user name for login - parameter username: (query) The user name for login
- parameter password: (query) The password for login in clear text - parameter password: (query) The password for login in clear text