mirror of
https://github.com/valitydev/openapi-generator.git
synced 2024-11-07 19:08:52 +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]*")) {
|
||||
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 {
|
||||
|
@ -46,9 +46,9 @@ class Decoders {
|
||||
}
|
||||
|
||||
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]()
|
||||
for (key, value) in sourceDictinoary {
|
||||
for (key, value) in sourceDictionary {
|
||||
dictionary[key] = Decoders.decode(clazz: T.self, source: value)
|
||||
}
|
||||
return dictionary
|
||||
@ -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…
Reference in New Issue
Block a user