Skip to content
Permalink
Browse files

Use ObjC reserved words only when objcCompatible is enabled (#2632)

* avoid whilelisting objc reseved words

* fix swift4 test

* add new files

* update swift4 tests
  • Loading branch information...
wing328 committed Apr 15, 2019
1 parent 3ca7e63 commit da9ba4cd7d5461647492b61aaf74cb850ded2456
Showing with 3,002 additions and 812 deletions.
  1. +1 −1 bin/swift4-petstore-promisekit.sh
  2. +1 −1 bin/swift4-petstore-rxswift.sh
  3. +1 −1 bin/swift4-petstore-unwrapRequired.sh
  4. +1 −1 bin/swift4-petstore.sh
  5. +15 −5 modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/Swift4Codegen.java
  6. +1 −1 modules/openapi-generator/src/test/java/org/openapitools/codegen/swift4/Swift4ModelTest.java
  7. +242 −37 ...enapi-generator/src/test/resources/2_0/swift/petstore-with-fake-endpoints-models-for-testing.yaml
  8. +6 −6 samples/client/petstore/swift4/default/PetstoreClient/Classes/OpenAPIs/APIs/AnotherFakeAPI.swift
  9. +30 −30 samples/client/petstore/swift4/default/PetstoreClient/Classes/OpenAPIs/APIs/FakeAPI.swift
  10. +6 −6 ...client/petstore/swift4/default/PetstoreClient/Classes/OpenAPIs/APIs/FakeClassnameTags123API.swift
  11. +17 −17 samples/client/petstore/swift4/default/PetstoreClient/Classes/OpenAPIs/APIs/PetAPI.swift
  12. +8 −8 samples/client/petstore/swift4/default/PetstoreClient/Classes/OpenAPIs/APIs/StoreAPI.swift
  13. +27 −27 samples/client/petstore/swift4/default/PetstoreClient/Classes/OpenAPIs/APIs/UserAPI.swift
  14. +7 −7 ...nt/petstore/swift4/default/PetstoreClient/Classes/OpenAPIs/Models/AdditionalPropertiesClass.swift
  15. +3 −8 samples/client/petstore/swift4/default/PetstoreClient/Classes/OpenAPIs/Models/Category.swift
  16. +2 −2 samples/client/petstore/swift4/default/PetstoreClient/Classes/OpenAPIs/Models/MapTest.swift
  17. +3 −12 samples/client/petstore/swift4/default/PetstoreClient/Classes/OpenAPIs/Models/Order.swift
  18. +3 −12 samples/client/petstore/swift4/default/PetstoreClient/Classes/OpenAPIs/Models/Pet.swift
  19. +3 −8 samples/client/petstore/swift4/default/PetstoreClient/Classes/OpenAPIs/Models/Tag.swift
  20. +38 −0 ...les/client/petstore/swift4/default/PetstoreClient/Classes/OpenAPIs/Models/TypeHolderDefault.swift
  21. +38 −0 ...les/client/petstore/swift4/default/PetstoreClient/Classes/OpenAPIs/Models/TypeHolderExample.swift
  22. +3 −14 samples/client/petstore/swift4/default/PetstoreClient/Classes/OpenAPIs/Models/User.swift
  23. +5 −5 samples/client/petstore/swift4/default/SwaggerClientTests/SwaggerClientTests/PetAPITests.swift
  24. +4 −4 samples/client/petstore/swift4/default/SwaggerClientTests/SwaggerClientTests/StoreAPITests.swift
  25. +1 −1 samples/client/petstore/swift4/default/SwaggerClientTests/run_xcodebuild.sh
  26. +6 −0 samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/OpenAPIs/APIHelper.swift
  27. +6 −6 ...s/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/OpenAPIs/APIs/AnotherFakeAPI.swift
  28. +65 −30 samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/OpenAPIs/APIs/FakeAPI.swift
  29. +6 −6 ...petstore/swift4/objcCompatible/PetstoreClient/Classes/OpenAPIs/APIs/FakeClassnameTags123API.swift
  30. +17 −17 samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/OpenAPIs/APIs/PetAPI.swift
  31. +8 −8 samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/OpenAPIs/APIs/StoreAPI.swift
  32. +27 −27 samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/OpenAPIs/APIs/UserAPI.swift
  33. +58 −0 ...re/swift4/objcCompatible/PetstoreClient/Classes/OpenAPIs/Models/AdditionalPropertiesAnyType.swift
  34. +58 −0 ...tore/swift4/objcCompatible/PetstoreClient/Classes/OpenAPIs/Models/AdditionalPropertiesArray.swift
  35. +58 −0 ...re/swift4/objcCompatible/PetstoreClient/Classes/OpenAPIs/Models/AdditionalPropertiesBoolean.swift
  36. +35 −8 ...tore/swift4/objcCompatible/PetstoreClient/Classes/OpenAPIs/Models/AdditionalPropertiesClass.swift
  37. +58 −0 ...re/swift4/objcCompatible/PetstoreClient/Classes/OpenAPIs/Models/AdditionalPropertiesInteger.swift
  38. +58 −0 ...ore/swift4/objcCompatible/PetstoreClient/Classes/OpenAPIs/Models/AdditionalPropertiesNumber.swift
  39. +58 −0 ...ore/swift4/objcCompatible/PetstoreClient/Classes/OpenAPIs/Models/AdditionalPropertiesObject.swift
  40. +58 −0 ...ore/swift4/objcCompatible/PetstoreClient/Classes/OpenAPIs/Models/AdditionalPropertiesString.swift
  41. +38 −0 ...ent/petstore/swift4/objcCompatible/PetstoreClient/Classes/OpenAPIs/Models/TypeHolderDefault.swift
  42. +38 −0 ...ent/petstore/swift4/objcCompatible/PetstoreClient/Classes/OpenAPIs/Models/TypeHolderExample.swift
  43. +110 −0 samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/OpenAPIs/Models/XmlItem.swift
  44. +6 −0 samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/OpenAPIs/APIHelper.swift
  45. +6 −6 samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/OpenAPIs/APIs/AnotherFakeAPI.swift
  46. +30 −30 samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/OpenAPIs/APIs/FakeAPI.swift
  47. +6 −6 ...ent/petstore/swift4/promisekit/PetstoreClient/Classes/OpenAPIs/APIs/FakeClassnameTags123API.swift
  48. +17 −17 samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/OpenAPIs/APIs/PetAPI.swift
  49. +8 −8 samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/OpenAPIs/APIs/StoreAPI.swift
  50. +27 −27 samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/OpenAPIs/APIs/UserAPI.swift
  51. +7 −7 ...petstore/swift4/promisekit/PetstoreClient/Classes/OpenAPIs/Models/AdditionalPropertiesClass.swift
  52. +3 −8 samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/OpenAPIs/Models/Category.swift
  53. +2 −2 samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/OpenAPIs/Models/MapTest.swift
  54. +3 −12 samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/OpenAPIs/Models/Order.swift
  55. +3 −12 samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/OpenAPIs/Models/Pet.swift
  56. +3 −8 samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/OpenAPIs/Models/Tag.swift
  57. +38 −0 .../client/petstore/swift4/promisekit/PetstoreClient/Classes/OpenAPIs/Models/TypeHolderDefault.swift
  58. +38 −0 .../client/petstore/swift4/promisekit/PetstoreClient/Classes/OpenAPIs/Models/TypeHolderExample.swift
  59. +3 −14 samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/OpenAPIs/Models/User.swift
  60. +110 −0 samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/OpenAPIs/Models/XmlItem.swift
  61. +5 −5 samples/client/petstore/swift4/promisekit/SwaggerClientTests/SwaggerClientTests/PetAPITests.swift
  62. +4 −4 samples/client/petstore/swift4/promisekit/SwaggerClientTests/SwaggerClientTests/StoreAPITests.swift
  63. +1 −1 samples/client/petstore/swift4/promisekit/SwaggerClientTests/run_xcodebuild.sh
  64. +6 −0 samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/OpenAPIs/APIHelper.swift
  65. +6 −6 samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/OpenAPIs/APIs/AnotherFakeAPI.swift
  66. +30 −30 samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/OpenAPIs/APIs/FakeAPI.swift
  67. +6 −6 ...client/petstore/swift4/rxswift/PetstoreClient/Classes/OpenAPIs/APIs/FakeClassnameTags123API.swift
  68. +17 −17 samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/OpenAPIs/APIs/PetAPI.swift
  69. +8 −8 samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/OpenAPIs/APIs/StoreAPI.swift
  70. +27 −27 samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/OpenAPIs/APIs/UserAPI.swift
  71. +58 −0 .../petstore/swift4/rxswift/PetstoreClient/Classes/OpenAPIs/Models/AdditionalPropertiesAnyType.swift
  72. +58 −0 ...nt/petstore/swift4/rxswift/PetstoreClient/Classes/OpenAPIs/Models/AdditionalPropertiesArray.swift
  73. +58 −0 .../petstore/swift4/rxswift/PetstoreClient/Classes/OpenAPIs/Models/AdditionalPropertiesBoolean.swift
  74. +7 −7 ...nt/petstore/swift4/rxswift/PetstoreClient/Classes/OpenAPIs/Models/AdditionalPropertiesClass.swift
  75. +58 −0 .../petstore/swift4/rxswift/PetstoreClient/Classes/OpenAPIs/Models/AdditionalPropertiesInteger.swift
  76. +58 −0 ...t/petstore/swift4/rxswift/PetstoreClient/Classes/OpenAPIs/Models/AdditionalPropertiesNumber.swift
  77. +58 −0 ...t/petstore/swift4/rxswift/PetstoreClient/Classes/OpenAPIs/Models/AdditionalPropertiesObject.swift
  78. +58 −0 ...t/petstore/swift4/rxswift/PetstoreClient/Classes/OpenAPIs/Models/AdditionalPropertiesString.swift
  79. +3 −8 samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/OpenAPIs/Models/Category.swift
  80. +2 −2 samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/OpenAPIs/Models/MapTest.swift
  81. +3 −12 samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/OpenAPIs/Models/Order.swift
  82. +3 −12 samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/OpenAPIs/Models/Pet.swift
  83. +3 −8 samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/OpenAPIs/Models/Tag.swift
  84. +38 −0 ...les/client/petstore/swift4/rxswift/PetstoreClient/Classes/OpenAPIs/Models/TypeHolderDefault.swift
  85. +38 −0 ...les/client/petstore/swift4/rxswift/PetstoreClient/Classes/OpenAPIs/Models/TypeHolderExample.swift
  86. +3 −14 samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/OpenAPIs/Models/User.swift
  87. +110 −0 samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/OpenAPIs/Models/XmlItem.swift
  88. +8 −8 samples/client/petstore/swift4/rxswift/SwaggerClientTests/SwaggerClientTests/PetAPITests.swift
  89. +4 −4 samples/client/petstore/swift4/rxswift/SwaggerClientTests/SwaggerClientTests/StoreAPITests.swift
  90. +2 −2 samples/client/petstore/swift4/rxswift/SwaggerClientTests/SwaggerClientTests/UserAPITests.swift
  91. +1 −1 samples/client/petstore/swift4/rxswift/SwaggerClientTests/run_xcodebuild.sh
  92. +7 −0 samples/client/petstore/swift4/swift4_test_all.sh
  93. +6 −0 samples/client/petstore/swift4/unwrapRequired/PetstoreClient/Classes/OpenAPIs/APIHelper.swift
  94. +6 −6 ...s/client/petstore/swift4/unwrapRequired/PetstoreClient/Classes/OpenAPIs/APIs/AnotherFakeAPI.swift
  95. +30 −30 samples/client/petstore/swift4/unwrapRequired/PetstoreClient/Classes/OpenAPIs/APIs/FakeAPI.swift
  96. +6 −6 ...petstore/swift4/unwrapRequired/PetstoreClient/Classes/OpenAPIs/APIs/FakeClassnameTags123API.swift
  97. +17 −17 samples/client/petstore/swift4/unwrapRequired/PetstoreClient/Classes/OpenAPIs/APIs/PetAPI.swift
  98. +8 −8 samples/client/petstore/swift4/unwrapRequired/PetstoreClient/Classes/OpenAPIs/APIs/StoreAPI.swift
  99. +27 −27 samples/client/petstore/swift4/unwrapRequired/PetstoreClient/Classes/OpenAPIs/APIs/UserAPI.swift
  100. +58 −0 ...re/swift4/unwrapRequired/PetstoreClient/Classes/OpenAPIs/Models/AdditionalPropertiesAnyType.swift
  101. +58 −0 ...tore/swift4/unwrapRequired/PetstoreClient/Classes/OpenAPIs/Models/AdditionalPropertiesArray.swift
  102. +58 −0 ...re/swift4/unwrapRequired/PetstoreClient/Classes/OpenAPIs/Models/AdditionalPropertiesBoolean.swift
  103. +7 −7 ...tore/swift4/unwrapRequired/PetstoreClient/Classes/OpenAPIs/Models/AdditionalPropertiesClass.swift
  104. +58 −0 ...re/swift4/unwrapRequired/PetstoreClient/Classes/OpenAPIs/Models/AdditionalPropertiesInteger.swift
  105. +58 −0 ...ore/swift4/unwrapRequired/PetstoreClient/Classes/OpenAPIs/Models/AdditionalPropertiesNumber.swift
  106. +58 −0 ...ore/swift4/unwrapRequired/PetstoreClient/Classes/OpenAPIs/Models/AdditionalPropertiesObject.swift
  107. +58 −0 ...ore/swift4/unwrapRequired/PetstoreClient/Classes/OpenAPIs/Models/AdditionalPropertiesString.swift
  108. +3 −8 samples/client/petstore/swift4/unwrapRequired/PetstoreClient/Classes/OpenAPIs/Models/Category.swift
  109. +2 −2 samples/client/petstore/swift4/unwrapRequired/PetstoreClient/Classes/OpenAPIs/Models/MapTest.swift
  110. +3 −12 samples/client/petstore/swift4/unwrapRequired/PetstoreClient/Classes/OpenAPIs/Models/Order.swift
  111. +3 −12 samples/client/petstore/swift4/unwrapRequired/PetstoreClient/Classes/OpenAPIs/Models/Pet.swift
  112. +3 −8 samples/client/petstore/swift4/unwrapRequired/PetstoreClient/Classes/OpenAPIs/Models/Tag.swift
  113. +38 −0 ...ent/petstore/swift4/unwrapRequired/PetstoreClient/Classes/OpenAPIs/Models/TypeHolderDefault.swift
  114. +38 −0 ...ent/petstore/swift4/unwrapRequired/PetstoreClient/Classes/OpenAPIs/Models/TypeHolderExample.swift
  115. +3 −14 samples/client/petstore/swift4/unwrapRequired/PetstoreClient/Classes/OpenAPIs/Models/User.swift
  116. +110 −0 samples/client/petstore/swift4/unwrapRequired/PetstoreClient/Classes/OpenAPIs/Models/XmlItem.swift
@@ -27,6 +27,6 @@ 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-promisekit.json -o samples/client/petstore/swift4/promisekit $@"
ags="generate -t modules/openapi-generator/src/main/resources/swift4 -i modules/openapi-generator/src/test/resources/2_0/swift/petstore-with-fake-endpoints-models-for-testing.yaml -g swift4 -c ./bin/swift4-petstore-promisekit.json -o samples/client/petstore/swift4/promisekit --generate-alias-as-model $@"

java $JAVA_OPTS -jar $executable $ags
@@ -27,6 +27,6 @@ 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-rxswift.json -o samples/client/petstore/swift4/rxswift $@"
ags="generate -t modules/openapi-generator/src/main/resources/swift4 -i modules/openapi-generator/src/test/resources/2_0/swift/petstore-with-fake-endpoints-models-for-testing.yaml -g swift4 -c ./bin/swift4-petstore-rxswift.json -o samples/client/petstore/swift4/rxswift --generate-alias-as-model $@"

java $JAVA_OPTS -jar $executable $ags
@@ -27,6 +27,6 @@ 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 $@"
ags="generate -t modules/openapi-generator/src/main/resources/swift4 -i modules/openapi-generator/src/test/resources/2_0/swift/petstore-with-fake-endpoints-models-for-testing.yaml -g swift4 -c ./bin/swift4-petstore-unwrapRequired.json -o samples/client/petstore/swift4/unwrapRequired --generate-alias-as-model $@"

java $JAVA_OPTS -jar $executable $ags
@@ -27,6 +27,6 @@ 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.json -o samples/client/petstore/swift4/default $@"
ags="generate -t modules/openapi-generator/src/main/resources/swift4 -i modules/openapi-generator/src/test/resources/2_0/swift/petstore-with-fake-endpoints-models-for-testing.yaml -g swift4 -c ./bin/swift4-petstore.json -o samples/client/petstore/swift4/default --generate-alias-as-model $@"

java $JAVA_OPTS -jar $executable $ags
@@ -66,6 +66,7 @@
protected boolean swiftUseApiNamespace;
protected String[] responseAs = new String[0];
protected String sourceFolder = "Classes" + File.separator + "OpenAPIs";
protected HashSet objcReservedWords;

/**
* Constructor for the swift4 language codegen module.
@@ -107,16 +108,20 @@ public Swift4Codegen() {
"AnyObject",
"Any")
);

objcReservedWords = new HashSet<>(
Arrays.asList(
// Added for Objective-C compatibility
"id", "description", "NSArray", "NSURL", "CGFloat", "NSSet", "NSString", "NSInteger", "NSUInteger",
"NSError", "NSDictionary"
)
);

reservedWords = new HashSet<>(
Arrays.asList(
// name used by swift client
"ErrorResponse", "Response",

// Added for Objective-C compatibility
"id", "description", "NSArray", "NSURL", "CGFloat", "NSSet", "NSString", "NSInteger", "NSUInteger",
"NSError", "NSDictionary",

//
// Swift keywords. This list is taken from here:
// https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/LexicalStructure.html#//apple_ref/doc/uid/TP40014097-CH30-ID410
//
@@ -326,6 +331,11 @@ public void processOpts() {
}
additionalProperties.put(OBJC_COMPATIBLE, objcCompatible);

// add objc reserved words
if (Boolean.TRUE.equals(objcCompatible)) {
reservedWords.addAll(objcReservedWords);
}

// Setup unwrapRequired option, which makes all the properties with "required" non-optional
if (additionalProperties.containsKey(RESPONSE_AS)) {
Object responseAsObject = additionalProperties.get(RESPONSE_AS);
@@ -59,7 +59,7 @@ public void simpleModelTest() {
final CodegenProperty property1 = cm.vars.get(0);
Assert.assertEquals(property1.baseName, "id");
Assert.assertEquals(property1.dataType, "Int64");
Assert.assertEquals(property1.name, "_id");
Assert.assertEquals(property1.name, "id");
Assert.assertNull(property1.defaultValue);
Assert.assertEquals(property1.baseType, "Int64");
Assert.assertTrue(property1.hasMore);
Oops, something went wrong.

0 comments on commit da9ba4c

Please sign in to comment.
You can’t perform that action at this time.