forked from loafle/openapi-generator-original
Merge branch 'enum' of https://github.com/cjolif/swagger-codegen into cjolif-enum
This commit is contained in:
commit
e0ce491b44
@ -355,8 +355,8 @@ public class SwiftCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
if (value.matches("[A-Z][a-z0-9]+[a-zA-Z0-9]*")) {
|
||||
return value;
|
||||
}
|
||||
char[] separators = {'-', '_', ' '};
|
||||
return WordUtils.capitalizeFully(StringUtils.lowerCase(value), separators).replaceAll("[-_ ]", "");
|
||||
char[] separators = {'-', '_', ' ', ':'};
|
||||
return WordUtils.capitalizeFully(StringUtils.lowerCase(value), separators).replaceAll("[-_ :]", "");
|
||||
}
|
||||
|
||||
|
||||
@ -502,6 +502,7 @@ public class SwiftCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
@Override
|
||||
public String toEnumVarName(String name, String datatype) {
|
||||
// TODO: this code is probably useless, because the var name is computed from the value in map.put("enum", toSwiftyEnumName(value));
|
||||
// number
|
||||
if ("int".equals(datatype) || "double".equals(datatype) || "float".equals(datatype)) {
|
||||
String varName = new String(name);
|
||||
@ -525,8 +526,9 @@ public class SwiftCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
@Override
|
||||
public String toEnumName(CodegenProperty property) {
|
||||
String enumName = underscore(toModelName(property.name)).toUpperCase();
|
||||
String enumName = toModelName(property.name);
|
||||
|
||||
// TODO: toModelName already does something for names starting with number, so this code is probably never called
|
||||
if (enumName.matches("\\d.*")) { // starts with number
|
||||
return "_" + enumName;
|
||||
} else {
|
||||
|
@ -155,13 +155,13 @@ public class PetAPI: APIBase {
|
||||
- OAuth:
|
||||
- type: oauth2
|
||||
- name: petstore_auth
|
||||
- examples: [{example={
|
||||
- examples: [{contentType=application/json, example={
|
||||
"name" : "Puma",
|
||||
"type" : "Dog",
|
||||
"color" : "Black",
|
||||
"gender" : "Female",
|
||||
"breed" : "Mixed"
|
||||
}, contentType=application/json}]
|
||||
}}]
|
||||
|
||||
- parameter status: (query) Status values that need to be considered for filter (optional, default to available)
|
||||
|
||||
@ -218,20 +218,20 @@ public class PetAPI: APIBase {
|
||||
- OAuth:
|
||||
- type: oauth2
|
||||
- name: petstore_auth
|
||||
- examples: [{example=[ {
|
||||
"tags" : [ {
|
||||
"id" : 123456789,
|
||||
"name" : "aeiou"
|
||||
} ],
|
||||
- examples: [{contentType=application/json, example=[ {
|
||||
"photoUrls" : [ "aeiou" ],
|
||||
"name" : "doggie",
|
||||
"id" : 123456789,
|
||||
"category" : {
|
||||
"id" : 123456789,
|
||||
"name" : "aeiou"
|
||||
"name" : "aeiou",
|
||||
"id" : 123456789
|
||||
},
|
||||
"status" : "aeiou",
|
||||
"name" : "doggie",
|
||||
"photoUrls" : [ "aeiou" ]
|
||||
} ], contentType=application/json}, {example=<Pet>
|
||||
"tags" : [ {
|
||||
"name" : "aeiou",
|
||||
"id" : 123456789
|
||||
} ],
|
||||
"status" : "aeiou"
|
||||
} ]}, {contentType=application/xml, example=<Pet>
|
||||
<id>123456</id>
|
||||
<name>doggie</name>
|
||||
<photoUrls>
|
||||
@ -240,21 +240,21 @@ public class PetAPI: APIBase {
|
||||
<tags>
|
||||
</tags>
|
||||
<status>string</status>
|
||||
</Pet>, contentType=application/xml}]
|
||||
- examples: [{example=[ {
|
||||
"tags" : [ {
|
||||
"id" : 123456789,
|
||||
"name" : "aeiou"
|
||||
} ],
|
||||
</Pet>}]
|
||||
- examples: [{contentType=application/json, example=[ {
|
||||
"photoUrls" : [ "aeiou" ],
|
||||
"name" : "doggie",
|
||||
"id" : 123456789,
|
||||
"category" : {
|
||||
"id" : 123456789,
|
||||
"name" : "aeiou"
|
||||
"name" : "aeiou",
|
||||
"id" : 123456789
|
||||
},
|
||||
"status" : "aeiou",
|
||||
"name" : "doggie",
|
||||
"photoUrls" : [ "aeiou" ]
|
||||
} ], contentType=application/json}, {example=<Pet>
|
||||
"tags" : [ {
|
||||
"name" : "aeiou",
|
||||
"id" : 123456789
|
||||
} ],
|
||||
"status" : "aeiou"
|
||||
} ]}, {contentType=application/xml, example=<Pet>
|
||||
<id>123456</id>
|
||||
<name>doggie</name>
|
||||
<photoUrls>
|
||||
@ -263,7 +263,7 @@ public class PetAPI: APIBase {
|
||||
<tags>
|
||||
</tags>
|
||||
<status>string</status>
|
||||
</Pet>, contentType=application/xml}]
|
||||
</Pet>}]
|
||||
|
||||
- parameter tags: (query) Tags to filter by (optional)
|
||||
|
||||
@ -317,26 +317,26 @@ public class PetAPI: APIBase {
|
||||
Find pet by ID
|
||||
- GET /pet/{petId}
|
||||
- Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions
|
||||
- API Key:
|
||||
- type: apiKey api_key
|
||||
- name: api_key
|
||||
- OAuth:
|
||||
- type: oauth2
|
||||
- name: petstore_auth
|
||||
- examples: [{example={
|
||||
"tags" : [ {
|
||||
"id" : 123456789,
|
||||
"name" : "aeiou"
|
||||
} ],
|
||||
- API Key:
|
||||
- type: apiKey api_key
|
||||
- name: api_key
|
||||
- examples: [{contentType=application/json, example={
|
||||
"photoUrls" : [ "aeiou" ],
|
||||
"name" : "doggie",
|
||||
"id" : 123456789,
|
||||
"category" : {
|
||||
"id" : 123456789,
|
||||
"name" : "aeiou"
|
||||
"name" : "aeiou",
|
||||
"id" : 123456789
|
||||
},
|
||||
"status" : "aeiou",
|
||||
"name" : "doggie",
|
||||
"photoUrls" : [ "aeiou" ]
|
||||
}, contentType=application/json}, {example=<Pet>
|
||||
"tags" : [ {
|
||||
"name" : "aeiou",
|
||||
"id" : 123456789
|
||||
} ],
|
||||
"status" : "aeiou"
|
||||
}}, {contentType=application/xml, example=<Pet>
|
||||
<id>123456</id>
|
||||
<name>doggie</name>
|
||||
<photoUrls>
|
||||
@ -345,21 +345,21 @@ public class PetAPI: APIBase {
|
||||
<tags>
|
||||
</tags>
|
||||
<status>string</status>
|
||||
</Pet>, contentType=application/xml}]
|
||||
- examples: [{example={
|
||||
"tags" : [ {
|
||||
"id" : 123456789,
|
||||
"name" : "aeiou"
|
||||
} ],
|
||||
</Pet>}]
|
||||
- examples: [{contentType=application/json, example={
|
||||
"photoUrls" : [ "aeiou" ],
|
||||
"name" : "doggie",
|
||||
"id" : 123456789,
|
||||
"category" : {
|
||||
"id" : 123456789,
|
||||
"name" : "aeiou"
|
||||
"name" : "aeiou",
|
||||
"id" : 123456789
|
||||
},
|
||||
"status" : "aeiou",
|
||||
"name" : "doggie",
|
||||
"photoUrls" : [ "aeiou" ]
|
||||
}, contentType=application/json}, {example=<Pet>
|
||||
"tags" : [ {
|
||||
"name" : "aeiou",
|
||||
"id" : 123456789
|
||||
} ],
|
||||
"status" : "aeiou"
|
||||
}}, {contentType=application/xml, example=<Pet>
|
||||
<id>123456</id>
|
||||
<name>doggie</name>
|
||||
<photoUrls>
|
||||
@ -368,7 +368,7 @@ public class PetAPI: APIBase {
|
||||
<tags>
|
||||
</tags>
|
||||
<status>string</status>
|
||||
</Pet>, contentType=application/xml}]
|
||||
</Pet>}]
|
||||
|
||||
- parameter petId: (path) ID of pet that needs to be fetched
|
||||
|
||||
|
@ -98,12 +98,12 @@ public class StoreAPI: APIBase {
|
||||
- API Key:
|
||||
- type: apiKey api_key
|
||||
- name: api_key
|
||||
- examples: [{example={
|
||||
- examples: [{contentType=application/json, example={
|
||||
"key" : 123
|
||||
}, contentType=application/json}, {example=not implemented io.swagger.models.properties.MapProperty@d1e580af, contentType=application/xml}]
|
||||
- examples: [{example={
|
||||
}}, {contentType=application/xml, example=not implemented io.swagger.models.properties.MapProperty@d1e580af}]
|
||||
- examples: [{contentType=application/json, example={
|
||||
"key" : 123
|
||||
}, contentType=application/json}, {example=not implemented io.swagger.models.properties.MapProperty@d1e580af, contentType=application/xml}]
|
||||
}}, {contentType=application/xml, example=not implemented io.swagger.models.properties.MapProperty@d1e580af}]
|
||||
|
||||
- returns: RequestBuilder<[String:Int32]>
|
||||
*/
|
||||
@ -153,36 +153,36 @@ public class StoreAPI: APIBase {
|
||||
Find purchase order by ID
|
||||
- GET /store/order/{orderId}
|
||||
- For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions
|
||||
- examples: [{example={
|
||||
"id" : 123456789,
|
||||
- examples: [{contentType=application/json, example={
|
||||
"petId" : 123456789,
|
||||
"complete" : true,
|
||||
"status" : "aeiou",
|
||||
"quantity" : 123,
|
||||
"shipDate" : "2000-01-23T04:56:07.000+0000"
|
||||
}, contentType=application/json}, {example=<Order>
|
||||
"id" : 123456789,
|
||||
"shipDate" : "2000-01-23T04:56:07.000+0000",
|
||||
"complete" : true,
|
||||
"status" : "aeiou"
|
||||
}}, {contentType=application/xml, example=<Order>
|
||||
<id>123456</id>
|
||||
<petId>123456</petId>
|
||||
<quantity>0</quantity>
|
||||
<shipDate>2000-01-23T04:56:07.000Z</shipDate>
|
||||
<status>string</status>
|
||||
<complete>true</complete>
|
||||
</Order>, contentType=application/xml}]
|
||||
- examples: [{example={
|
||||
"id" : 123456789,
|
||||
</Order>}]
|
||||
- examples: [{contentType=application/json, example={
|
||||
"petId" : 123456789,
|
||||
"complete" : true,
|
||||
"status" : "aeiou",
|
||||
"quantity" : 123,
|
||||
"shipDate" : "2000-01-23T04:56:07.000+0000"
|
||||
}, contentType=application/json}, {example=<Order>
|
||||
"id" : 123456789,
|
||||
"shipDate" : "2000-01-23T04:56:07.000+0000",
|
||||
"complete" : true,
|
||||
"status" : "aeiou"
|
||||
}}, {contentType=application/xml, example=<Order>
|
||||
<id>123456</id>
|
||||
<petId>123456</petId>
|
||||
<quantity>0</quantity>
|
||||
<shipDate>2000-01-23T04:56:07.000Z</shipDate>
|
||||
<status>string</status>
|
||||
<complete>true</complete>
|
||||
</Order>, contentType=application/xml}]
|
||||
</Order>}]
|
||||
|
||||
- parameter orderId: (path) ID of pet that needs to be fetched
|
||||
|
||||
@ -235,36 +235,36 @@ public class StoreAPI: APIBase {
|
||||
Place an order for a pet
|
||||
- POST /store/order
|
||||
-
|
||||
- examples: [{example={
|
||||
"id" : 123456789,
|
||||
- examples: [{contentType=application/json, example={
|
||||
"petId" : 123456789,
|
||||
"complete" : true,
|
||||
"status" : "aeiou",
|
||||
"quantity" : 123,
|
||||
"shipDate" : "2000-01-23T04:56:07.000+0000"
|
||||
}, contentType=application/json}, {example=<Order>
|
||||
"id" : 123456789,
|
||||
"shipDate" : "2000-01-23T04:56:07.000+0000",
|
||||
"complete" : true,
|
||||
"status" : "aeiou"
|
||||
}}, {contentType=application/xml, example=<Order>
|
||||
<id>123456</id>
|
||||
<petId>123456</petId>
|
||||
<quantity>0</quantity>
|
||||
<shipDate>2000-01-23T04:56:07.000Z</shipDate>
|
||||
<status>string</status>
|
||||
<complete>true</complete>
|
||||
</Order>, contentType=application/xml}]
|
||||
- examples: [{example={
|
||||
"id" : 123456789,
|
||||
</Order>}]
|
||||
- examples: [{contentType=application/json, example={
|
||||
"petId" : 123456789,
|
||||
"complete" : true,
|
||||
"status" : "aeiou",
|
||||
"quantity" : 123,
|
||||
"shipDate" : "2000-01-23T04:56:07.000+0000"
|
||||
}, contentType=application/json}, {example=<Order>
|
||||
"id" : 123456789,
|
||||
"shipDate" : "2000-01-23T04:56:07.000+0000",
|
||||
"complete" : true,
|
||||
"status" : "aeiou"
|
||||
}}, {contentType=application/xml, example=<Order>
|
||||
<id>123456</id>
|
||||
<petId>123456</petId>
|
||||
<quantity>0</quantity>
|
||||
<shipDate>2000-01-23T04:56:07.000Z</shipDate>
|
||||
<status>string</status>
|
||||
<complete>true</complete>
|
||||
</Order>, contentType=application/xml}]
|
||||
</Order>}]
|
||||
|
||||
- parameter body: (body) order placed for purchasing the pet (optional)
|
||||
|
||||
|
@ -244,16 +244,16 @@ public class UserAPI: APIBase {
|
||||
Get user by user name
|
||||
- GET /user/{username}
|
||||
-
|
||||
- examples: [{example={
|
||||
"id" : 123456789,
|
||||
"lastName" : "aeiou",
|
||||
"phone" : "aeiou",
|
||||
"username" : "aeiou",
|
||||
"email" : "aeiou",
|
||||
"userStatus" : 123,
|
||||
- examples: [{contentType=application/json, example={
|
||||
"firstName" : "aeiou",
|
||||
"password" : "aeiou"
|
||||
}, contentType=application/json}, {example=<User>
|
||||
"lastName" : "aeiou",
|
||||
"password" : "aeiou",
|
||||
"userStatus" : 123,
|
||||
"phone" : "aeiou",
|
||||
"id" : 123456789,
|
||||
"email" : "aeiou",
|
||||
"username" : "aeiou"
|
||||
}}, {contentType=application/xml, example=<User>
|
||||
<id>123456</id>
|
||||
<username>string</username>
|
||||
<firstName>string</firstName>
|
||||
@ -262,17 +262,17 @@ public class UserAPI: APIBase {
|
||||
<password>string</password>
|
||||
<phone>string</phone>
|
||||
<userStatus>0</userStatus>
|
||||
</User>, contentType=application/xml}]
|
||||
- examples: [{example={
|
||||
"id" : 123456789,
|
||||
"lastName" : "aeiou",
|
||||
"phone" : "aeiou",
|
||||
"username" : "aeiou",
|
||||
"email" : "aeiou",
|
||||
"userStatus" : 123,
|
||||
</User>}]
|
||||
- examples: [{contentType=application/json, example={
|
||||
"firstName" : "aeiou",
|
||||
"password" : "aeiou"
|
||||
}, contentType=application/json}, {example=<User>
|
||||
"lastName" : "aeiou",
|
||||
"password" : "aeiou",
|
||||
"userStatus" : 123,
|
||||
"phone" : "aeiou",
|
||||
"id" : 123456789,
|
||||
"email" : "aeiou",
|
||||
"username" : "aeiou"
|
||||
}}, {contentType=application/xml, example=<User>
|
||||
<id>123456</id>
|
||||
<username>string</username>
|
||||
<firstName>string</firstName>
|
||||
@ -281,7 +281,7 @@ public class UserAPI: APIBase {
|
||||
<password>string</password>
|
||||
<phone>string</phone>
|
||||
<userStatus>0</userStatus>
|
||||
</User>, contentType=application/xml}]
|
||||
</User>}]
|
||||
|
||||
- parameter username: (path) The name that needs to be fetched. Use user1 for testing.
|
||||
|
||||
@ -336,8 +336,8 @@ public class UserAPI: APIBase {
|
||||
Logs user into the system
|
||||
- GET /user/login
|
||||
-
|
||||
- examples: [{example="aeiou", contentType=application/json}, {example=string, contentType=application/xml}]
|
||||
- examples: [{example="aeiou", contentType=application/json}, {example=string, contentType=application/xml}]
|
||||
- examples: [{contentType=application/json, example="aeiou"}, {contentType=application/xml, example=string}]
|
||||
- examples: [{contentType=application/json, example="aeiou"}, {contentType=application/xml, example=string}]
|
||||
|
||||
- parameter username: (query) The user name for login (optional)
|
||||
- parameter password: (query) The password for login in clear text (optional)
|
||||
|
@ -156,7 +156,7 @@ class Decoders {
|
||||
instance.petId = Decoders.decodeOptional(clazz: Int64.self, source: sourceDictionary["petId"])
|
||||
instance.quantity = Decoders.decodeOptional(clazz: Int32.self, source: sourceDictionary["quantity"])
|
||||
instance.shipDate = Decoders.decodeOptional(clazz: NSDate.self, source: sourceDictionary["shipDate"])
|
||||
instance.status = Order.ST(rawValue: (sourceDictionary["status"] as? String) ?? "")
|
||||
instance.status = Order.Status(rawValue: (sourceDictionary["status"] as? String) ?? "")
|
||||
instance.complete = Decoders.decodeOptional(clazz: Bool.self, source: sourceDictionary["complete"])
|
||||
return instance
|
||||
}
|
||||
@ -175,7 +175,7 @@ class Decoders {
|
||||
instance.name = Decoders.decodeOptional(clazz: String.self, source: sourceDictionary["name"])
|
||||
instance.photoUrls = Decoders.decodeOptional(clazz: Array.self, source: sourceDictionary["photoUrls"])
|
||||
instance.tags = Decoders.decodeOptional(clazz: Array.self, source: sourceDictionary["tags"])
|
||||
instance.status = Pet.ST(rawValue: (sourceDictionary["status"] as? String) ?? "")
|
||||
instance.status = Pet.Status(rawValue: (sourceDictionary["status"] as? String) ?? "")
|
||||
return instance
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,7 @@ import Foundation
|
||||
|
||||
|
||||
public class Order: JSONEncodable {
|
||||
public enum ST: String {
|
||||
public enum Status: String {
|
||||
case Placed = "placed"
|
||||
case Approved = "approved"
|
||||
case Delivered = "delivered"
|
||||
@ -19,7 +19,7 @@ public class Order: JSONEncodable {
|
||||
public var quantity: Int32?
|
||||
public var shipDate: NSDate?
|
||||
/** Order Status */
|
||||
public var status: ST?
|
||||
public var status: Status?
|
||||
public var complete: Bool?
|
||||
|
||||
public init() {}
|
||||
|
@ -9,7 +9,7 @@ import Foundation
|
||||
|
||||
|
||||
public class Pet: JSONEncodable {
|
||||
public enum ST: String {
|
||||
public enum Status: String {
|
||||
case Available = "available"
|
||||
case Pending = "pending"
|
||||
case Sold = "sold"
|
||||
@ -20,7 +20,7 @@ public class Pet: JSONEncodable {
|
||||
public var photoUrls: [String]?
|
||||
public var tags: [Tag]?
|
||||
/** pet status in the store */
|
||||
public var status: ST?
|
||||
public var status: Status?
|
||||
|
||||
public init() {}
|
||||
|
||||
|
@ -32,7 +32,8 @@ class StoreAPITests: XCTestCase {
|
||||
order.complete = false
|
||||
order.quantity = 10
|
||||
order.shipDate = NSDate()
|
||||
order.status = .Placed
|
||||
// use explicit naming to reference the enum so that we test we don't regress on enum naming
|
||||
order.status = Order.Status.Placed
|
||||
let expectation = self.expectationWithDescription("testPlaceOrder")
|
||||
StoreAPI.placeOrder(body: order).then { order -> Void in
|
||||
XCTAssert(order.id == 1000, "invalid id")
|
||||
|
Loading…
x
Reference in New Issue
Block a user