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

[PHP-Symfony] Fixes #14930 #14933

Merged
merged 2 commits into from Mar 14, 2023
Merged

[PHP-Symfony] Fixes #14930 #14933

merged 2 commits into from Mar 14, 2023

Conversation

gturri
Copy link
Contributor

@gturri gturri commented Mar 12, 2023

This fixes the issues described on #14930 , ie: it fixes the parsing of date-time parameter, as well as non-required date-time parameters.
All the details are either on the bug report and on commit messages.

This PR can be tested by setting up a Symfony app with autogenerated code using the openapi file described on #14930 and performing the queries:

curl -i http://localhost:8000/my-route  # with this PR it leads to a 200 response (instead of 400 with current master)
curl -i http://localhost:8000/my-route?myparam=2017-07-21T12:34:56Z # this also returns 200 with this PR instead of a 400

(since this is PHP I guess I should ping @jebentier, @dkarlovi , @mandrean, @jfastnacht , @ybelenko @renepardon (sorry in advance for the noise if I misunderstood that guideline))

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.

This fixes parts of OpenAPITools#14930.

Without this patch a parameter declared as date-time
is validated against Symfony's "DateTime" constraint,
which always fails. Because this constraint expects
a string with format "Y-m-d H:i:s".
It fails because the generated code performs the check
after the deserialization, so the variable checked is not
a string anymore.

Besides this, even if we performed that validation on the
string, that would not work well because OpenApi
specification expects date-time to conform to RFC 3339
and that "Y-m-d H:i:s" would reject RFC 3339 compliant dates.

With this change we ensure that the string provided by the
web user could be parsed by PHP to DateTime, which solves both issues.

(Note however that it means that it now accepts more formats than just
RFC 3339 compliant ones for those parameters (it would accept all formats
accepted by PHP DateTime). That being said it's compliant with the guideline
""be conservative in what you send, be liberal in what you accept")
This fixes one of the issue described on OpenAPITools#14930, namely that
the deserializeString method of the generated class JsmSerializer returns null
for other types of string, but not for date-time. Instead it returns a DateTime
which represents "now" (because that what `new DateTime(null)` does).

Consequently when an API declares a date-time parameter as non-required and
when that endpoint is called without that parameters, then the user code
would end up having "now" instead of "null" for this parameter.
@wing328
Copy link
Member

wing328 commented Mar 13, 2023

thanks for the PR.

cc @jebentier (2017/07), @dkarlovi (2017/07), @mandrean (2017/08), @jfastnacht (2017/09), @ybelenko (2018/07), @renepardon (2018/12)

@wing328
Copy link
Member

wing328 commented Mar 14, 2023

LGTM

@wing328 wing328 merged commit 9fd989e into OpenAPITools:master Mar 14, 2023
7 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.

None yet

2 participants