Skip to content

Commit 5b5fe3c

Browse files
joeboyscout04wing328
authored andcommitted
[Swift 4] add compatibility for unwrapRequired config option (#229)
* Added support for unwrapRequired in Swift 4 * Update petstore generators for Swift.
1 parent 4664c07 commit 5b5fe3c

241 files changed

Lines changed: 14870 additions & 1111 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

bin/swift4-petstore-all.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
./bin/swift4-petstore-promisekit.sh
55
./bin/swift4-petstore-rxswift.sh
66
./bin/swift4-petstore-objcCompatible.sh
7+
./bin/swift4-petstore-unwrapRequired.sh
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"podSummary": "PetstoreClient",
3+
"podHomepage": "https://github.com/openapitools/openapi-generator",
4+
"podAuthors": "",
5+
"projectName": "PetstoreClient",
6+
"unwrapRequired": true
7+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/sh
2+
3+
SCRIPT="$0"
4+
echo "# START SCRIPT: $SCRIPT"
5+
6+
while [ -h "$SCRIPT" ] ; do
7+
ls=`ls -ld "$SCRIPT"`
8+
link=`expr "$ls" : '.*-> \(.*\)$'`
9+
if expr "$link" : '/.*' > /dev/null; then
10+
SCRIPT="$link"
11+
else
12+
SCRIPT=`dirname "$SCRIPT"`/"$link"
13+
fi
14+
done
15+
16+
if [ ! -d "${APP_DIR}" ]; then
17+
APP_DIR=`dirname "$SCRIPT"`/..
18+
APP_DIR=`cd "${APP_DIR}"; pwd`
19+
fi
20+
21+
executable="./modules/openapi-generator-cli/target/openapi-generator-cli.jar"
22+
23+
if [ ! -f "$executable" ]
24+
then
25+
mvn -B clean package
26+
fi
27+
28+
# if you've executed sbt assembly previously it will use that instead.
29+
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
30+
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 $@"
31+
32+
java $JAVA_OPTS -jar $executable $ags

modules/openapi-generator/src/main/resources/swift4/modelObject.mustache

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ public struct {{classname}}: Codable {
99
{{#allVars}}
1010
{{#isEnum}}
1111
{{#description}}/** {{description}} */
12-
{{/description}}public var {{name}}: {{{datatypeWithEnum}}}{{^required}}?{{/required}}{{#defaultValue}} = {{{defaultValue}}}{{/defaultValue}}
12+
{{/description}}public var {{name}}: {{{datatypeWithEnum}}}{{#unwrapRequired}}?{{/unwrapRequired}}{{^unwrapRequired}}{{^required}}?{{/required}}{{/unwrapRequired}}{{#defaultValue}} = {{{defaultValue}}}{{/defaultValue}}
1313
{{/isEnum}}
1414
{{^isEnum}}
1515
{{#description}}/** {{description}} */
16-
{{/description}}public var {{name}}: {{{dataType}}}{{^required}}?{{/required}}{{#defaultValue}} = {{{defaultValue}}}{{/defaultValue}}{{#objcCompatible}}{{#vendorExtensions.x-swift-optional-scalar}}
16+
{{/description}}public var {{name}}: {{{datatype}}}{{#unwrapRequired}}?{{/unwrapRequired}}{{^unwrapRequired}}{{^required}}?{{/required}}{{/unwrapRequired}}{{#defaultValue}} = {{{defaultValue}}}{{/defaultValue}}{{#objcCompatible}}{{#vendorExtensions.x-swift-optional-scalar}}
1717
public var {{name}}Num: NSNumber? {
1818
get {
1919
return {{name}}.map({ return NSNumber(value: $0) })
@@ -23,7 +23,7 @@ public struct {{classname}}: Codable {
2323
{{/allVars}}
2424

2525
{{#hasVars}}
26-
public init({{#allVars}}{{name}}: {{{datatypeWithEnum}}}{{^required}}?{{/required}}{{#hasMore}}, {{/hasMore}}{{/allVars}}) {
26+
public init({{#allVars}}{{name}}: {{{datatypeWithEnum}}}{{#unwrapRequired}}?{{/unwrapRequired}}{{^unwrapRequired}}{{^required}}?{{/required}}{{/unwrapRequired}}{{#hasMore}}, {{/hasMore}}{{/allVars}}) {
2727
{{#allVars}}
2828
self.{{name}} = {{name}}
2929
{{/allVars}}
@@ -52,7 +52,7 @@ public struct {{classname}}: Codable {
5252
var container = encoder.container(keyedBy: String.self)
5353
5454
{{#allVars}}
55-
try container.encode{{^required}}IfPresent{{/required}}({{{name}}}, forKey: "{{{baseName}}}")
55+
try container.encode{{#unwrapRequired}}IfPresent{{/unwrapRequired}}{{^unwrapRequired}}{{^required}}IfPresent{{/required}}{{/unwrapRequired}}({{{name}}}, forKey: "{{{baseName}}}")
5656
{{/allVars}}
5757
try container.encodeMap(additionalProperties)
5858
}
@@ -63,7 +63,7 @@ public struct {{classname}}: Codable {
6363
let container = try decoder.container(keyedBy: String.self)
6464
6565
{{#allVars}}
66-
{{name}} = try container.decode{{^required}}IfPresent{{/required}}({{{datatypeWithEnum}}}.self, forKey: "{{{baseName}}}")
66+
{{name}} = try container.decode{{#unwrapRequired}}IfPresent{{/unwrapRequired}}{{^unwrapRequired}}{{^required}}IfPresent{{/required}}{{/unwrapRequired}}({{{datatypeWithEnum}}}.self, forKey: "{{{baseName}}}")
6767
{{/allVars}}
6868
var nonAdditionalPropertyKeys = Set<String>()
6969
{{#allVars}}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.0.0-SNAPSHOT
1+
3.0.1-SNAPSHOT
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.0.0-SNAPSHOT
1+
3.0.1-SNAPSHOT

samples/client/petstore/swift3/objcCompatible/PetstoreClient/Classes/OpenAPIs/APIs/AnotherFakeAPI.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ open class AnotherFakeAPI: APIBase {
2626
To test special tags
2727
- PATCH /another-fake/dummy
2828
- To test special tags
29-
- examples: [{contentType=application/json, example={
30-
"client" : "client"
31-
}}]
3229
- parameter client: (body) client model
3330
- returns: RequestBuilder<Client>
3431
*/

samples/client/petstore/swift3/objcCompatible/PetstoreClient/Classes/OpenAPIs/APIs/FakeAPI.swift

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ open class FakeAPI: APIBase {
2424
/**
2525
- POST /fake/outer/boolean
2626
- Test serialization of outer boolean types
27-
- examples: [{contentType=*/*, example=null}]
2827
- parameter body: (body) Input boolean as post body (optional)
2928
- returns: RequestBuilder<Bool>
3029
*/
@@ -54,7 +53,6 @@ open class FakeAPI: APIBase {
5453
/**
5554
- POST /fake/outer/composite
5655
- Test serialization of object with outer number type
57-
- examples: [{contentType=*/*, example={ }}]
5856
- parameter outerComposite: (body) Input composite as post body (optional)
5957
- returns: RequestBuilder<OuterComposite>
6058
*/
@@ -84,7 +82,6 @@ open class FakeAPI: APIBase {
8482
/**
8583
- POST /fake/outer/number
8684
- Test serialization of outer number types
87-
- examples: [{contentType=*/*, example=null}]
8885
- parameter body: (body) Input number as post body (optional)
8986
- returns: RequestBuilder<Double>
9087
*/
@@ -114,7 +111,6 @@ open class FakeAPI: APIBase {
114111
/**
115112
- POST /fake/outer/string
116113
- Test serialization of outer string types
117-
- examples: [{contentType=*/*, example=null}]
118114
- parameter body: (body) Input string as post body (optional)
119115
- returns: RequestBuilder<String>
120116
*/
@@ -146,9 +142,6 @@ open class FakeAPI: APIBase {
146142
To test \"client\" model
147143
- PATCH /fake
148144
- To test \"client\" model
149-
- examples: [{contentType=application/json, example={
150-
"client" : "client"
151-
}}]
152145
- parameter client: (body) client model
153146
- returns: RequestBuilder<Client>
154147
*/

samples/client/petstore/swift3/objcCompatible/PetstoreClient/Classes/OpenAPIs/APIs/FakeClassnameTags123API.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ open class FakeClassnameTags123API: APIBase {
2828
- API Key:
2929
- type: apiKey api_key_query (QUERY)
3030
- name: api_key_query
31-
- examples: [{contentType=application/json, example={
32-
"client" : "client"
33-
}}]
3431
- parameter client: (body) client model
3532
- returns: RequestBuilder<Client>
3633
*/

samples/client/petstore/swift3/objcCompatible/PetstoreClient/Classes/OpenAPIs/APIs/PetAPI.swift

Lines changed: 0 additions & 161 deletions
Original file line numberDiff line numberDiff line change
@@ -113,58 +113,6 @@ open class PetAPI: APIBase {
113113
- OAuth:
114114
- type: oauth2
115115
- name: petstore_auth
116-
- examples: [{contentType=application/json, example={
117-
"photoUrls" : [ "photoUrls", "photoUrls" ],
118-
"name" : "doggie",
119-
"id" : 0,
120-
"category" : {
121-
"name" : "name",
122-
"id" : 6
123-
},
124-
"tags" : [ {
125-
"name" : "name",
126-
"id" : 1
127-
}, {
128-
"name" : "name",
129-
"id" : 1
130-
} ],
131-
"status" : "available"
132-
}}, {contentType=application/xml, example=<Pet>
133-
<id>123456789</id>
134-
<name>doggie</name>
135-
<photoUrls>
136-
<photoUrls>aeiou</photoUrls>
137-
</photoUrls>
138-
<tags>
139-
</tags>
140-
<status>aeiou</status>
141-
</Pet>}]
142-
- examples: [{contentType=application/json, example={
143-
"photoUrls" : [ "photoUrls", "photoUrls" ],
144-
"name" : "doggie",
145-
"id" : 0,
146-
"category" : {
147-
"name" : "name",
148-
"id" : 6
149-
},
150-
"tags" : [ {
151-
"name" : "name",
152-
"id" : 1
153-
}, {
154-
"name" : "name",
155-
"id" : 1
156-
} ],
157-
"status" : "available"
158-
}}, {contentType=application/xml, example=<Pet>
159-
<id>123456789</id>
160-
<name>doggie</name>
161-
<photoUrls>
162-
<photoUrls>aeiou</photoUrls>
163-
</photoUrls>
164-
<tags>
165-
</tags>
166-
<status>aeiou</status>
167-
</Pet>}]
168116
- parameter status: (query) Status values that need to be considered for filter
169117
- returns: RequestBuilder<[Pet]>
170118
*/
@@ -202,58 +150,6 @@ open class PetAPI: APIBase {
202150
- OAuth:
203151
- type: oauth2
204152
- name: petstore_auth
205-
- examples: [{contentType=application/json, example={
206-
"photoUrls" : [ "photoUrls", "photoUrls" ],
207-
"name" : "doggie",
208-
"id" : 0,
209-
"category" : {
210-
"name" : "name",
211-
"id" : 6
212-
},
213-
"tags" : [ {
214-
"name" : "name",
215-
"id" : 1
216-
}, {
217-
"name" : "name",
218-
"id" : 1
219-
} ],
220-
"status" : "available"
221-
}}, {contentType=application/xml, example=<Pet>
222-
<id>123456789</id>
223-
<name>doggie</name>
224-
<photoUrls>
225-
<photoUrls>aeiou</photoUrls>
226-
</photoUrls>
227-
<tags>
228-
</tags>
229-
<status>aeiou</status>
230-
</Pet>}]
231-
- examples: [{contentType=application/json, example={
232-
"photoUrls" : [ "photoUrls", "photoUrls" ],
233-
"name" : "doggie",
234-
"id" : 0,
235-
"category" : {
236-
"name" : "name",
237-
"id" : 6
238-
},
239-
"tags" : [ {
240-
"name" : "name",
241-
"id" : 1
242-
}, {
243-
"name" : "name",
244-
"id" : 1
245-
} ],
246-
"status" : "available"
247-
}}, {contentType=application/xml, example=<Pet>
248-
<id>123456789</id>
249-
<name>doggie</name>
250-
<photoUrls>
251-
<photoUrls>aeiou</photoUrls>
252-
</photoUrls>
253-
<tags>
254-
</tags>
255-
<status>aeiou</status>
256-
</Pet>}]
257153
- parameter tags: (query) Tags to filter by
258154
- returns: RequestBuilder<[Pet]>
259155
*/
@@ -291,58 +187,6 @@ open class PetAPI: APIBase {
291187
- API Key:
292188
- type: apiKey api_key
293189
- name: api_key
294-
- examples: [{contentType=application/json, example={
295-
"photoUrls" : [ "photoUrls", "photoUrls" ],
296-
"name" : "doggie",
297-
"id" : 0,
298-
"category" : {
299-
"name" : "name",
300-
"id" : 6
301-
},
302-
"tags" : [ {
303-
"name" : "name",
304-
"id" : 1
305-
}, {
306-
"name" : "name",
307-
"id" : 1
308-
} ],
309-
"status" : "available"
310-
}}, {contentType=application/xml, example=<Pet>
311-
<id>123456789</id>
312-
<name>doggie</name>
313-
<photoUrls>
314-
<photoUrls>aeiou</photoUrls>
315-
</photoUrls>
316-
<tags>
317-
</tags>
318-
<status>aeiou</status>
319-
</Pet>}]
320-
- examples: [{contentType=application/json, example={
321-
"photoUrls" : [ "photoUrls", "photoUrls" ],
322-
"name" : "doggie",
323-
"id" : 0,
324-
"category" : {
325-
"name" : "name",
326-
"id" : 6
327-
},
328-
"tags" : [ {
329-
"name" : "name",
330-
"id" : 1
331-
}, {
332-
"name" : "name",
333-
"id" : 1
334-
} ],
335-
"status" : "available"
336-
}}, {contentType=application/xml, example=<Pet>
337-
<id>123456789</id>
338-
<name>doggie</name>
339-
<photoUrls>
340-
<photoUrls>aeiou</photoUrls>
341-
</photoUrls>
342-
<tags>
343-
</tags>
344-
<status>aeiou</status>
345-
</Pet>}]
346190
- parameter petId: (path) ID of pet to return
347191
- returns: RequestBuilder<Pet>
348192
*/
@@ -460,11 +304,6 @@ open class PetAPI: APIBase {
460304
- OAuth:
461305
- type: oauth2
462306
- name: petstore_auth
463-
- examples: [{contentType=application/json, example={
464-
"code" : 0,
465-
"type" : "type",
466-
"message" : "message"
467-
}}]
468307
- parameter petId: (path) ID of pet to update
469308
- parameter additionalMetadata: (form) Additional data to pass to server (optional)
470309
- parameter file: (form) file to upload (optional)

0 commit comments

Comments
 (0)