Skip to content
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

Merged
merged 1 commit into from
Sep 9, 2018

Conversation

grEvenX
Copy link
Contributor

@grEvenX grEvenX commented Jul 26, 2018

PR checklist

  • Read the contribution guidelines.
  • Ran the shell script under ./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\.
  • Filed the PR against the correct branch: master, 4.0.x. Default: master.
  • Copied the technical committee to review the pull request if your PR is targeting a particular programming language.

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

@grEvenX
Copy link
Contributor Author

grEvenX commented Jul 26, 2018

Haven't run the scripts: ./bin/swift4-petstore.sh like mentioned in the checklist since I saw that it hasn't been run in a good while (so it caused more changes than this PR). Should probably run though :)

@jaz-ah
Copy link
Contributor

jaz-ah commented Jul 26, 2018

+1 LGTM

@jaz-ah
Copy link
Contributor

jaz-ah commented Jul 26, 2018

(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.
@wing328
Copy link
Member

wing328 commented Sep 7, 2018

I've update the Swift4 petstore samples and tests ran successfully:

▸ Test execute Succeeded
All tests
Test Suite SwaggerClientTests.xctest started
PetAPITests
    ✓ test1CreatePet (1.097 seconds)
    ✓ test2GetPet (0.618 seconds)
    ✓ test3DeletePet (0.585 seconds)
StoreAPITests
    ✓ test1PlaceOrder (0.768 seconds)
    ✓ test2GetOrder (0.572 seconds)
    ✓ test3DeleteOrder (0.707 seconds)
    ✓ testDownloadProgress (0.616 seconds)
UserAPITests
    ✓ testLogin (0.496 seconds)
    ✓ testLogout (0.526 seconds)
    ✓ testPathParamsAreEscaped (0.000 seconds)


Executed 10 tests, with 0 failures (0 unexpected) in 5.986 (5.990) seconds

git diff is only showing the following changes:

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)

@wing328 wing328 added this to the 3.3.0 milestone Sep 9, 2018
@wing328 wing328 merged commit f80fa08 into OpenAPITools:master Sep 9, 2018
jaumard pushed a commit to jaumard/openapi-generator that referenced this pull request Sep 21, 2018
…#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.
@wing328
Copy link
Member

wing328 commented Oct 2, 2018

@grEvenX thanks again for the PR, which is included in the v3.3.0 minor release: https://twitter.com/oas_generator/status/1046941449609068544

A-Joshi pushed a commit to ihsmarkitoss/openapi-generator that referenced this pull request Feb 27, 2019
…#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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants