-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
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
[Clojure] Add model generation and conforming #122
[Clojure] Add model generation and conforming #122
Conversation
- Generate clojure.specs from models - Optionally validate them at runtime (validation is active if orchestra.spec.test/instrument is called after specs are imported) - Coerce the results of the API calls to get objects that conform to the spec (e.g. get Date objects for dates and time instead of strings)
So that the order of the forms will be resolved by the compiler, otherwise we'd have to implement a topological ordering.
If I understand correctly, this is a breaking change and therefore I've labeled this PR as such. I'm testing the change and will merge when the test passes. |
@@ -1,32 +0,0 @@ | |||
<project> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@f-f please add back pom.xml so that CI (circleci) can run the tests for Clojure Petstore sample
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes sorry, I accidentally deleted them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem. Let us know if you need help running the tests locally for verification.
@@ -1,104 +0,0 @@ | |||
(ns open-api-petstore.api.pet-test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@f-f please add back this file as well as other "*_test.clj" files for Petstore integration tests.
2abe0c8
to
91fa925
Compare
It is if the |
Thanks for the explanation. I would suggest defaulting |
91fa925
to
2750e24
Compare
👍 I pushed the change to the setting and the updated sample. However, the tests are failing because we are on Java7, but this PR requires Java8. How can I upgrade it? |
The generator itself now requires java 8 so I think that it is fine to upgrade it. |
Please remove https://github.com/f-f/openapi-generator/blob/2750e249a08956ad67d87585d832b94813555b28/CI/pom.xml.circleci.java7#L839 |
@wing328 I pushed a fix for the tests, but they don't pass on my machine due to the API returning a 500 (which happens when I run the tests on master). They also don't pass on the CI seemingly due to the same issue (but CI log doesn't show the exceptions?). I'm testing by running |
@f-f the CircleCI tests failed with the following message:
I'll mark this as a breaking change without fallback as the Clojure client no longer works with JDK7 |
@wing328 yes I saw that, but I'm not able to replicate locally (to get debug info and inspect what's wrong with it), as I get a
👍 |
One way is to run the petstore server locally: https://hub.docker.com/r/swaggerapi/petstore/ and you will need to update the host table:
|
@wing328 thanks a lot! I fixed the existing tests, and added a test for the new decoding feature; now all tests pass locally. |
@f-f The CircleCI failed with the following errors:
Please take a look when you've time. |
@wing328 yeah I saw that and it's failing because of not finding the classes, which the last commit I pushed (88726c1) should have fixed (needs the capitalized filenames). |
I found a small bug in the meanwhile, so I'll ping again here once it's fixed |
Thanks for the update. If you need help from us, please let us know. Since it's a breaking change, I've changed the target branch to be "4.1.x" (for breaking changes without fallback) |
@f-f Thank you for taking the time to do this work, and share it back to the community. I'm seeing this working without test failures on MacOSX, does this fail anywhere other than CI reliably? |
Also, @f-f, you should be able to use
in the project directory to fix your issue with case insensitivity |
Hi @langford, thanks for dropping by! Also thanks for the I'll add a bit of context to what's blocking this PR:
IllegalStateException Package already refers to: class java.lang.Package ^ this is the bug I was referring to in my last comment. The solution I'd like to adopt would be to uncapitalize again the model names, and then just rename the name clashes where relevant. I'll try to put something together later today or tomorrow or next week. @wing328 thanks for asking if I'd need some help :) My only desire would be to have a more complex example API to test the program on (as this PR works fine on the Petstore tests but breaks on our API) |
@f-f you can consider using fake pestore spec instead of petstore.yaml/json as fake petstore covers a lot more edge cases (which may not be all addressed by this PR) |
Would prefixing all the spec names with a long hardcoded string allow this to be verified as working and merged sooner? It seems like that step could allow this all to be validated without worrying about removing the capitalization code. I offer this alternative as it seems this would also be less mysterious than context-dependent renames for people using the plugin on their own codebases. I doubt many people would go "of course my model name collides with the java keyword "strictfp", that's why it renames. Example:
Checking large specs is a great idea. Other specs that might work for validation purposes: YAML, possibly handwritten: Several different APIs using many features (2.0, but seems like they should be compatible): |
@f-f is there anything we (the community) can help with this PR? |
I had the fix on our patched version since a while, but wanted to test it and think about it a bit more. Things I did to fix:
Yeah, as I mentioned before we should setup more complex tests. I opened #743 to track that |
@f-f I'll merge it into 4.0.x tomorrow (Sunday) if no one has further feedback on this PR. |
@f-f PR merged into 4.0.x branch. Thanks for your contribution 👍 |
@wing328 thank you! :) |
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
.Description of the PR
This big PR adds support for generating Clojure Specs from OpenAPI Models.
Spec is a core library available since Clojure 1.9. Description from the linked page:
Things going on in this PR:
1.7.0
->1.9.0
: This is backwards compatible, so users can just bump their version and everything should be fine.spec
files from Models: they are in thespecs/
folder, and imported by allapi
files. This is done with the Data Specs from thespec-tools
library, as they are much nicer to read/write than vanilla specs.api
functions viadefn-spec
: in this way at development time all the inputs and outputs of function calls will be checked and will except if they don't conform (you need to callorchestra.spec.test/instrument
for it to be active).:decode-models
setting inapi-context
: so the above conforming can be turned off if it's indesiderable. This is opt-out (but we can make it opt-in if we want to keep backwards compatibility).I am not entirely sure this is correct in all cases (e.g. I'm suspicious about multiple arities), but we have an API much bigger than Petstore on which this is already deployed, and the generated code looks fine and works.
/cc @wing328 @xhh
Moreover, if this PR goes in I'd be available to be in the Clojure generator "technical committee", as the list is currently empty, and I could help with it.