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-lang] Various fixes for Crystal client #21045

Merged
merged 6 commits into from
Apr 9, 2025

Conversation

n-rodriguez
Copy link
Contributor

@n-rodriguez n-rodriguez commented Apr 7, 2025

  • fix(crystal): implement cookie Auth
  • fix(crystal): don't send query parameters when parameter is nil
  • fix(crystal): make optional parameters truly optional
  • fix(crystal): bump to Crest 1.5.1
  • fix(crystal): allow users to YAML.dump(model) to ease debug

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 || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    (For Windows users, please run the script in Git BASH)
    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*.
    IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
  • File the PR against the correct branch: master (upcoming 7.x.0 minor release - breaking changes with fallbacks), 8.0.x (breaking changes without fallbacks)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

@n-rodriguez
Copy link
Contributor Author

n-rodriguez commented Apr 7, 2025

@wing328 I'd like to change this

typeMapping.put("object", "Object");
typeMapping.put("AnyType", "Object");

to

typeMapping.put("object", "Nil | String | Bool | Int32 | Int64 | Float32 | Float64 | Time");
typeMapping.put("AnyType", "Nil | String | Bool | Int32 | Int64 | Float32 | Float64 | Time");

here:

typeMapping.put("object", "Object");
typeMapping.put("AnyType", "Object");

because Object can no longer be instantiated directly (see: https://forum.crystal-lang.org/t/why-object-is-avoided-as-generic-type/645)

But when I run openapi-generator-cli :

	export _JAVA_OPTIONS=-DmaxYamlCodePoints=99999999 && \
		java -jar openapi-generator-cli.jar generate \
		-i ./netbox-rest.yml \
		-g crystal \
		-o ./netbox-client \
		--additional-properties moduleName=NetboxClient \
		--additional-properties shardName=netbox-client

final type is wrongly generated :

# @return [Hash(String, NilStringBoolInt32Int64Float32Float64Time)]

instead of

# @return [Hash(String, Nil | String | Bool | Int32 | Int64 | Float32 | Float64 | Time)]

When I run openapi-generator-cli with :

	export _JAVA_OPTIONS=-DmaxYamlCodePoints=99999999 && \
		java -jar openapi-generator-cli.jar generate \
		-i ./netbox-rest.yml \
		-g crystal \
		-o ./netbox-client \
		--additional-properties moduleName=NetboxClient \
		--additional-properties shardName=netbox-client \
		--type-mappings "Object=Nil | String | Bool | Int32 | Int64 | Float32 | Float64 | Time"

it works as expected but I'd prefer to update Java code directly to avoid adding --type-mappings option.

Thank you!

@wing328
Copy link
Member

wing328 commented Apr 7, 2025

thanks for the PR

i got the following errors when running the integration tests with your branch

[INFO]
[INFO] --- exec:3.0.0:exec (crystal-spec) @ CrystalPetstoreClientTests ---
Showing last frame. Use --error-trace for full trace.

In lib/http_proxy/src/http/proxy/server.cr:2:1

 2 | require "wait_group"
     ^
Error: can't find file 'wait_group'

If you're trying to require a shard:
- Did you remember to run `shards install`?
- Did you make sure you're running the compiler in the same directory as your shard.yml?
[ERROR] Command execution failed.

and tests passed with the master

can you please take a look when you've time?

@n-rodriguez
Copy link
Contributor Author

@wing328 I think it might come from the Crystal version used to run the tests. Which version of Crystal are you using?

@wing328
Copy link
Member

wing328 commented Apr 8, 2025

Crystal 1.12.1 [4cea10199] (2024-04-11)

LLVM: 15.0.7
Default target: x86_64-unknown-linux-gnu

which version are you using?

@wing328
Copy link
Member

wing328 commented Apr 8, 2025

also cc @cyangle (2021/01)

@n-rodriguez
Copy link
Contributor Author

@wing328

Crystal 1.15.1 [89944bf17] (2025-02-04)

LLVM: 15.0.7
Default target: aarch64-apple-macosx11.0

@wing328
Copy link
Member

wing328 commented Apr 8, 2025

if you run it with crystal 1.12.x, did you get the same error? just want to rule out it's issue with my local crystal setup.

@n-rodriguez
Copy link
Contributor Author

if you run it with crystal 1.12.x, did you get the same error?

yes

nicolas@MacBook-Pro-de-Nicolas:~/PROJECTS/GITHUB/FORKS/openapi-generator/samples/client/petstore/crystal$ crystal -v
Crystal 1.12.1 [4cea10199] (2024-04-11)

LLVM: 15.0.7
Default target: aarch64-apple-macosx11.0
nicolas@MacBook-Pro-de-Nicolas:~/PROJECTS/GITHUB/FORKS/openapi-generator/samples/client/petstore/crystal$ shards install
Resolving dependencies
Fetching https://github.com/kemalcr/kemal.git
Fetching https://github.com/crystal-ameba/ameba.git
Fetching https://github.com/mamantoha/crest.git
Fetching https://gitlab.com/arctic-fox/spectator.git
Fetching https://github.com/luislavena/radix.git
Fetching https://github.com/crystal-loot/exception_page.git
Fetching https://github.com/sija/backtracer.cr.git
Fetching https://github.com/mamantoha/http-client-digest_auth.git
Fetching https://github.com/mamantoha/http_proxy.git
Using http-client-digest_auth (0.6.0)
Installing http_proxy (0.13.0)
Installing crest (1.5.1)
Using radix (0.4.1)
Using backtracer (1.2.4)
Using exception_page (0.4.1)
Using kemal (1.5.0)
Using ameba (1.6.4)
Using spectator (0.12.1)
Writing shard.lock
Shard "http_proxy" may be incompatible with Crystal 1.12.1
nicolas@MacBook-Pro-de-Nicolas:~/PROJECTS/GITHUB/FORKS/openapi-generator/samples/client/petstore/crystal$ crystal spec
Showing last frame. Use --error-trace for full trace.

In lib/http_proxy/src/http/proxy/server.cr:2:1

 2 | require "wait_group"
     ^
Error: can't find file 'wait_group'

If you're trying to require a shard:
- Did you remember to run `shards install`?
- Did you make sure you're running the compiler in the same directory as your shard.yml?

@@ -22,7 +22,7 @@ shards:

http_proxy:
git: https://github.com/mamantoha/http_proxy.git
version: 0.10.3
version: 0.13.0
Copy link
Member

Choose a reason for hiding this comment

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

can we use an older version of http_proxy that works with crystal 1.12.x ?

0.13.0 was only released 3 weeks ago

Copy link
Contributor Author

Choose a reason for hiding this comment

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

can we use an older version of http_proxy that works with crystal 1.12.x ?

Actually the issue comes from crest shard. I've removed the commit that updates crest to v1.5.1. Now it works with Crystal 1.12

@wing328
Copy link
Member

wing328 commented Apr 9, 2025

all tests passed

............................................................................................

Finished in 230.99 milliseconds
92 examples, 0 failures

@wing328 wing328 merged commit 6bf5289 into OpenAPITools:master Apr 9, 2025
15 checks passed
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.

2 participants