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

Rust validation handling #15288

Merged
merged 20 commits into from
Jun 16, 2023
Merged

Rust validation handling #15288

merged 20 commits into from
Jun 16, 2023

Conversation

ErikWegner
Copy link
Contributor

@ErikWegner ErikWegner commented Apr 22, 2023

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.
  • In case you are adding a new generator, run the following additional script :
    ./bin/utils/ensure-up-to-date.sh
    
    Commit all changed files.
  • File the PR against the correct branch: master (6.3.0) (minor release - breaking changes with fallbacks), 7.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. @paladinzh @jacob-pro

#/issues/10546

@jacob-pro
Copy link
Contributor

Thank you, I'm glad to see support for this feature.
Have you seen this thread though?

Keats/validator#201 (comment)

May want to look at using the replacement garde instead (or maybe not if it isn't ready yet)

https://github.com/jprochazk/garde

@ErikWegner
Copy link
Contributor Author

The garde crate works for my case, so the templates are adopted now.

@ErikWegner
Copy link
Contributor Author

@jacob-pro Is it ok now?

@jacob-pro
Copy link
Contributor

It would be good to have some samples so we can see it is working?

If you add some validation to this spec
https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/test/resources/3_0/rust/petstore.yaml

It should show up if you regenerate samples

@ErikWegner
Copy link
Contributor Author

@jacob-pro Now with validation in the sample.

@jacob-pro
Copy link
Contributor

Looks good to me 👍
Up to @wing328 to approve

@wing328
Copy link
Member

wing328 commented Apr 26, 2023

rust server tests failed: https://github.com/OpenAPITools/openapi-generator/actions/runs/4798540177/jobs/8554012928?pr=15288

can you please take a look ?

@ErikWegner
Copy link
Contributor Author

@wing328 The template is changed to handle that case. Can you please run the tests again?
Btw: are those circleci failures important?

@jacob-pro
Copy link
Contributor

jacob-pro commented Apr 27, 2023

I didn't realise this when i first looked since the title was only for Rust, but does this only apply to the "rust-server" generator and not the regular Rust generator?

If so please can you apply the same to the Rust generator?

@ErikWegner
Copy link
Contributor Author

Yes, this change applies to the rust-server generation.

The rust templates are for clients and are far more relaxed when it comes to data types and validation. My first impression was, this comes from the robustness principle: Be strict with what you send, be liberal what you accept, i.e. the server (rust-server) has strongly typed structs for sending data as described by the api specification, the client (rust) accepts many variants what a server may present, e.g. it puts dates into strings and leaves conversion to the calling code.

But the rust-server templates generate several parts that can be used independently: models, a client and a server. Therefore I would like to leave the rust templates untouched.

@jacob-pro
Copy link
Contributor

Ok makes sense

@ErikWegner
Copy link
Contributor Author

What are the next steps to get this forward, @jacob-pro ?

@wing328
Copy link
Member

wing328 commented May 8, 2023

Btw: are those circleci failures important?

yup, all tests are important and those failures (not related to this change) have been fixed in the master already.

@wing328
Copy link
Member

wing328 commented May 8, 2023

the rust server tests failed: https://github.com/OpenAPITools/openapi-generator/actions/runs/4912308190/jobs/8771220846?pr=15288

can you please take a look?

@ErikWegner
Copy link
Contributor Author

I will have a look into the failures.

@wing328 wing328 modified the milestones: 6.6.0, 7.0.0 May 11, 2023
@ErikWegner
Copy link
Contributor Author

The garde crate (for validation) has this issue: jprochazk/garde#39. What is your opinion on reverting back to the validator crate for now?

@wing328
Copy link
Member

wing328 commented May 24, 2023

I'm ok with switching back to validator, which seems to be more popular.

@jacob-pro
Copy link
Contributor

Yep like I said in my original suggestion - Garde may not yet be ready for general use, feel free to switch back
Or otherwise the ideal solution would be to have a flag that allows you to choose which validation library you want

@ErikWegner
Copy link
Contributor Author

@jacob-pro @wing328 Now it is rewritten to use the validator crate.

@wing328
Copy link
Member

wing328 commented Jun 15, 2023

Thanks for the PR but your commit (as shown in the Commits tab) is not linked to your Github account, which means this PR won't count as your contribution in https://github.com/OpenAPITools/openapi-generator/graphs/contributors.

Let me know if you need help fixing it.

Ref: https://github.com/OpenAPITools/openapi-generator/wiki/FAQ#how-can-i-update-commits-that-are-not-linked-to-my-github-account

@wing328
Copy link
Member

wing328 commented Jun 15, 2023

@ErikWegner
Copy link
Contributor Author

@wing328 Here it is.

@wing328
Copy link
Member

wing328 commented Jun 16, 2023

lgtm. let's give it a try.

@wing328 wing328 merged commit 3892703 into OpenAPITools:master Jun 16, 2023
fmoraespadtec pushed a commit to padteclab/openapi-generator that referenced this pull request Jun 26, 2023
* Prevent JavaScript regex delimiter

* Validation

* validator dependency

* validation with range

* Switch to garde crate for validation

* Update uuid crate

* Examples

* All rust-server samples

* Added rule handling

* Exchange garde for validator crate (rust)

* Version update in samples

---------

Co-authored-by: Erik Wegner <erik.wegner@regiocom.com>
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.

3 participants