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] convert data to string before giving it to preg_match #16513

Merged
merged 1 commit into from
Sep 6, 2023

Conversation

individual-it
Copy link
Contributor

@individual-it individual-it commented Sep 5, 2023

Properties like

        lastModifiedDateTime:
          pattern: '^[0-9]{4,}-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])[Tt]([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]([.][0-9]{1,12})?([Zz]|[+-][0-9][0-9]:[0-9][0-9])$'
          type: string
          description: Date and time the item was last modified. Read-only.
          format: date-time
          readOnly: true

generate this kind of code:

    /**
     * Sets last_modified_date_time
     *
     * @param \DateTime|null $last_modified_date_time Date and time the item was last modified. Read-only.
     *
     * @return self
     */
    public function setLastModifiedDateTime($last_modified_date_time)
    {
        if (is_null($last_modified_date_time)) {
            throw new \InvalidArgumentException('non-nullable last_modified_date_time cannot be null');
        }
         if ((!preg_match("/^[0-9]{4,}-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])[Tt]([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]([.][0-9]{1,12})?([Zz]|[+-][0-9][0-9]:[0-9][0-9])$/", $last_modified_date_time))) {
              throw new \InvalidArgumentException("invalid value for \$last_modified_date_time when calling Drive., must conform to the pattern /^[0-9]{4,}-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])[Tt]([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]([.][0-9]{1,12})?([Zz]|[+-][0-9][0-9]:[0-9][0-9])$/.");
         }
....

so preg_match receives a DateTime objects and fails with Uncaught TypeError: preg_match(): Argument #2 ($subject) must be of type string, DateTime given

To avoid that call ObjectSerializer::toString, which takes a value and turns it into a string. If it's a string, pass through unchanged If it's a datetime object, format it in ISO8601 If it's a boolean, convert it to "true" or "false".

CC @jebentier @dkarlovi @mandrean @jfastnacht @ybelenko @renepardon

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
    
    Commit all changed files.
  • File the PR against the correct branch: master (7.0.1 - patch release), 7.1.x (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.

@wing328
Copy link
Member

wing328 commented Sep 5, 2023

please follow step 3 to update the samples so that the CI can verify the change.

@individual-it
Copy link
Contributor Author

@wing328 Sorry for not following the correct process. I've done that now

@wing328
Copy link
Member

wing328 commented Sep 6, 2023

thanks for the fix. tests passed locally:

PHPUnit 9.6.10 by Sebastian Bergmann and contributors.

...............................................................  63 / 207 ( 30%)
............................................................... 126 / 207 ( 60%)
............................................................... 189 / 207 ( 91%)
..................                                              207 / 207 (100%)

Time: 00:01.939, Memory: 12.00 MB

OK (207 tests, 357 assertions)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  7.153 s
[INFO] Finished at: 2023-09-06T15:40:04+08:00
[INFO] ------------------------------------------------------------------------
[INFO] 3 goals, 3 executed
[INFO] 
[INFO] Publishing build scan...
[INFO] https://ge.openapi-generator.tech/s/2k6f4ug2pttn2

@wing328 wing328 merged commit 270238e into OpenAPITools:master Sep 6, 2023
16 checks passed
@individual-it individual-it deleted the patch-1 branch September 6, 2023 07:47
@wing328
Copy link
Member

wing328 commented Oct 10, 2023

FYI. I've created a Slack channel (https://app.slack.com/client/TLQFRCNJZ/C0600D9TMK9) to facilitate discussions related to the PHP generators

@individual-it
Copy link
Contributor Author

same issue fixed in php-nextgen in #17119

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