Fixes for swift4 language (#6116)

* 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
This commit is contained in:
ehyche
2017-07-20 03:45:09 -04:00
committed by wing328
parent bca35f6645
commit 2be2ee080b
96 changed files with 13391 additions and 4 deletions

View File

@@ -139,10 +139,10 @@ public class Swift4Codegen extends DefaultCodegen implements CodegenConfig {
typeMapping.put("string", "String");
typeMapping.put("char", "Character");
typeMapping.put("short", "Int");
typeMapping.put("int", "Int32");
typeMapping.put("int", "Int");
typeMapping.put("long", "Int64");
typeMapping.put("integer", "Int32");
typeMapping.put("Integer", "Int32");
typeMapping.put("integer", "Int");
typeMapping.put("Integer", "Int");
typeMapping.put("float", "Float");
typeMapping.put("number", "Double");
typeMapping.put("double", "Double");

View File

@@ -35,7 +35,9 @@ open class CodableHelper {
var returnedError: Error? = nil
let encoder = JSONEncoder()
encoder.outputFormatting = (prettyPrint ? .prettyPrinted : .compact)
if prettyPrint {
encoder.outputFormatting = .prettyPrinted
}
encoder.dataEncodingStrategy = .base64Encode
if #available(iOS 10.0, *) {
encoder.dateEncodingStrategy = .iso8601

View File

@@ -71,6 +71,11 @@ open class {{classname}}: {{#parent}}{{{parent}}}{{/parent}}{{^parent}}Codable{{
}
}
{{/additionalPropertiesType}}
private enum CodingKeys: String, CodingKey { {{#vars}}
case {{{name}}} = "{{{baseName}}}"{{/vars}}
}
}
{{/vars.isEmpty}}
{{/isEnum}}

View File

@@ -0,0 +1,279 @@
{
"swagger": "2.0",
"info": {
"title": "Swift 4 Test Schema",
"description": "This is a test schema which exercises Swagger schema features for testing the swift4 language codegen module.",
"termsOfService": "These are the dummy Terms of Service for the swift4 test schema.",
"contact": {
"name": "John Doe",
"url": "http://www.example.com",
"email": "jdoe@example.com"
},
"license": {
"name": "This is the license name for the swift4 test schema.",
"url": "http://www.example.com"
},
"version": "1.0"
},
"host": "api.example.com",
"basePath": "/basePath",
"schemes": [
"http",
"https"
],
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
{
"name": "Swift4Test"
}
],
"externalDocs": {
"description": "Look in this doc for further information.",
"url": "https://www.example.com/doc/index.html"
},
"paths": {
"/allModels": {
"get": {
"tags": [
"Swift4Test"
],
"summary": "Get all of the models",
"description": "This endpoint tests get a dictionary which contains examples of all of the models.",
"operationId": "GetAllModels",
"produces": [
"application/json"
],
"parameters": [
{
"name": "client_id",
"in": "query",
"description": "id that represent the Api client",
"required": true,
"type": "string",
"x-example": "swagger_ui"
}
],
"responses": {
"200": {
"description": "Successful operation",
"schema": {
"$ref": "#/definitions/GetAllModelsResult"
}
},
"400": {
"description": "Invalid client input",
"schema": {
"$ref": "#/definitions/ErrorInfo"
}
},
"424": {
"description": "Timeout",
"schema": {
"$ref": "#/definitions/ErrorInfo"
}
},
"500": {
"description": "Unexpected Server Error",
"schema": {
"$ref": "#/definitions/ErrorInfo"
}
}
}
}
}
},
"definitions": {
"StringEnum": {
"type": "string",
"enum": [
"stringEnumValue1",
"stringEnumValue2",
"stringEnumValue3"
]
},
"AllPrimitives": {
"type": "object",
"properties": {
"myInteger": {
"type": "integer"
},
"myIntegerArray": {
"type": "array",
"items": {
"type": "integer"
}
},
"myLong": {
"type": "integer",
"format": "int64"
},
"myLongArray": {
"type": "array",
"items": {
"type": "integer",
"format": "int64"
}
},
"myFloat": {
"type": "number",
"format": "float"
},
"myFloatArray": {
"type": "array",
"items": {
"type": "number",
"format": "float"
}
},
"myDouble": {
"type": "number",
"format": "double"
},
"myDoubleArray": {
"type": "array",
"items": {
"type": "number",
"format": "double"
}
},
"myString": {
"type": "string"
},
"myStringArray": {
"type": "array",
"items": {
"type": "string"
}
},
"myBytes": {
"type": "string",
"format": "byte"
},
"myBytesArray": {
"type": "array",
"items": {
"type": "string",
"format": "byte"
}
},
"myBoolean": {
"type": "boolean"
},
"myBooleanArray": {
"type": "array",
"items": {
"type": "boolean"
}
},
"myDate": {
"type": "string",
"format": "date"
},
"myDateArray": {
"type": "array",
"items": {
"type": "string",
"format": "date"
}
},
"myDateTime": {
"type": "string",
"format": "date-time"
},
"myDateTimeArray": {
"type": "array",
"items": {
"type": "string",
"format": "date-time"
}
},
"myFile": {
"type": "file"
},
"myFileArray": {
"type": "array",
"items": {
"type": "file"
}
},
"myUUID": {
"type": "string",
"format": "uuid"
},
"myUUIDArray": {
"type": "array",
"items": {
"type": "string",
"format": "uuid"
}
},
"myStringEnum": {
"$ref": "#/definitions/StringEnum"
},
"myStringEnumArray": {
"type": "array",
"items": {
"$ref": "#/definitions/StringEnum"
}
}
},
"description": "Object which contains lots of different primitive Swagger types"
},
"ErrorInfo": {
"type": "object",
"properties": {
"code": {
"type": "integer",
"format": "int32"
},
"message": {
"type": "string"
},
"details": {
"type": "array",
"items": {
"type": "string"
}
}
},
"description": "Example Error object"
},
"VariableNameTest": {
"description": "This object contains property names which we know will be different from their variable name. Examples of this include snake case property names and property names which are Swift 4 reserved words.",
"type": "object",
"properties": {
"example_name": {
"description": "This snake-case examle_name property name should be converted to a camelCase variable name like exampleName",
"type": "string"
},
"for": {
"description": "This property name is a reserved word in most languages, including Swift 4.",
"type": "string"
}
}
},
"GetAllModelsResult": {
"type": "object",
"properties": {
"myPrimitiveArray": {
"type": "array",
"items": {
"$ref": "#/definitions/AllPrimitives"
}
},
"myPrimitive": {
"$ref": "#/definitions/AllPrimitives"
},
"myVariableNameTest": {
"$ref": "#/definitions/VariableNameTest"
}
},
"description": "Response object containing AllPrimitives object"
}
}
}