Skip to content

Commit

Permalink
[Swift 4] add compatibility for unwrapRequired config option (#229)
Browse files Browse the repository at this point in the history
* Added support for unwrapRequired in Swift 4

* Update petstore generators for Swift.
  • Loading branch information
joeboyscout04 authored and wing328 committed Jun 21, 2018
1 parent 4664c07 commit 5b5fe3c
Show file tree
Hide file tree
Showing 241 changed files with 14,870 additions and 1,111 deletions.
1 change: 1 addition & 0 deletions bin/swift4-petstore-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
./bin/swift4-petstore-promisekit.sh
./bin/swift4-petstore-rxswift.sh
./bin/swift4-petstore-objcCompatible.sh
./bin/swift4-petstore-unwrapRequired.sh
7 changes: 7 additions & 0 deletions bin/swift4-petstore-unwrapRequired.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"podSummary": "PetstoreClient",
"podHomepage": "https://github.com/openapitools/openapi-generator",
"podAuthors": "",
"projectName": "PetstoreClient",
"unwrapRequired": true
}
32 changes: 32 additions & 0 deletions bin/swift4-petstore-unwrapRequired.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/sh

SCRIPT="$0"
echo "# START SCRIPT: $SCRIPT"

while [ -h "$SCRIPT" ] ; do
ls=`ls -ld "$SCRIPT"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
SCRIPT="$link"
else
SCRIPT=`dirname "$SCRIPT"`/"$link"
fi
done

if [ ! -d "${APP_DIR}" ]; then
APP_DIR=`dirname "$SCRIPT"`/..
APP_DIR=`cd "${APP_DIR}"; pwd`
fi

executable="./modules/openapi-generator-cli/target/openapi-generator-cli.jar"

if [ ! -f "$executable" ]
then
mvn -B clean package
fi

# if you've executed sbt assembly previously it will use that instead.
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
ags="generate -t modules/openapi-generator/src/main/resources/swift4 -i modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -g swift4 -c ./bin/swift4-petstore-unwrapRequired.json -o samples/client/petstore/swift4/unwrapRequired $@"

java $JAVA_OPTS -jar $executable $ags
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ public struct {{classname}}: Codable {
{{#allVars}}
{{#isEnum}}
{{#description}}/** {{description}} */
{{/description}}public var {{name}}: {{{datatypeWithEnum}}}{{^required}}?{{/required}}{{#defaultValue}} = {{{defaultValue}}}{{/defaultValue}}
{{/description}}public var {{name}}: {{{datatypeWithEnum}}}{{#unwrapRequired}}?{{/unwrapRequired}}{{^unwrapRequired}}{{^required}}?{{/required}}{{/unwrapRequired}}{{#defaultValue}} = {{{defaultValue}}}{{/defaultValue}}
{{/isEnum}}
{{^isEnum}}
{{#description}}/** {{description}} */
{{/description}}public var {{name}}: {{{dataType}}}{{^required}}?{{/required}}{{#defaultValue}} = {{{defaultValue}}}{{/defaultValue}}{{#objcCompatible}}{{#vendorExtensions.x-swift-optional-scalar}}
{{/description}}public var {{name}}: {{{datatype}}}{{#unwrapRequired}}?{{/unwrapRequired}}{{^unwrapRequired}}{{^required}}?{{/required}}{{/unwrapRequired}}{{#defaultValue}} = {{{defaultValue}}}{{/defaultValue}}{{#objcCompatible}}{{#vendorExtensions.x-swift-optional-scalar}}
public var {{name}}Num: NSNumber? {
get {
return {{name}}.map({ return NSNumber(value: $0) })
Expand All @@ -23,7 +23,7 @@ public struct {{classname}}: Codable {
{{/allVars}}

{{#hasVars}}
public init({{#allVars}}{{name}}: {{{datatypeWithEnum}}}{{^required}}?{{/required}}{{#hasMore}}, {{/hasMore}}{{/allVars}}) {
public init({{#allVars}}{{name}}: {{{datatypeWithEnum}}}{{#unwrapRequired}}?{{/unwrapRequired}}{{^unwrapRequired}}{{^required}}?{{/required}}{{/unwrapRequired}}{{#hasMore}}, {{/hasMore}}{{/allVars}}) {
{{#allVars}}
self.{{name}} = {{name}}
{{/allVars}}
Expand Down Expand Up @@ -52,7 +52,7 @@ public struct {{classname}}: Codable {
var container = encoder.container(keyedBy: String.self)
{{#allVars}}
try container.encode{{^required}}IfPresent{{/required}}({{{name}}}, forKey: "{{{baseName}}}")
try container.encode{{#unwrapRequired}}IfPresent{{/unwrapRequired}}{{^unwrapRequired}}{{^required}}IfPresent{{/required}}{{/unwrapRequired}}({{{name}}}, forKey: "{{{baseName}}}")
{{/allVars}}
try container.encodeMap(additionalProperties)
}
Expand All @@ -63,7 +63,7 @@ public struct {{classname}}: Codable {
let container = try decoder.container(keyedBy: String.self)
{{#allVars}}
{{name}} = try container.decode{{^required}}IfPresent{{/required}}({{{datatypeWithEnum}}}.self, forKey: "{{{baseName}}}")
{{name}} = try container.decode{{#unwrapRequired}}IfPresent{{/unwrapRequired}}{{^unwrapRequired}}{{^required}}IfPresent{{/required}}{{/unwrapRequired}}({{{datatypeWithEnum}}}.self, forKey: "{{{baseName}}}")
{{/allVars}}
var nonAdditionalPropertyKeys = Set<String>()
{{#allVars}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0.0-SNAPSHOT
3.0.1-SNAPSHOT
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0.0-SNAPSHOT
3.0.1-SNAPSHOT
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ open class AnotherFakeAPI: APIBase {
To test special tags
- PATCH /another-fake/dummy
- To test special tags
- examples: [{contentType=application/json, example={
"client" : "client"
}}]
- parameter client: (body) client model
- returns: RequestBuilder<Client>
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ open class FakeAPI: APIBase {
/**
- POST /fake/outer/boolean
- Test serialization of outer boolean types
- examples: [{contentType=*/*, example=null}]
- parameter body: (body) Input boolean as post body (optional)
- returns: RequestBuilder<Bool>
*/
Expand Down Expand Up @@ -54,7 +53,6 @@ open class FakeAPI: APIBase {
/**
- POST /fake/outer/composite
- Test serialization of object with outer number type
- examples: [{contentType=*/*, example={ }}]
- parameter outerComposite: (body) Input composite as post body (optional)
- returns: RequestBuilder<OuterComposite>
*/
Expand Down Expand Up @@ -84,7 +82,6 @@ open class FakeAPI: APIBase {
/**
- POST /fake/outer/number
- Test serialization of outer number types
- examples: [{contentType=*/*, example=null}]
- parameter body: (body) Input number as post body (optional)
- returns: RequestBuilder<Double>
*/
Expand Down Expand Up @@ -114,7 +111,6 @@ open class FakeAPI: APIBase {
/**
- POST /fake/outer/string
- Test serialization of outer string types
- examples: [{contentType=*/*, example=null}]
- parameter body: (body) Input string as post body (optional)
- returns: RequestBuilder<String>
*/
Expand Down Expand Up @@ -146,9 +142,6 @@ open class FakeAPI: APIBase {
To test \"client\" model
- PATCH /fake
- To test \"client\" model
- examples: [{contentType=application/json, example={
"client" : "client"
}}]
- parameter client: (body) client model
- returns: RequestBuilder<Client>
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ open class FakeClassnameTags123API: APIBase {
- API Key:
- type: apiKey api_key_query (QUERY)
- name: api_key_query
- examples: [{contentType=application/json, example={
"client" : "client"
}}]
- parameter client: (body) client model
- returns: RequestBuilder<Client>
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,58 +113,6 @@ open class PetAPI: APIBase {
- OAuth:
- type: oauth2
- name: petstore_auth
- examples: [{contentType=application/json, example={
"photoUrls" : [ "photoUrls", "photoUrls" ],
"name" : "doggie",
"id" : 0,
"category" : {
"name" : "name",
"id" : 6
},
"tags" : [ {
"name" : "name",
"id" : 1
}, {
"name" : "name",
"id" : 1
} ],
"status" : "available"
}}, {contentType=application/xml, example=<Pet>
<id>123456789</id>
<name>doggie</name>
<photoUrls>
<photoUrls>aeiou</photoUrls>
</photoUrls>
<tags>
</tags>
<status>aeiou</status>
</Pet>}]
- examples: [{contentType=application/json, example={
"photoUrls" : [ "photoUrls", "photoUrls" ],
"name" : "doggie",
"id" : 0,
"category" : {
"name" : "name",
"id" : 6
},
"tags" : [ {
"name" : "name",
"id" : 1
}, {
"name" : "name",
"id" : 1
} ],
"status" : "available"
}}, {contentType=application/xml, example=<Pet>
<id>123456789</id>
<name>doggie</name>
<photoUrls>
<photoUrls>aeiou</photoUrls>
</photoUrls>
<tags>
</tags>
<status>aeiou</status>
</Pet>}]
- parameter status: (query) Status values that need to be considered for filter
- returns: RequestBuilder<[Pet]>
*/
Expand Down Expand Up @@ -202,58 +150,6 @@ open class PetAPI: APIBase {
- OAuth:
- type: oauth2
- name: petstore_auth
- examples: [{contentType=application/json, example={
"photoUrls" : [ "photoUrls", "photoUrls" ],
"name" : "doggie",
"id" : 0,
"category" : {
"name" : "name",
"id" : 6
},
"tags" : [ {
"name" : "name",
"id" : 1
}, {
"name" : "name",
"id" : 1
} ],
"status" : "available"
}}, {contentType=application/xml, example=<Pet>
<id>123456789</id>
<name>doggie</name>
<photoUrls>
<photoUrls>aeiou</photoUrls>
</photoUrls>
<tags>
</tags>
<status>aeiou</status>
</Pet>}]
- examples: [{contentType=application/json, example={
"photoUrls" : [ "photoUrls", "photoUrls" ],
"name" : "doggie",
"id" : 0,
"category" : {
"name" : "name",
"id" : 6
},
"tags" : [ {
"name" : "name",
"id" : 1
}, {
"name" : "name",
"id" : 1
} ],
"status" : "available"
}}, {contentType=application/xml, example=<Pet>
<id>123456789</id>
<name>doggie</name>
<photoUrls>
<photoUrls>aeiou</photoUrls>
</photoUrls>
<tags>
</tags>
<status>aeiou</status>
</Pet>}]
- parameter tags: (query) Tags to filter by
- returns: RequestBuilder<[Pet]>
*/
Expand Down Expand Up @@ -291,58 +187,6 @@ open class PetAPI: APIBase {
- API Key:
- type: apiKey api_key
- name: api_key
- examples: [{contentType=application/json, example={
"photoUrls" : [ "photoUrls", "photoUrls" ],
"name" : "doggie",
"id" : 0,
"category" : {
"name" : "name",
"id" : 6
},
"tags" : [ {
"name" : "name",
"id" : 1
}, {
"name" : "name",
"id" : 1
} ],
"status" : "available"
}}, {contentType=application/xml, example=<Pet>
<id>123456789</id>
<name>doggie</name>
<photoUrls>
<photoUrls>aeiou</photoUrls>
</photoUrls>
<tags>
</tags>
<status>aeiou</status>
</Pet>}]
- examples: [{contentType=application/json, example={
"photoUrls" : [ "photoUrls", "photoUrls" ],
"name" : "doggie",
"id" : 0,
"category" : {
"name" : "name",
"id" : 6
},
"tags" : [ {
"name" : "name",
"id" : 1
}, {
"name" : "name",
"id" : 1
} ],
"status" : "available"
}}, {contentType=application/xml, example=<Pet>
<id>123456789</id>
<name>doggie</name>
<photoUrls>
<photoUrls>aeiou</photoUrls>
</photoUrls>
<tags>
</tags>
<status>aeiou</status>
</Pet>}]
- parameter petId: (path) ID of pet to return
- returns: RequestBuilder<Pet>
*/
Expand Down Expand Up @@ -460,11 +304,6 @@ open class PetAPI: APIBase {
- OAuth:
- type: oauth2
- name: petstore_auth
- examples: [{contentType=application/json, example={
"code" : 0,
"type" : "type",
"message" : "message"
}}]
- parameter petId: (path) ID of pet to update
- parameter additionalMetadata: (form) Additional data to pass to server (optional)
- parameter file: (form) file to upload (optional)
Expand Down
Loading

0 comments on commit 5b5fe3c

Please sign in to comment.