-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Swift4] Fix default value for enums (#652) #656
Conversation
Haven't run the scripts: |
+1 LGTM |
(maybe we just run the petstore script in a followup pr which only has that change in it to catch up) |
This fixes an issue that makes the swift 4 api client fail to compile when using enums with a default value. The fix changes the toDefaultValue method to check if the property is of enum type, and then returns a properly formatted value. Looking into the code, I wonder why toEnumDefaultValue is not being used here, which seems to be the case for the java implementation.
I've update the Swift4 petstore samples and tests ran successfully:
diff --git a/samples/client/petstore/swift4/default/PetstoreClient/Classes/OpenAPIs/APIs/FakeAPI.swift b/samples/client/petstore/swift4/default/PetstoreClient/Classes/OpenAPIs/APIs/FakeAPI.swift
index 00f689db5..7dc52cc3b 100644
--- a/samples/client/petstore/swift4/default/PetstoreClient/Classes/OpenAPIs/APIs/FakeAPI.swift
+++ b/samples/client/petstore/swift4/default/PetstoreClient/Classes/OpenAPIs/APIs/FakeAPI.swift
@@ -389,13 +389,13 @@ open class FakeAPI {
To test enum parameters
- parameter enumHeaderStringArray: (header) Header parameter enum test (string array) (optional)
- - parameter enumHeaderString: (header) Header parameter enum test (string) (optional, default to "-efg")
+ - parameter enumHeaderString: (header) Header parameter enum test (string) (optional, default to .-efg)
- parameter enumQueryStringArray: (query) Query parameter enum test (string array) (optional)
- - parameter enumQueryString: (query) Query parameter enum test (string) (optional, default to "-efg")
+ - parameter enumQueryString: (query) Query parameter enum test (string) (optional, default to .-efg)
- parameter enumQueryInteger: (query) Query parameter enum test (double) (optional)
- parameter enumQueryDouble: (query) Query parameter enum test (double) (optional)
- - parameter enumFormStringArray: (form) Form parameter enum test (string array) (optional, default to "$")
- - parameter enumFormString: (form) Form parameter enum test (string) (optional, default to "-efg")
+ - parameter enumFormStringArray: (form) Form parameter enum test (string array) (optional, default to .$)
+ - parameter enumFormString: (form) Form parameter enum test (string) (optional, default to .-efg)
- parameter completion: completion handler to receive the data and the error objects
*/
open class func testEnumParameters(enumHeaderStringArray: [String]? = nil, enumHeaderString: EnumHeaderString_testEnumParameters? = nil, enumQueryStringArray: [String]? = nil, enumQueryString: EnumQueryString_testEnumParameters? = nil, enumQueryInteger: EnumQueryInteger_testEnumParameters? = nil, enumQueryDouble: EnumQueryDouble_testEnumParameters? = nil, enumFormStringArray: [String]? = nil, enumFormString: EnumFormString_testEnumParameters? = nil, completion: @escaping ((_ data: Void?,_ error: Error?) -> Void)) {
@@ -414,13 +414,13 @@ open class FakeAPI {
- GET /fake
- To test enum parameters
- parameter enumHeaderStringArray: (header) Header parameter enum test (string array) (optional)
- - parameter enumHeaderString: (header) Header parameter enum test (string) (optional, default to "-efg")
+ - parameter enumHeaderString: (header) Header parameter enum test (string) (optional, default to .-efg)
- parameter enumQueryStringArray: (query) Query parameter enum test (string array) (optional)
- - parameter enumQueryString: (query) Query parameter enum test (string) (optional, default to "-efg")
+ - parameter enumQueryString: (query) Query parameter enum test (string) (optional, default to .-efg)
- parameter enumQueryInteger: (query) Query parameter enum test (double) (optional)
- parameter enumQueryDouble: (query) Query parameter enum test (double) (optional)
- - parameter enumFormStringArray: (form) Form parameter enum test (string array) (optional, default to "$")
- - parameter enumFormString: (form) Form parameter enum test (string) (optional, default to "-efg")
+ - parameter enumFormStringArray: (form) Form parameter enum test (string array) (optional, default to .$)
+ - parameter enumFormString: (form) Form parameter enum test (string) (optional, default to .-efg)
- returns: RequestBuilder<Void>
*/
open class func testEnumParametersWithRequestBuilder(enumHeaderStringArray: [String]? = nil, enumHeaderString: EnumHeaderString_testEnumParameters? = nil, enumQueryStringArray: [String]? = nil, enumQueryString: EnumQueryString_testEnumParameters? = nil, enumQueryInteger: EnumQueryInteger_testEnumParameters? = nil, enumQueryDouble: EnumQueryDouble_testEnumParameters? = nil, enumFormStringArray: [String]? = nil, enumFormString: EnumFormString_testEnumParameters? = nil) -> RequestBuilder<Void> { If no further question/feedback. I'll merge it over the weekend. (@grEvenX my apologies for the delay in reviewing this PR) |
…#656) This fixes an issue that makes the swift 4 api client fail to compile when using enums with a default value. The fix changes the toDefaultValue method to check if the property is of enum type, and then returns a properly formatted value. Looking into the code, I wonder why toEnumDefaultValue is not being used here, which seems to be the case for the java implementation.
@grEvenX thanks again for the PR, which is included in the v3.3.0 minor release: https://twitter.com/oas_generator/status/1046941449609068544 |
…#656) This fixes an issue that makes the swift 4 api client fail to compile when using enums with a default value. The fix changes the toDefaultValue method to check if the property is of enum type, and then returns a properly formatted value. Looking into the code, I wonder why toEnumDefaultValue is not being used here, which seems to be the case for the java implementation.
PR checklist
./bin/
to update Petstore sample so that CIs can verify the change. (For instance, only need to run./bin/{LANG}-petstore.sh
and./bin/security/{LANG}-petstore.sh
if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in.\bin\windows\
.master
,4.0.x
. Default:master
.Description of the PR
This fixes an issue that makes the swift 4 api client fail to compile when using enums with a default value.
The fix changes the toDefaultValue method to check if the property is of enum type, and then returns a properly formatted value.
Looking into the code, I wonder why toEnumDefaultValue is not being used here, which seems to be the case for the java implementation. See issue details in #652 for example and expected output.
CC: @jgavris @ehyche @Edubits @jaz-ah @d-date