-
-
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
Erlang server overhaul #19465
Erlang server overhaul #19465
Conversation
b7e60ef
to
9fef973
Compare
9fef973
to
bb1cb46
Compare
thanks for refactoring the erlang sever generator 👍
in erlang, is there auto code formatter/linter to automatically format the code? that's what we usually recommend to users to do as it's not easy to format all the code perfectly in mustache template |
I'll mark the old (existing) erlang generator as deprecated (in another PR) so that we can include this PR in the upcoming release which allows breaking changes with fallback. |
Unfortunately (or fortunately?), there's like 4 different standard formatters. I could pick my favourite and just apply, though it would require plenty of manual tweaking taking into account it'd be running against mustache templates and not real erlang code. But it might at least ensure the generated code would just comply (?). However I'm not sure it's worth the effort, as, as I said, there are several tool out there anyway. But I can just try that maybe? 🥲 |
@wing328 I have a question as well, there are more issues related to mime types I'd like to fix (not sure if in this PR or already on a separate one), however the mustache templates give me booleans only for json and xml mime types ( Line 6887 in 4330b2f
|
users can pick whatever formatter they want. my point is we don't need to make sure the auto-generated code is perfectly formatted as such task can be delegated to code formatter/linter instead. |
another way is to check the value during runtime (in erlang code). not sure if it's something common in erlang. |
fyi. filed #19474 to mark current erlang-server as deprecated (just in case users need a fallback) |
Great to see! One question, should |
Can do that, it only will look ugly from the perspective of Erlang code, but this is autogenerated code anyway so nobody should be reading it much 🙈 |
Hello there! 😄 That's a very good point, one which I'm not familiar with 🥲 How hard it'd be to add 07 to jesse? Otherwise I'll find out how to set up some flag to ignore validation 🤔 |
I don't know how much changed between jsonschema versions. Maybe its not a big task, I sort of just assumed it would be a decent amount of work. |
I'm honestly thinking we could get away with validation here. I'm reading a bit about it and it seems like this requires a very smart generator. 3.0.x require actually draft 5, while 3.1.0 requires 2020-12. Mustache is very limited in what it allows you to template (logic-less, ya'know) and jesse is yet another limiting dependency here, and it's quite hard to template all these options, I think this could be left to the final user of the code rather 😕 |
@tsloughter I've pushed a big change, also solving #10393, but with some caveats, see the commit message for details 🙂 |
With this work, json validation becomes optional, fully implemented in the `_api` module as it was before, but without being forcibly called by the `_handler`. It is instead left as optional for the user to take advantage of the exposed callbacks. Jesse also chooses draft-06 as a default, but these can be chosen manually by the user too, as long as jesse implements them. `_handler` also becomes lighter, it now handles all mime types transparently by forwarding to a user-given module that must implement `accept_callback/4` and `provide_callback/4` as described in the `_logic_handler` callbacks. These will simply be the return values of cowboy_rest's `content_types_accepted` and `content_types_provided` respectively, and should simply comply with their defined APIs. They only get two parameters extending the behaviour, so that the user-given callback can pattern-match on them: the path prefix of the logic handler, and the operationID of the call.
5c40296
to
27eee49
Compare
27eee49
to
a634692
Compare
Pushed a fix for the typo that came out on CI |
The less dependencies the built code requires the better.
@wing328 what's the timeline for this PR? It's ready from my side, I've already been using it in local builds 🙂 |
Ok, pushed a check to make dialyzer (static typing analysis tool) stricter. Still, code is ready, looking forward to get this released :) |
can you please update the samples when you've time? |
79f7d01
to
36e89c5
Compare
Ouch, a single space went wrong 🥲 Updated! |
FYI. Merged #19547 to provide |
Amazing! Thank you so much! |
This is really a total overhaul of the 8 years old submitted erlang generator. It is not only very buggy but also quite incomplete.
Changes are many, and they're breaking. First thing, is that I'm requiring the latest OTP27, which includes a json parser and therefore using this and dumping the very old
jsx
. The new one on the standard library is 5-20x faster according to all public benchmarks. I'm here also upgrading the versions of cowboy and ranch to the latest ones, for way more performance improvements and related bug fixes.There's plenty of formatting changes, to actually follow the linked
inaka
guidelines (of which I am part of their team).There's also bug fixes like generating duplicated
is_authorized
handlers.PR checklist
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.
master
(upcoming 7.6.0 minor release - breaking changes with fallbacks),8.0.x
(breaking changes without fallbacks)8.0.x
? Not sure about it so pointing to master for now, please confirm me if I need to change it, that'd be easy.@tsloughter @jfacorro @robertoaloi