forked from loafle/openapi-generator-original
* Fix build error in Xcode 9 beta 3, as .compact is no longer defined * Add test schema for Swift 4 and associated script and config files * Add test app for swift4Test.json schema * Make integer, Integer, int, and Int32 types map to Swift Int type instead of Int32 type * Add CodingKeys to model template, which allows us to serialize/deserialize variable names that are different than property names * Make updates to Swift 4 test schema * Fixes for unit test app for swift4Test.json Swift 4 test schema
43 lines
1.4 KiB
Swift
43 lines
1.4 KiB
Swift
//
|
|
// TestClientAppTests.swift
|
|
// TestClientAppTests
|
|
//
|
|
// Created by Eric Hyche on 7/18/17.
|
|
// Copyright © 2017 Swagger Codegen. All rights reserved.
|
|
//
|
|
|
|
import XCTest
|
|
import TestClient
|
|
@testable import TestClientApp
|
|
|
|
class TestClientAppTests: XCTestCase {
|
|
|
|
|
|
func testWhenVariableNameIsDifferentFromPropertyName() {
|
|
// This tests to make sure that the swift4 language can handle when
|
|
// we have property names which map to variable names that are not the same.
|
|
// This can happen when we have things like snake_case property names,
|
|
// or when we have property names which may be Swift 4 reserved words.
|
|
let jsonData = """
|
|
{
|
|
"example_name": "Test example name",
|
|
"for": "Some reason"
|
|
}
|
|
""".data(using: .utf8)!
|
|
|
|
let decodedResult = CodableHelper.decode(VariableNameTest.self, from: jsonData)
|
|
|
|
XCTAssertNil(decodedResult.error, "Got an error decoding VariableNameTest, error=\(String(describing: decodedResult.error))")
|
|
|
|
guard let variableNameTest = decodedResult.decodableObj else {
|
|
XCTFail("Did not get an VariableNameTest decoded object")
|
|
return
|
|
}
|
|
|
|
XCTAssertTrue(variableNameTest.exampleName == "Test example name", "Did not decode snake_case property correctly.")
|
|
XCTAssertTrue(variableNameTest._for == "Some reason", "Did not decode property name that is a reserved word correctly.")
|
|
}
|
|
|
|
|
|
}
|