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

[crystal] Fix some issues in crystal client templates #10629

Merged
merged 22 commits into from
Oct 23, 2021

Conversation

cyangle
Copy link
Contributor

@cyangle cyangle commented Oct 19, 2021

@wing328 Fixed some issues found when using crystal generator to generate client library for google drive v3 api
tests failed with below errors:

366313 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:3.0.0-M5:test (default-test) on project openapi-generator: There are test failures.
366313 [ERROR] 
366313 [ERROR] Please refer to /gen/modules/openapi-generator/target/surefire-reports for the individual test results.
366313 [ERROR] Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.
366313 [ERROR] ExecutionException The forked VM terminated without properly saying goodbye. VM crash or System.exit called?
366313 [ERROR] Command was /bin/sh -c cd /gen/modules/openapi-generator && /usr/local/openjdk-8/jre/bin/java -Xmx1024m -XX:MaxPermSize=256m org.apache.maven.surefire.booter.ForkedBooter /gen/modules/openapi-generator/target/surefire 2021-10-19T04-17-42_620-jvmRun1 surefire1215040486184154595tmp surefire_32415854988303674911tmp
366313 [ERROR] Error occurred in starting fork, check output in log
366314 [ERROR] Process Exit Code: 137
366314 [ERROR] Crashed tests:
366314 [ERROR] org.openapitools.codegen.kotlin.spring.KotlinSpringServerCodegenTest
366314 [ERROR] org.apache.maven.surefire.booter.SurefireBooterForkException: ExecutionException The forked VM terminated without properly saying goodbye. VM crash or System.exit called?
366314 [ERROR] Command was /bin/sh -c cd /gen/modules/openapi-generator && /usr/local/openjdk-8/jre/bin/java -Xmx1024m -XX:MaxPermSize=256m org.apache.maven.surefire.booter.ForkedBooter /gen/modules/openapi-generator/target/surefire 2021-10-19T04-17-42_620-jvmRun1 surefire1215040486184154595tmp surefire_32415854988303674911tmp

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package 
    ./bin/generate-samples.sh
    ./bin/utils/export_docs_generators.sh
    
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    For Windows users, please run the script in Git BASH.
  • File the PR against the correct branch: master (5.3.0), 6.0.x
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

@cyangle cyangle changed the title Fix some issues in crystal client templates [crystal] Fix some issues in crystal client templates Oct 19, 2021
@@ -245,18 +146,19 @@ module {{moduleName}}
when :pipes
param.join("|")
when :multi
# TODO: Need to fix this
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about raise an error saying multi is not supported in the client?

when {{{value}}}
{{{name}}}
{{/enumVars}} {{/allowableValues}}
else
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion to allow trailing spaces:

      {{#allowableValues}}
      {{#enumVars}}
      when {{{value}}}
        {{{name}}}
      {{/enumVars}}
      {{/allowableValues}}

Raises on unsupported feature
clean up extra new lines in partial_model_enum_class.mustache
length is undefined for String or Array
# return the array directly as typhoeus will handle it as expected
param
# TODO: Need to fix this
raise "mult is not supported yet"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo mult => multi

@wing328
Copy link
Member

wing328 commented Oct 21, 2021

I ran the crystal petstore integration tests (samples/client/petstore/crystal/pom.xml) locally but got

In src/petstore/models/pet.cr:63:69

 63 | def initialize(@id : Int64? = nil, @category : Category? = nil, @name : String, @photo_urls : Array(String), @tags : Array(Tag)? = nil, @status : String? = nil)
                                                                      ^
Error: parameter must have a default value

Looks like there's a breaking change in initializing the model (pet in this case)?

Can we remove the breaking change for the time being so that rest of the fixes/enhancements can be merged into master first?

@@ -432,7 +432,7 @@ module Petstore
# uploads an image
# @param pet_id [Int64] ID of pet to update
# @return [ApiResponse]
def upload_file(pet_id : Int64, additional_metadata : String?, file : File?)
def upload_file(pet_id : Int64, additional_metadata : String? = nil, file : File? = nil)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cyangle Is this (default to nil) also breaking change when it comes to calling the operations? If yes, please revert the change for the time being?

Copy link
Contributor Author

@cyangle cyangle Oct 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I missed it

@cyangle
Copy link
Contributor Author

cyangle commented Oct 22, 2021

@wing328 I have reverted the breaking changes and also added file upload support and other bug fixes

@cyangle
Copy link
Contributor Author

cyangle commented Oct 22, 2021

I have no idea how to fix this issue:

$ crystal test.cr 
In src/google_drive/api/about_api.cr:22:49

 22 | def drive_about_get(alt : String? = "json", fields : String?, key : String?, oauth_token : String?, pretty_print : Bool? = true, quota_user : String?, user_ip : String?)
                                                  ^
Error: parameter must have a default value

In crystal, a method can specify default values for the last parameters from here

@wing328
Copy link
Member

wing328 commented Oct 22, 2021

I reran the tests and now I got

Showing last frame. Use --error-trace for full trace.

In spec/api/pet_api_spec.cr:100:23

 100 | result.category.id.should eq pet_id + 10
                       ^-
Error: undefined method 'id' for Nil (compile-time type is (Petstore::Category | Nil))
[ERROR] Command execution failed.

Has there been any breaking changes to the model properties?

@wing328
Copy link
Member

wing328 commented Oct 22, 2021

Btw, here is how you can run the test locally with a petstore server running in your machine:

https://github.com/OpenAPITools/openapi-generator/wiki/Integration-Tests#how-to-add-integration-tests-for-new-petstore-samples

@wing328
Copy link
Member

wing328 commented Oct 23, 2021

All local tests passed:

In /usr/local/Cellar/crystal/1.2.0/src/uri/encoding.cr:119:25

 119 | String.build { |io| encode(string, io, space_to_plus: space_to_plus) }
                           ^-----
Warning: Deprecated URI.encode:space_to_plus. Use `.encode_path` instead.

In src/petstore/api/pet_api.cr:277:68

 277 | local_var_path = "/pet/{petId}".sub("{" + "petId" + "}", URI.encode(pet_id.to_s).gsub("%2F", "/"))
                                                                    ^-----
Warning: Deprecated URI.encode. Use `.encode_path` instead.

A total of 2 warnings were found.
..............................................................

Finished in 378.8 milliseconds
62 examples, 0 failures, 0 errors, 0 pending
[INFO] ----------------------------------------

@wing328 wing328 merged commit 27459b5 into OpenAPITools:master Oct 23, 2021
@wing328 wing328 added this to the 5.3.0 milestone Oct 23, 2021
@cyangle cyangle deleted the crystal branch October 23, 2021 04:03
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

2 participants