mirror of
https://github.com/valitydev/openapi-generator.git
synced 2024-11-08 03:18:53 +00:00
Merge branch 'cjolif-enum'
This commit is contained in:
commit
8769e9b4f9
@ -355,8 +355,8 @@ public class SwiftCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
if (value.matches("[A-Z][a-z0-9]+[a-zA-Z0-9]*")) {
|
if (value.matches("[A-Z][a-z0-9]+[a-zA-Z0-9]*")) {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
char[] separators = {'-', '_', ' '};
|
char[] separators = {'-', '_', ' ', ':'};
|
||||||
return WordUtils.capitalizeFully(StringUtils.lowerCase(value), separators).replaceAll("[-_ ]", "");
|
return WordUtils.capitalizeFully(StringUtils.lowerCase(value), separators).replaceAll("[-_ :]", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -502,6 +502,7 @@ public class SwiftCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toEnumVarName(String name, String datatype) {
|
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
|
// number
|
||||||
if ("int".equals(datatype) || "double".equals(datatype) || "float".equals(datatype)) {
|
if ("int".equals(datatype) || "double".equals(datatype) || "float".equals(datatype)) {
|
||||||
String varName = new String(name);
|
String varName = new String(name);
|
||||||
@ -525,8 +526,9 @@ public class SwiftCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toEnumName(CodegenProperty property) {
|
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
|
if (enumName.matches("\\d.*")) { // starts with number
|
||||||
return "_" + enumName;
|
return "_" + enumName;
|
||||||
} else {
|
} else {
|
||||||
|
@ -46,9 +46,9 @@ class Decoders {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static func decode<T, Key: Hashable>(clazz clazz: [Key:T].Type, source: AnyObject) -> [Key:T] {
|
static func decode<T, Key: Hashable>(clazz clazz: [Key:T].Type, source: AnyObject) -> [Key:T] {
|
||||||
let sourceDictinoary = source as! [Key: AnyObject]
|
let sourceDictionary = source as! [Key: AnyObject]
|
||||||
var dictionary = [Key:T]()
|
var dictionary = [Key:T]()
|
||||||
for (key, value) in sourceDictinoary {
|
for (key, value) in sourceDictionary {
|
||||||
dictionary[key] = Decoders.decode(clazz: T.self, source: value)
|
dictionary[key] = Decoders.decode(clazz: T.self, source: value)
|
||||||
}
|
}
|
||||||
return dictionary
|
return dictionary
|
||||||
@ -156,7 +156,7 @@ class Decoders {
|
|||||||
instance.petId = Decoders.decodeOptional(clazz: Int64.self, source: sourceDictionary["petId"])
|
instance.petId = Decoders.decodeOptional(clazz: Int64.self, source: sourceDictionary["petId"])
|
||||||
instance.quantity = Decoders.decodeOptional(clazz: Int32.self, source: sourceDictionary["quantity"])
|
instance.quantity = Decoders.decodeOptional(clazz: Int32.self, source: sourceDictionary["quantity"])
|
||||||
instance.shipDate = Decoders.decodeOptional(clazz: NSDate.self, source: sourceDictionary["shipDate"])
|
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"])
|
instance.complete = Decoders.decodeOptional(clazz: Bool.self, source: sourceDictionary["complete"])
|
||||||
return instance
|
return instance
|
||||||
}
|
}
|
||||||
@ -175,7 +175,7 @@ class Decoders {
|
|||||||
instance.name = Decoders.decodeOptional(clazz: String.self, source: sourceDictionary["name"])
|
instance.name = Decoders.decodeOptional(clazz: String.self, source: sourceDictionary["name"])
|
||||||
instance.photoUrls = Decoders.decodeOptional(clazz: Array.self, source: sourceDictionary["photoUrls"])
|
instance.photoUrls = Decoders.decodeOptional(clazz: Array.self, source: sourceDictionary["photoUrls"])
|
||||||
instance.tags = Decoders.decodeOptional(clazz: Array.self, source: sourceDictionary["tags"])
|
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
|
return instance
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ import Foundation
|
|||||||
|
|
||||||
|
|
||||||
public class Order: JSONEncodable {
|
public class Order: JSONEncodable {
|
||||||
public enum ST: String {
|
public enum Status: String {
|
||||||
case Placed = "placed"
|
case Placed = "placed"
|
||||||
case Approved = "approved"
|
case Approved = "approved"
|
||||||
case Delivered = "delivered"
|
case Delivered = "delivered"
|
||||||
@ -19,7 +19,7 @@ public class Order: JSONEncodable {
|
|||||||
public var quantity: Int32?
|
public var quantity: Int32?
|
||||||
public var shipDate: NSDate?
|
public var shipDate: NSDate?
|
||||||
/** Order Status */
|
/** Order Status */
|
||||||
public var status: ST?
|
public var status: Status?
|
||||||
public var complete: Bool?
|
public var complete: Bool?
|
||||||
|
|
||||||
public init() {}
|
public init() {}
|
||||||
|
@ -9,7 +9,7 @@ import Foundation
|
|||||||
|
|
||||||
|
|
||||||
public class Pet: JSONEncodable {
|
public class Pet: JSONEncodable {
|
||||||
public enum ST: String {
|
public enum Status: String {
|
||||||
case Available = "available"
|
case Available = "available"
|
||||||
case Pending = "pending"
|
case Pending = "pending"
|
||||||
case Sold = "sold"
|
case Sold = "sold"
|
||||||
@ -20,7 +20,7 @@ public class Pet: JSONEncodable {
|
|||||||
public var photoUrls: [String]?
|
public var photoUrls: [String]?
|
||||||
public var tags: [Tag]?
|
public var tags: [Tag]?
|
||||||
/** pet status in the store */
|
/** pet status in the store */
|
||||||
public var status: ST?
|
public var status: Status?
|
||||||
|
|
||||||
public init() {}
|
public init() {}
|
||||||
|
|
||||||
|
@ -32,7 +32,8 @@ class StoreAPITests: XCTestCase {
|
|||||||
order.complete = false
|
order.complete = false
|
||||||
order.quantity = 10
|
order.quantity = 10
|
||||||
order.shipDate = NSDate()
|
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")
|
let expectation = self.expectationWithDescription("testPlaceOrder")
|
||||||
StoreAPI.placeOrder(body: order).then { order -> Void in
|
StoreAPI.placeOrder(body: order).then { order -> Void in
|
||||||
XCTAssert(order.id == 1000, "invalid id")
|
XCTAssert(order.id == 1000, "invalid id")
|
||||||
|
Loading…
Reference in New Issue
Block a user