From 16096e6bad20b35ffcbd3b21fb3706b863318198 Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Mon, 27 Apr 2026 15:46:54 +0000 Subject: [PATCH] feat: introduce DeveloperKnowledge --- .repo-metadata-full.json | 8 + DevelopersKnowledge/.OwlBot.yaml | 4 + DevelopersKnowledge/.gitattributes | 7 + .../.github/pull_request_template.md | 24 ++ DevelopersKnowledge/CONTRIBUTING.md | 10 + DevelopersKnowledge/LICENSE | 202 +++++++++++ DevelopersKnowledge/README.md | 73 ++++ DevelopersKnowledge/SECURITY.md | 7 + DevelopersKnowledge/VERSION | 1 + DevelopersKnowledge/composer.json | 30 ++ .../metadata/V1/Developerknowledge.php | 29 ++ DevelopersKnowledge/owlbot.py | 47 +++ DevelopersKnowledge/phpunit.xml.dist | 16 + .../batch_get_documents.php | 77 ++++ .../DeveloperKnowledgeClient/get_document.php | 73 ++++ .../search_document_chunks.php | 87 +++++ .../src/V1/BatchGetDocumentsRequest.php | 134 +++++++ .../src/V1/BatchGetDocumentsResponse.php | 68 ++++ .../V1/Client/DeveloperKnowledgeClient.php | 338 +++++++++++++++++ DevelopersKnowledge/src/V1/Document.php | 343 ++++++++++++++++++ DevelopersKnowledge/src/V1/DocumentChunk.php | 252 +++++++++++++ DevelopersKnowledge/src/V1/DocumentView.php | 84 +++++ .../src/V1/GetDocumentRequest.php | 142 ++++++++ .../src/V1/SearchDocumentChunksRequest.php | 322 ++++++++++++++++ .../src/V1/SearchDocumentChunksResponse.php | 138 +++++++ .../src/V1/gapic_metadata.json | 33 ++ .../developer_knowledge_client_config.json | 49 +++ .../developer_knowledge_descriptor_config.php | 59 +++ ...developer_knowledge_rest_client_config.php | 48 +++ .../Client/DeveloperKnowledgeClientTest.php | 304 ++++++++++++++++ composer.json | 3 + 31 files changed, 3012 insertions(+) create mode 100644 DevelopersKnowledge/.OwlBot.yaml create mode 100644 DevelopersKnowledge/.gitattributes create mode 100644 DevelopersKnowledge/.github/pull_request_template.md create mode 100644 DevelopersKnowledge/CONTRIBUTING.md create mode 100644 DevelopersKnowledge/LICENSE create mode 100644 DevelopersKnowledge/README.md create mode 100644 DevelopersKnowledge/SECURITY.md create mode 100644 DevelopersKnowledge/VERSION create mode 100644 DevelopersKnowledge/composer.json create mode 100644 DevelopersKnowledge/metadata/V1/Developerknowledge.php create mode 100644 DevelopersKnowledge/owlbot.py create mode 100644 DevelopersKnowledge/phpunit.xml.dist create mode 100644 DevelopersKnowledge/samples/V1/DeveloperKnowledgeClient/batch_get_documents.php create mode 100644 DevelopersKnowledge/samples/V1/DeveloperKnowledgeClient/get_document.php create mode 100644 DevelopersKnowledge/samples/V1/DeveloperKnowledgeClient/search_document_chunks.php create mode 100644 DevelopersKnowledge/src/V1/BatchGetDocumentsRequest.php create mode 100644 DevelopersKnowledge/src/V1/BatchGetDocumentsResponse.php create mode 100644 DevelopersKnowledge/src/V1/Client/DeveloperKnowledgeClient.php create mode 100644 DevelopersKnowledge/src/V1/Document.php create mode 100644 DevelopersKnowledge/src/V1/DocumentChunk.php create mode 100644 DevelopersKnowledge/src/V1/DocumentView.php create mode 100644 DevelopersKnowledge/src/V1/GetDocumentRequest.php create mode 100644 DevelopersKnowledge/src/V1/SearchDocumentChunksRequest.php create mode 100644 DevelopersKnowledge/src/V1/SearchDocumentChunksResponse.php create mode 100644 DevelopersKnowledge/src/V1/gapic_metadata.json create mode 100644 DevelopersKnowledge/src/V1/resources/developer_knowledge_client_config.json create mode 100644 DevelopersKnowledge/src/V1/resources/developer_knowledge_descriptor_config.php create mode 100644 DevelopersKnowledge/src/V1/resources/developer_knowledge_rest_client_config.php create mode 100644 DevelopersKnowledge/tests/Unit/V1/Client/DeveloperKnowledgeClientTest.php diff --git a/.repo-metadata-full.json b/.repo-metadata-full.json index eaa99a006ff3..e39249c92c79 100644 --- a/.repo-metadata-full.json +++ b/.repo-metadata-full.json @@ -653,6 +653,14 @@ "library_type": "GAPIC_AUTO", "api_shortname": "developerconnect" }, + "DevelopersKnowledge": { + "language": "php", + "distribution_name": "google/developers-knowledge", + "release_level": "preview", + "client_documentation": "https://cloud.google.com/php/docs/reference/developers-knowledge/latest", + "library_type": "GAPIC_AUTO", + "api_shortname": "developerknowledge" + }, "DeviceStreaming": { "language": "php", "distribution_name": "google/cloud-devicestreaming", diff --git a/DevelopersKnowledge/.OwlBot.yaml b/DevelopersKnowledge/.OwlBot.yaml new file mode 100644 index 000000000000..a41f4244ed9e --- /dev/null +++ b/DevelopersKnowledge/.OwlBot.yaml @@ -0,0 +1,4 @@ +deep-copy-regex: + - source: /google/developers/knowledge/(v1)/.*-php/(.*) + dest: /owl-bot-staging/DevelopersKnowledge/$1/$2 +api-name: DevelopersKnowledge diff --git a/DevelopersKnowledge/.gitattributes b/DevelopersKnowledge/.gitattributes new file mode 100644 index 000000000000..4bf0fe6f415b --- /dev/null +++ b/DevelopersKnowledge/.gitattributes @@ -0,0 +1,7 @@ +/*.xml.dist export-ignore +/.OwlBot.yaml export-ignore +/.github export-ignore +/owlbot.py export-ignore +/src/**/gapic_metadata.json export-ignore +/samples export-ignore +/tests export-ignore diff --git a/DevelopersKnowledge/.github/pull_request_template.md b/DevelopersKnowledge/.github/pull_request_template.md new file mode 100644 index 000000000000..3b73c5eb7e0f --- /dev/null +++ b/DevelopersKnowledge/.github/pull_request_template.md @@ -0,0 +1,24 @@ +**PLEASE READ THIS ENTIRE MESSAGE** + +Hello, and thank you for your contribution! Please note that this repository is +a read-only split of `googleapis/google-cloud-php`. As such, we are +unable to accept pull requests to this repository. + +We welcome your pull request and would be happy to consider it for inclusion in +our library if you follow these steps: + +* Clone the parent client library repository: + +```sh +$ git clone git@github.com:googleapis/google-cloud-php.git +``` + +* Move your changes into the correct location in that library. Library code +belongs in `DevelopersKnowledge/src`, and tests in `DevelopersKnowledge/tests`. + +* Push the changes in a new branch to a fork, and open a new pull request +[here](https://github.com/googleapis/google-cloud-php). + +Thanks again, and we look forward to seeing your proposed change! + +The Google Cloud PHP team diff --git a/DevelopersKnowledge/CONTRIBUTING.md b/DevelopersKnowledge/CONTRIBUTING.md new file mode 100644 index 000000000000..76ea811cacdb --- /dev/null +++ b/DevelopersKnowledge/CONTRIBUTING.md @@ -0,0 +1,10 @@ +# How to Contribute + +We'd love to accept your patches and contributions to this project. We accept +and review pull requests against the main +[Google Cloud PHP](https://github.com/googleapis/google-cloud-php) +repository, which contains all of our client libraries. You will also need to +sign a Contributor License Agreement. For more details about how to contribute, +see the +[CONTRIBUTING.md](https://github.com/googleapis/google-cloud-php/blob/main/CONTRIBUTING.md) +file in the main Google Cloud PHP repository. diff --git a/DevelopersKnowledge/LICENSE b/DevelopersKnowledge/LICENSE new file mode 100644 index 000000000000..8f71f43fee3f --- /dev/null +++ b/DevelopersKnowledge/LICENSE @@ -0,0 +1,202 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "{}" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright {yyyy} {name of copyright owner} + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + diff --git a/DevelopersKnowledge/README.md b/DevelopersKnowledge/README.md new file mode 100644 index 000000000000..e4feee127d7a --- /dev/null +++ b/DevelopersKnowledge/README.md @@ -0,0 +1,73 @@ +# Google Developers Knowledge for PHP + +> Idiomatic PHP client for [Google Developers Knowledge](https://developers.google.com/knowledge). + +[![Latest Stable Version](https://poser.pugx.org/google/developers-knowledge/v/stable)](https://packagist.org/packages/google/developers-knowledge) [![Packagist](https://img.shields.io/packagist/dm/google/developers-knowledge.svg)](https://packagist.org/packages/google/developers-knowledge) + +* [API documentation](https://cloud.google.com/php/docs/reference/developers-knowledge/latest) + +**NOTE:** This repository is part of [Google Cloud PHP](https://github.com/googleapis/google-cloud-php). Any +support requests, bug reports, or development contributions should be directed to +that project. + +### Installation + +To begin, install the preferred dependency manager for PHP, [Composer](https://getcomposer.org/). + +Now, install this component: + +```sh +$ composer require google/developers-knowledge +``` + +> Browse the complete list of [Google Cloud APIs](https://cloud.google.com/php/docs/reference) +> for PHP + +This component supports both REST over HTTP/1.1 and gRPC. In order to take advantage of the benefits +offered by gRPC (such as streaming methods) please see our +[gRPC installation guide](https://cloud.google.com/php/grpc). + +### Authentication + +Please see our [Authentication guide](https://github.com/googleapis/google-cloud-php/blob/main/AUTHENTICATION.md) for more information +on authenticating your client. Once authenticated, you'll be ready to start making requests. + +### Sample + +```php +use Google\ApiCore\ApiException; +use Google\Developers\Knowledge\V1\Client\DeveloperKnowledgeClient; +use Google\Developers\Knowledge\V1\Document; +use Google\Developers\Knowledge\V1\GetDocumentRequest; + +// Create a client. +$developerKnowledgeClient = new DeveloperKnowledgeClient(); + +// Prepare the request message. +$request = (new GetDocumentRequest()) + ->setName($formattedName); + +// Call the API and handle any network failures. +try { + /** @var Document $response */ + $response = $developerKnowledgeClient->getDocument($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); +} catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); +} +``` + +See the [samples directory](https://github.com/googleapis/php-developers-knowledge/tree/main/samples) for a canonical list of samples. + +### Debugging + +Please see our [Debugging guide](https://github.com/googleapis/google-cloud-php/blob/main/DEBUG.md) +for more information about the debugging tools. + +### Version + +This component is considered alpha. As such, it is still a work-in-progress and is more likely to get backwards-incompatible updates. + +### Next Steps + +1. Understand the [official documentation](https://developers.google.com/knowledge). diff --git a/DevelopersKnowledge/SECURITY.md b/DevelopersKnowledge/SECURITY.md new file mode 100644 index 000000000000..8b58ae9c01ae --- /dev/null +++ b/DevelopersKnowledge/SECURITY.md @@ -0,0 +1,7 @@ +# Security Policy + +To report a security issue, please use [g.co/vulnz](https://g.co/vulnz). + +The Google Security Team will respond within 5 working days of your report on g.co/vulnz. + +We use g.co/vulnz for our intake, and do coordination and disclosure here using GitHub Security Advisory to privately discuss and fix the issue. diff --git a/DevelopersKnowledge/VERSION b/DevelopersKnowledge/VERSION new file mode 100644 index 000000000000..77d6f4ca2371 --- /dev/null +++ b/DevelopersKnowledge/VERSION @@ -0,0 +1 @@ +0.0.0 diff --git a/DevelopersKnowledge/composer.json b/DevelopersKnowledge/composer.json new file mode 100644 index 000000000000..9450b807d9e5 --- /dev/null +++ b/DevelopersKnowledge/composer.json @@ -0,0 +1,30 @@ +{ + "name": "google/developers-knowledge", + "description": "Google Developers Knowledge Client for PHP", + "license": "Apache-2.0", + "minimum-stability": "stable", + "autoload": { + "psr-4": { + "Google\\Developers\\Knowledge\\": "src", + "GPBMetadata\\Google\\Developers\\Knowledge\\": "metadata" + } + }, + "extra": { + "component": { + "id": "developers-knowledge", + "path": "DevelopersKnowledge", + "target": "googleapis/php-developers-knowledge" + } + }, + "require": { + "php": "^8.1", + "google/gax": "^1.42.0" + }, + "require-dev": { + "phpunit/phpunit": "^9.0" + }, + "suggest": { + "ext-grpc": "Enables use of gRPC, a universal high-performance RPC framework created by Google.", + "ext-protobuf": "Provides a significant increase in throughput over the pure PHP protobuf implementation. See https://cloud.google.com/php/grpc for installation instructions." + } +} diff --git a/DevelopersKnowledge/metadata/V1/Developerknowledge.php b/DevelopersKnowledge/metadata/V1/Developerknowledge.php new file mode 100644 index 000000000000..ee5e44696234 --- /dev/null +++ b/DevelopersKnowledge/metadata/V1/Developerknowledge.php @@ -0,0 +1,29 @@ +internalAddGeneratedFile( + "\x0A\xF9\x11\x0A7google/developers/knowledge/v1/developerknowledge.proto\x12\x1Egoogle.developers.knowledge.v1\x1A\x17google/api/client.proto\x1A\x1Fgoogle/api/field_behavior.proto\x1A\x19google/api/resource.proto\x1A\x1Fgoogle/protobuf/timestamp.proto\"\xE0\x02\x0A\x08Document\x12\x11\x0A\x04name\x18\x01 \x01(\x09B\x03\xE0A\x08\x12\x10\x0A\x03uri\x18\x02 \x01(\x09B\x03\xE0A\x03\x12\x14\x0A\x07content\x18\x03 \x01(\x09B\x03\xE0A\x03\x12\x18\x0A\x0Bdescription\x18\x04 \x01(\x09B\x03\xE0A\x03\x12\x18\x0A\x0Bdata_source\x18\x05 \x01(\x09B\x03\xE0A\x03\x12\x12\x0A\x05title\x18\x06 \x01(\x09B\x03\xE0A\x03\x124\x0A\x0Bupdate_time\x18\x07 \x01(\x0B2\x1A.google.protobuf.TimestampB\x03\xE0A\x03\x12?\x0A\x04view\x18\x08 \x01(\x0E2,.google.developers.knowledge.v1.DocumentViewB\x03\xE0A\x03:Z\xEAAW\x0A*developerknowledge.googleapis.com/Document\x12\x14documents/{document}*\x09documents2\x08document\"w\x0A\x1BSearchDocumentChunksRequest\x12\x12\x0A\x05query\x18\x01 \x01(\x09B\x03\xE0A\x02\x12\x16\x0A\x09page_size\x18\x02 \x01(\x05B\x03\xE0A\x01\x12\x17\x0A\x0Apage_token\x18\x03 \x01(\x09B\x03\xE0A\x01\x12\x13\x0A\x06filter\x18\x04 \x01(\x09B\x03\xE0A\x01\"|\x0A\x1CSearchDocumentChunksResponse\x12>\x0A\x07results\x18\x01 \x03(\x0B2-.google.developers.knowledge.v1.DocumentChunk\x12\x1C\x0A\x0Fnext_page_token\x18\x02 \x01(\x09B\x03\xE0A\x01\"\x97\x01\x0A\x12GetDocumentRequest\x12@\x0A\x04name\x18\x01 \x01(\x09B2\xE0A\x02\xFAA,\x0A*developerknowledge.googleapis.com/Document\x12?\x0A\x04view\x18\x02 \x01(\x0E2,.google.developers.knowledge.v1.DocumentViewB\x03\xE0A\x01\"\x9E\x01\x0A\x18BatchGetDocumentsRequest\x12A\x0A\x05names\x18\x01 \x03(\x09B2\xE0A\x02\xFAA,\x0A*developerknowledge.googleapis.com/Document\x12?\x0A\x04view\x18\x02 \x01(\x0E2,.google.developers.knowledge.v1.DocumentViewB\x03\xE0A\x01\"X\x0A\x19BatchGetDocumentsResponse\x12;\x0A\x09documents\x18\x01 \x03(\x0B2(.google.developers.knowledge.v1.Document\"\xBB\x01\x0A\x0DDocumentChunk\x12B\x0A\x06parent\x18\x01 \x01(\x09B2\xE0A\x03\xFAA,\x0A*developerknowledge.googleapis.com/Document\x12\x0F\x0A\x02id\x18\x02 \x01(\x09B\x03\xE0A\x03\x12\x14\x0A\x07content\x18\x03 \x01(\x09B\x03\xE0A\x03\x12?\x0A\x08document\x18\x04 \x01(\x0B2(.google.developers.knowledge.v1.DocumentB\x03\xE0A\x03*y\x0A\x0CDocumentView\x12\x1D\x0A\x19DOCUMENT_VIEW_UNSPECIFIED\x10\x00\x12\x17\x0A\x13DOCUMENT_VIEW_BASIC\x10\x01\x12\x16\x0A\x12DOCUMENT_VIEW_FULL\x10\x02\x12\x19\x0A\x15DOCUMENT_VIEW_CONTENT\x10\x032\xEC\x04\x0A\x12DeveloperKnowledge\x12\xBD\x01\x0A\x14SearchDocumentChunks\x12;.google.developers.knowledge.v1.SearchDocumentChunksRequest\x1A<.google.developers.knowledge.v1.SearchDocumentChunksResponse\"*\x82\xD3\xE4\x93\x02\$\x12\"/v1/documents:searchDocumentChunks\x12\x93\x01\x0A\x0BGetDocument\x122.google.developers.knowledge.v1.GetDocumentRequest\x1A(.google.developers.knowledge.v1.Document\"&\xDAA\x04name\x82\xD3\xE4\x93\x02\x19\x12\x17/v1/{name=documents/**}\x12\xA8\x01\x0A\x11BatchGetDocuments\x128.google.developers.knowledge.v1.BatchGetDocumentsRequest\x1A9.google.developers.knowledge.v1.BatchGetDocumentsResponse\"\x1E\x82\xD3\xE4\x93\x02\x18\x12\x16/v1/documents:batchGet\x1AU\xCAA!developerknowledge.googleapis.com\xD2A.https://www.googleapis.com/auth/cloud-platformB\x88\x01\x0A\"com.google.developers.knowledge.v1B\x17DeveloperKnowledgeProtoP\x01ZGgoogle.golang.org/genproto/googleapis/developers/knowledge/v1;knowledgeb\x06proto3" + , true); + + static::$is_initialized = true; + } +} + diff --git a/DevelopersKnowledge/owlbot.py b/DevelopersKnowledge/owlbot.py new file mode 100644 index 000000000000..fae080ac62fd --- /dev/null +++ b/DevelopersKnowledge/owlbot.py @@ -0,0 +1,47 @@ +# Copyright 2024 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""This script is used to synthesize generated parts of this library.""" + +import logging +from pathlib import Path +import subprocess + +import synthtool as s +from synthtool.languages import php +from synthtool import _tracked_paths + +logging.basicConfig(level=logging.DEBUG) + +src = Path(f"../{php.STAGING_DIR}/DevelopersKnowledge").resolve() +dest = Path().resolve() + +# Added so that we can pass copy_excludes in the owlbot_main() call +_tracked_paths.add(src) + +php.owlbot_main(src=src, dest=dest) + +# format generated clients +subprocess.run([ + 'npm', + 'exec', + '--yes', + '--package=@prettier/plugin-php@^0.19', + '--', + 'prettier', + '**/Client/*', + '--write', + '--parser=php', + '--single-quote', + '--print-width=120']) diff --git a/DevelopersKnowledge/phpunit.xml.dist b/DevelopersKnowledge/phpunit.xml.dist new file mode 100644 index 000000000000..af27724f2594 --- /dev/null +++ b/DevelopersKnowledge/phpunit.xml.dist @@ -0,0 +1,16 @@ + + + + + src + + + src/V[!a-zA-Z]* + + + + + tests/Unit + + + diff --git a/DevelopersKnowledge/samples/V1/DeveloperKnowledgeClient/batch_get_documents.php b/DevelopersKnowledge/samples/V1/DeveloperKnowledgeClient/batch_get_documents.php new file mode 100644 index 000000000000..c1f4812761d5 --- /dev/null +++ b/DevelopersKnowledge/samples/V1/DeveloperKnowledgeClient/batch_get_documents.php @@ -0,0 +1,77 @@ +setNames($formattedNames); + + // Call the API and handle any network failures. + try { + /** @var BatchGetDocumentsResponse $response */ + $response = $developerKnowledgeClient->batchGetDocuments($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); + } catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); + } +} + +/** + * Helper to execute the sample. + * + * This sample has been automatically generated and should be regarded as a code + * template only. It will require modifications to work: + * - It may require correct/in-range values for request initialization. + * - It may require specifying regional endpoints when creating the service client, + * please see the apiEndpoint client configuration option for more details. + */ +function callSample(): void +{ + $formattedNamesElement = DeveloperKnowledgeClient::documentName('[DOCUMENT]'); + + batch_get_documents_sample($formattedNamesElement); +} +// [END developerknowledge_v1_generated_DeveloperKnowledge_BatchGetDocuments_sync] diff --git a/DevelopersKnowledge/samples/V1/DeveloperKnowledgeClient/get_document.php b/DevelopersKnowledge/samples/V1/DeveloperKnowledgeClient/get_document.php new file mode 100644 index 000000000000..9564343c9bc5 --- /dev/null +++ b/DevelopersKnowledge/samples/V1/DeveloperKnowledgeClient/get_document.php @@ -0,0 +1,73 @@ +setName($formattedName); + + // Call the API and handle any network failures. + try { + /** @var Document $response */ + $response = $developerKnowledgeClient->getDocument($request); + printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); + } catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); + } +} + +/** + * Helper to execute the sample. + * + * This sample has been automatically generated and should be regarded as a code + * template only. It will require modifications to work: + * - It may require correct/in-range values for request initialization. + * - It may require specifying regional endpoints when creating the service client, + * please see the apiEndpoint client configuration option for more details. + */ +function callSample(): void +{ + $formattedName = DeveloperKnowledgeClient::documentName('[DOCUMENT]'); + + get_document_sample($formattedName); +} +// [END developerknowledge_v1_generated_DeveloperKnowledge_GetDocument_sync] diff --git a/DevelopersKnowledge/samples/V1/DeveloperKnowledgeClient/search_document_chunks.php b/DevelopersKnowledge/samples/V1/DeveloperKnowledgeClient/search_document_chunks.php new file mode 100644 index 000000000000..6eea019ba96a --- /dev/null +++ b/DevelopersKnowledge/samples/V1/DeveloperKnowledgeClient/search_document_chunks.php @@ -0,0 +1,87 @@ +setQuery($query); + + // Call the API and handle any network failures. + try { + /** @var PagedListResponse $response */ + $response = $developerKnowledgeClient->searchDocumentChunks($request); + + /** @var DocumentChunk $element */ + foreach ($response as $element) { + printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString()); + } + } catch (ApiException $ex) { + printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); + } +} + +/** + * Helper to execute the sample. + * + * This sample has been automatically generated and should be regarded as a code + * template only. It will require modifications to work: + * - It may require correct/in-range values for request initialization. + * - It may require specifying regional endpoints when creating the service client, + * please see the apiEndpoint client configuration option for more details. + */ +function callSample(): void +{ + $query = '[QUERY]'; + + search_document_chunks_sample($query); +} +// [END developerknowledge_v1_generated_DeveloperKnowledge_SearchDocumentChunks_sync] diff --git a/DevelopersKnowledge/src/V1/BatchGetDocumentsRequest.php b/DevelopersKnowledge/src/V1/BatchGetDocumentsRequest.php new file mode 100644 index 000000000000..535c5d13f7a7 --- /dev/null +++ b/DevelopersKnowledge/src/V1/BatchGetDocumentsRequest.php @@ -0,0 +1,134 @@ +google.developers.knowledge.v1.BatchGetDocumentsRequest + */ +class BatchGetDocumentsRequest extends \Google\Protobuf\Internal\Message +{ + /** + * Required. Specifies the names of the documents to retrieve. A maximum of 20 + * documents can be retrieved in a batch. The documents are returned in the + * same order as the `names` in the request. + * Format: `documents/{uri_without_scheme}` + * Example: `documents/docs.cloud.google.com/storage/docs/creating-buckets` + * + * Generated from protobuf field repeated string names = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { + */ + private $names; + /** + * Optional. Specifies the + * [DocumentView][google.developers.knowledge.v1.DocumentView] of the + * document. If unspecified, + * [DeveloperKnowledge.BatchGetDocuments][google.developers.knowledge.v1.DeveloperKnowledge.BatchGetDocuments] + * defaults to `DOCUMENT_VIEW_CONTENT`. + * + * Generated from protobuf field .google.developers.knowledge.v1.DocumentView view = 2 [(.google.api.field_behavior) = OPTIONAL]; + */ + protected $view = 0; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string[] $names + * Required. Specifies the names of the documents to retrieve. A maximum of 20 + * documents can be retrieved in a batch. The documents are returned in the + * same order as the `names` in the request. + * Format: `documents/{uri_without_scheme}` + * Example: `documents/docs.cloud.google.com/storage/docs/creating-buckets` + * @type int $view + * Optional. Specifies the + * [DocumentView][google.developers.knowledge.v1.DocumentView] of the + * document. If unspecified, + * [DeveloperKnowledge.BatchGetDocuments][google.developers.knowledge.v1.DeveloperKnowledge.BatchGetDocuments] + * defaults to `DOCUMENT_VIEW_CONTENT`. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Developers\Knowledge\V1\Developerknowledge::initOnce(); + parent::__construct($data); + } + + /** + * Required. Specifies the names of the documents to retrieve. A maximum of 20 + * documents can be retrieved in a batch. The documents are returned in the + * same order as the `names` in the request. + * Format: `documents/{uri_without_scheme}` + * Example: `documents/docs.cloud.google.com/storage/docs/creating-buckets` + * + * Generated from protobuf field repeated string names = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { + * @return RepeatedField + */ + public function getNames() + { + return $this->names; + } + + /** + * Required. Specifies the names of the documents to retrieve. A maximum of 20 + * documents can be retrieved in a batch. The documents are returned in the + * same order as the `names` in the request. + * Format: `documents/{uri_without_scheme}` + * Example: `documents/docs.cloud.google.com/storage/docs/creating-buckets` + * + * Generated from protobuf field repeated string names = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { + * @param string[] $var + * @return $this + */ + public function setNames($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::STRING); + $this->names = $arr; + + return $this; + } + + /** + * Optional. Specifies the + * [DocumentView][google.developers.knowledge.v1.DocumentView] of the + * document. If unspecified, + * [DeveloperKnowledge.BatchGetDocuments][google.developers.knowledge.v1.DeveloperKnowledge.BatchGetDocuments] + * defaults to `DOCUMENT_VIEW_CONTENT`. + * + * Generated from protobuf field .google.developers.knowledge.v1.DocumentView view = 2 [(.google.api.field_behavior) = OPTIONAL]; + * @return int + */ + public function getView() + { + return $this->view; + } + + /** + * Optional. Specifies the + * [DocumentView][google.developers.knowledge.v1.DocumentView] of the + * document. If unspecified, + * [DeveloperKnowledge.BatchGetDocuments][google.developers.knowledge.v1.DeveloperKnowledge.BatchGetDocuments] + * defaults to `DOCUMENT_VIEW_CONTENT`. + * + * Generated from protobuf field .google.developers.knowledge.v1.DocumentView view = 2 [(.google.api.field_behavior) = OPTIONAL]; + * @param int $var + * @return $this + */ + public function setView($var) + { + GPBUtil::checkEnum($var, \Google\Developers\Knowledge\V1\DocumentView::class); + $this->view = $var; + + return $this; + } + +} + diff --git a/DevelopersKnowledge/src/V1/BatchGetDocumentsResponse.php b/DevelopersKnowledge/src/V1/BatchGetDocumentsResponse.php new file mode 100644 index 000000000000..9352f4a5dab9 --- /dev/null +++ b/DevelopersKnowledge/src/V1/BatchGetDocumentsResponse.php @@ -0,0 +1,68 @@ +google.developers.knowledge.v1.BatchGetDocumentsResponse + */ +class BatchGetDocumentsResponse extends \Google\Protobuf\Internal\Message +{ + /** + * Contains the documents requested. + * + * Generated from protobuf field repeated .google.developers.knowledge.v1.Document documents = 1; + */ + private $documents; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type \Google\Developers\Knowledge\V1\Document[] $documents + * Contains the documents requested. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Developers\Knowledge\V1\Developerknowledge::initOnce(); + parent::__construct($data); + } + + /** + * Contains the documents requested. + * + * Generated from protobuf field repeated .google.developers.knowledge.v1.Document documents = 1; + * @return RepeatedField<\Google\Developers\Knowledge\V1\Document> + */ + public function getDocuments() + { + return $this->documents; + } + + /** + * Contains the documents requested. + * + * Generated from protobuf field repeated .google.developers.knowledge.v1.Document documents = 1; + * @param \Google\Developers\Knowledge\V1\Document[] $var + * @return $this + */ + public function setDocuments($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Developers\Knowledge\V1\Document::class); + $this->documents = $arr; + + return $this; + } + +} + diff --git a/DevelopersKnowledge/src/V1/Client/DeveloperKnowledgeClient.php b/DevelopersKnowledge/src/V1/Client/DeveloperKnowledgeClient.php new file mode 100644 index 000000000000..2fcdf882ba4b --- /dev/null +++ b/DevelopersKnowledge/src/V1/Client/DeveloperKnowledgeClient.php @@ -0,0 +1,338 @@ + batchGetDocumentsAsync(BatchGetDocumentsRequest $request, array $optionalArgs = []) + * @method PromiseInterface getDocumentAsync(GetDocumentRequest $request, array $optionalArgs = []) + * @method PromiseInterface searchDocumentChunksAsync(SearchDocumentChunksRequest $request, array $optionalArgs = []) + */ +final class DeveloperKnowledgeClient +{ + use GapicClientTrait; + use ResourceHelperTrait; + + /** The name of the service. */ + private const SERVICE_NAME = 'google.developers.knowledge.v1.DeveloperKnowledge'; + + /** + * The default address of the service. + * + * @deprecated SERVICE_ADDRESS_TEMPLATE should be used instead. + */ + private const SERVICE_ADDRESS = 'developerknowledge.googleapis.com'; + + /** The address template of the service. */ + private const SERVICE_ADDRESS_TEMPLATE = 'developerknowledge.UNIVERSE_DOMAIN'; + + /** The default port of the service. */ + private const DEFAULT_SERVICE_PORT = 443; + + /** The name of the code generator, to be included in the agent header. */ + private const CODEGEN_NAME = 'gapic'; + + /** The default scopes required by the service. */ + public static $serviceScopes = ['https://www.googleapis.com/auth/cloud-platform']; + + private static function getClientDefaults() + { + return [ + 'serviceName' => self::SERVICE_NAME, + 'apiEndpoint' => self::SERVICE_ADDRESS . ':' . self::DEFAULT_SERVICE_PORT, + 'clientConfig' => __DIR__ . '/../resources/developer_knowledge_client_config.json', + 'descriptorsConfigPath' => __DIR__ . '/../resources/developer_knowledge_descriptor_config.php', + 'gcpApiConfigPath' => __DIR__ . '/../resources/developer_knowledge_grpc_config.json', + 'credentialsConfig' => [ + 'defaultScopes' => self::$serviceScopes, + ], + 'transportConfig' => [ + 'rest' => [ + 'restClientConfigPath' => __DIR__ . '/../resources/developer_knowledge_rest_client_config.php', + ], + ], + ]; + } + + /** + * Formats a string containing the fully-qualified path to represent a document + * resource. + * + * @param string $document + * + * @return string The formatted document resource. + */ + public static function documentName(string $document): string + { + return self::getPathTemplate('document')->render([ + 'document' => $document, + ]); + } + + /** + * Parses a formatted name string and returns an associative array of the components in the name. + * The following name formats are supported: + * Template: Pattern + * - document: documents/{document} + * + * The optional $template argument can be supplied to specify a particular pattern, + * and must match one of the templates listed above. If no $template argument is + * provided, or if the $template argument does not match one of the templates + * listed, then parseName will check each of the supported templates, and return + * the first match. + * + * @param string $formattedName The formatted name string + * @param ?string $template Optional name of template to match + * + * @return array An associative array from name component IDs to component values. + * + * @throws ValidationException If $formattedName could not be matched. + */ + public static function parseName(string $formattedName, ?string $template = null): array + { + return self::parseFormattedName($formattedName, $template); + } + + /** + * Constructor. + * + * @param array|ClientOptions $options { + * Optional. Options for configuring the service API wrapper. + * + * @type string $apiEndpoint + * The address of the API remote host. May optionally include the port, formatted + * as ":". Default 'developerknowledge.googleapis.com:443'. + * @type FetchAuthTokenInterface|CredentialsWrapper $credentials + * This option should only be used with a pre-constructed + * {@see FetchAuthTokenInterface} or {@see CredentialsWrapper} object. Note that + * when one of these objects are provided, any settings in $credentialsConfig will + * be ignored. + * **Important**: If you are providing a path to a credentials file, or a decoded + * credentials file as a PHP array, this usage is now DEPRECATED. Providing an + * unvalidated credential configuration to Google APIs can compromise the security + * of your systems and data. It is recommended to create the credentials explicitly + * ``` + * use Google\Auth\Credentials\ServiceAccountCredentials; + * use Google\Developers\Knowledge\V1\DeveloperKnowledgeClient; + * $creds = new ServiceAccountCredentials($scopes, $json); + * $options = new DeveloperKnowledgeClient(['credentials' => $creds]); + * ``` + * {@see + * https://cloud.google.com/docs/authentication/external/externally-sourced-credentials} + * @type array $credentialsConfig + * Options used to configure credentials, including auth token caching, for the + * client. For a full list of supporting configuration options, see + * {@see \Google\ApiCore\CredentialsWrapper::build()} . + * @type bool $disableRetries + * Determines whether or not retries defined by the client configuration should be + * disabled. Defaults to `false`. + * @type string|array $clientConfig + * Client method configuration, including retry settings. This option can be either + * a path to a JSON file, or a PHP array containing the decoded JSON data. By + * default this settings points to the default client config file, which is + * provided in the resources folder. + * @type string|TransportInterface $transport + * The transport used for executing network requests. May be either the string + * `rest` or `grpc`. Defaults to `grpc` if gRPC support is detected on the system. + * *Advanced usage*: Additionally, it is possible to pass in an already + * instantiated {@see \Google\ApiCore\Transport\TransportInterface} object. Note + * that when this object is provided, any settings in $transportConfig, and any + * $apiEndpoint setting, will be ignored. + * @type array $transportConfig + * Configuration options that will be used to construct the transport. Options for + * each supported transport type should be passed in a key for that transport. For + * example: + * $transportConfig = [ + * 'grpc' => [...], + * 'rest' => [...], + * ]; + * See the {@see \Google\ApiCore\Transport\GrpcTransport::build()} and + * {@see \Google\ApiCore\Transport\RestTransport::build()} methods for the + * supported options. + * @type callable $clientCertSource + * A callable which returns the client cert as a string. This can be used to + * provide a certificate and private key to the transport layer for mTLS. + * @type false|LoggerInterface $logger + * A PSR-3 compliant logger. If set to false, logging is disabled, ignoring the + * 'GOOGLE_SDK_PHP_LOGGING' environment flag + * @type string $universeDomain + * The service domain for the client. Defaults to 'googleapis.com'. + * } + * + * @throws ValidationException + */ + public function __construct(array|ClientOptions $options = []) + { + $clientOptions = $this->buildClientOptions($options); + $this->setClientOptions($clientOptions); + } + + /** Handles execution of the async variants for each documented method. */ + public function __call($method, $args) + { + if (substr($method, -5) !== 'Async') { + trigger_error('Call to undefined method ' . __CLASS__ . "::$method()", E_USER_ERROR); + } + + array_unshift($args, substr($method, 0, -5)); + return call_user_func_array([$this, 'startAsyncCall'], $args); + } + + /** + * Retrieves multiple documents, each with its full Markdown content. + * + * The async variant is {@see DeveloperKnowledgeClient::batchGetDocumentsAsync()} . + * + * @example samples/V1/DeveloperKnowledgeClient/batch_get_documents.php + * + * @param BatchGetDocumentsRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return BatchGetDocumentsResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function batchGetDocuments( + BatchGetDocumentsRequest $request, + array $callOptions = [] + ): BatchGetDocumentsResponse { + return $this->startApiCall('BatchGetDocuments', $request, $callOptions)->wait(); + } + + /** + * Retrieves a single document with its full Markdown content. + * + * The async variant is {@see DeveloperKnowledgeClient::getDocumentAsync()} . + * + * @example samples/V1/DeveloperKnowledgeClient/get_document.php + * + * @param GetDocumentRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return Document + * + * @throws ApiException Thrown if the API call fails. + */ + public function getDocument(GetDocumentRequest $request, array $callOptions = []): Document + { + return $this->startApiCall('GetDocument', $request, $callOptions)->wait(); + } + + /** + * Searches for developer knowledge across Google's developer documentation. + * Returns [DocumentChunk][google.developers.knowledge.v1.DocumentChunk]s + * based on the user's query. There may be many chunks from the same + * [Document][google.developers.knowledge.v1.Document]. To retrieve full + * documents, use + * [DeveloperKnowledge.GetDocument][google.developers.knowledge.v1.DeveloperKnowledge.GetDocument] + * or + * [DeveloperKnowledge.BatchGetDocuments][google.developers.knowledge.v1.DeveloperKnowledge.BatchGetDocuments] + * with the + * [DocumentChunk.parent][google.developers.knowledge.v1.DocumentChunk.parent] + * returned in the + * [SearchDocumentChunksResponse.results][google.developers.knowledge.v1.SearchDocumentChunksResponse.results]. + * + * The async variant is + * {@see DeveloperKnowledgeClient::searchDocumentChunksAsync()} . + * + * @example samples/V1/DeveloperKnowledgeClient/search_document_chunks.php + * + * @param SearchDocumentChunksRequest $request A request to house fields associated with the call. + * @param array $callOptions { + * Optional. + * + * @type RetrySettings|array $retrySettings + * Retry settings to use for this call. Can be a {@see RetrySettings} object, or an + * associative array of retry settings parameters. See the documentation on + * {@see RetrySettings} for example usage. + * } + * + * @return PagedListResponse + * + * @throws ApiException Thrown if the API call fails. + */ + public function searchDocumentChunks( + SearchDocumentChunksRequest $request, + array $callOptions = [] + ): PagedListResponse { + return $this->startApiCall('SearchDocumentChunks', $request, $callOptions); + } +} diff --git a/DevelopersKnowledge/src/V1/Document.php b/DevelopersKnowledge/src/V1/Document.php new file mode 100644 index 000000000000..e1e933a323ee --- /dev/null +++ b/DevelopersKnowledge/src/V1/Document.php @@ -0,0 +1,343 @@ +google.developers.knowledge.v1.Document + */ +class Document extends \Google\Protobuf\Internal\Message +{ + /** + * Identifier. Contains the resource name of the document. + * Format: `documents/{uri_without_scheme}` + * Example: `documents/docs.cloud.google.com/storage/docs/creating-buckets` + * + * Generated from protobuf field string name = 1 [(.google.api.field_behavior) = IDENTIFIER]; + */ + protected $name = ''; + /** + * Output only. Provides the URI of the content, such as + * `docs.cloud.google.com/storage/docs/creating-buckets`. + * + * Generated from protobuf field string uri = 2 [(.google.api.field_behavior) = OUTPUT_ONLY]; + */ + protected $uri = ''; + /** + * Output only. Contains the full content of the document in Markdown format. + * + * Generated from protobuf field string content = 3 [(.google.api.field_behavior) = OUTPUT_ONLY]; + */ + protected $content = ''; + /** + * Output only. Provides a description of the document. + * + * Generated from protobuf field string description = 4 [(.google.api.field_behavior) = OUTPUT_ONLY]; + */ + protected $description = ''; + /** + * Output only. Specifies the data source of the document. + * Example data source: `firebase.google.com` + * + * Generated from protobuf field string data_source = 5 [(.google.api.field_behavior) = OUTPUT_ONLY]; + */ + protected $data_source = ''; + /** + * Output only. Provides the title of the document. + * + * Generated from protobuf field string title = 6 [(.google.api.field_behavior) = OUTPUT_ONLY]; + */ + protected $title = ''; + /** + * Output only. Represents the timestamp when the content or metadata of the + * document was last updated. + * + * Generated from protobuf field .google.protobuf.Timestamp update_time = 7 [(.google.api.field_behavior) = OUTPUT_ONLY]; + */ + protected $update_time = null; + /** + * Output only. Specifies the + * [DocumentView][google.developers.knowledge.v1.DocumentView] of the + * document. + * + * Generated from protobuf field .google.developers.knowledge.v1.DocumentView view = 8 [(.google.api.field_behavior) = OUTPUT_ONLY]; + */ + protected $view = 0; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $name + * Identifier. Contains the resource name of the document. + * Format: `documents/{uri_without_scheme}` + * Example: `documents/docs.cloud.google.com/storage/docs/creating-buckets` + * @type string $uri + * Output only. Provides the URI of the content, such as + * `docs.cloud.google.com/storage/docs/creating-buckets`. + * @type string $content + * Output only. Contains the full content of the document in Markdown format. + * @type string $description + * Output only. Provides a description of the document. + * @type string $data_source + * Output only. Specifies the data source of the document. + * Example data source: `firebase.google.com` + * @type string $title + * Output only. Provides the title of the document. + * @type \Google\Protobuf\Timestamp $update_time + * Output only. Represents the timestamp when the content or metadata of the + * document was last updated. + * @type int $view + * Output only. Specifies the + * [DocumentView][google.developers.knowledge.v1.DocumentView] of the + * document. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Developers\Knowledge\V1\Developerknowledge::initOnce(); + parent::__construct($data); + } + + /** + * Identifier. Contains the resource name of the document. + * Format: `documents/{uri_without_scheme}` + * Example: `documents/docs.cloud.google.com/storage/docs/creating-buckets` + * + * Generated from protobuf field string name = 1 [(.google.api.field_behavior) = IDENTIFIER]; + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Identifier. Contains the resource name of the document. + * Format: `documents/{uri_without_scheme}` + * Example: `documents/docs.cloud.google.com/storage/docs/creating-buckets` + * + * Generated from protobuf field string name = 1 [(.google.api.field_behavior) = IDENTIFIER]; + * @param string $var + * @return $this + */ + public function setName($var) + { + GPBUtil::checkString($var, True); + $this->name = $var; + + return $this; + } + + /** + * Output only. Provides the URI of the content, such as + * `docs.cloud.google.com/storage/docs/creating-buckets`. + * + * Generated from protobuf field string uri = 2 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @return string + */ + public function getUri() + { + return $this->uri; + } + + /** + * Output only. Provides the URI of the content, such as + * `docs.cloud.google.com/storage/docs/creating-buckets`. + * + * Generated from protobuf field string uri = 2 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @param string $var + * @return $this + */ + public function setUri($var) + { + GPBUtil::checkString($var, True); + $this->uri = $var; + + return $this; + } + + /** + * Output only. Contains the full content of the document in Markdown format. + * + * Generated from protobuf field string content = 3 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @return string + */ + public function getContent() + { + return $this->content; + } + + /** + * Output only. Contains the full content of the document in Markdown format. + * + * Generated from protobuf field string content = 3 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @param string $var + * @return $this + */ + public function setContent($var) + { + GPBUtil::checkString($var, True); + $this->content = $var; + + return $this; + } + + /** + * Output only. Provides a description of the document. + * + * Generated from protobuf field string description = 4 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @return string + */ + public function getDescription() + { + return $this->description; + } + + /** + * Output only. Provides a description of the document. + * + * Generated from protobuf field string description = 4 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @param string $var + * @return $this + */ + public function setDescription($var) + { + GPBUtil::checkString($var, True); + $this->description = $var; + + return $this; + } + + /** + * Output only. Specifies the data source of the document. + * Example data source: `firebase.google.com` + * + * Generated from protobuf field string data_source = 5 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @return string + */ + public function getDataSource() + { + return $this->data_source; + } + + /** + * Output only. Specifies the data source of the document. + * Example data source: `firebase.google.com` + * + * Generated from protobuf field string data_source = 5 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @param string $var + * @return $this + */ + public function setDataSource($var) + { + GPBUtil::checkString($var, True); + $this->data_source = $var; + + return $this; + } + + /** + * Output only. Provides the title of the document. + * + * Generated from protobuf field string title = 6 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @return string + */ + public function getTitle() + { + return $this->title; + } + + /** + * Output only. Provides the title of the document. + * + * Generated from protobuf field string title = 6 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @param string $var + * @return $this + */ + public function setTitle($var) + { + GPBUtil::checkString($var, True); + $this->title = $var; + + return $this; + } + + /** + * Output only. Represents the timestamp when the content or metadata of the + * document was last updated. + * + * Generated from protobuf field .google.protobuf.Timestamp update_time = 7 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @return \Google\Protobuf\Timestamp|null + */ + public function getUpdateTime() + { + return $this->update_time; + } + + public function hasUpdateTime() + { + return isset($this->update_time); + } + + public function clearUpdateTime() + { + unset($this->update_time); + } + + /** + * Output only. Represents the timestamp when the content or metadata of the + * document was last updated. + * + * Generated from protobuf field .google.protobuf.Timestamp update_time = 7 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @param \Google\Protobuf\Timestamp $var + * @return $this + */ + public function setUpdateTime($var) + { + GPBUtil::checkMessage($var, \Google\Protobuf\Timestamp::class); + $this->update_time = $var; + + return $this; + } + + /** + * Output only. Specifies the + * [DocumentView][google.developers.knowledge.v1.DocumentView] of the + * document. + * + * Generated from protobuf field .google.developers.knowledge.v1.DocumentView view = 8 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @return int + */ + public function getView() + { + return $this->view; + } + + /** + * Output only. Specifies the + * [DocumentView][google.developers.knowledge.v1.DocumentView] of the + * document. + * + * Generated from protobuf field .google.developers.knowledge.v1.DocumentView view = 8 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @param int $var + * @return $this + */ + public function setView($var) + { + GPBUtil::checkEnum($var, \Google\Developers\Knowledge\V1\DocumentView::class); + $this->view = $var; + + return $this; + } + +} + diff --git a/DevelopersKnowledge/src/V1/DocumentChunk.php b/DevelopersKnowledge/src/V1/DocumentChunk.php new file mode 100644 index 000000000000..e8895fa575a3 --- /dev/null +++ b/DevelopersKnowledge/src/V1/DocumentChunk.php @@ -0,0 +1,252 @@ +google.developers.knowledge.v1.DocumentChunk + */ +class DocumentChunk extends \Google\Protobuf\Internal\Message +{ + /** + * Output only. Contains the resource name of the document this chunk is from. + * Format: `documents/{uri_without_scheme}` + * Example: `documents/docs.cloud.google.com/storage/docs/creating-buckets` + * + * Generated from protobuf field string parent = 1 [(.google.api.field_behavior) = OUTPUT_ONLY, (.google.api.resource_reference) = { + */ + protected $parent = ''; + /** + * Output only. Specifies the ID of this chunk within the document. The chunk + * ID is unique within a document, but not globally unique across documents. + * The chunk ID is not stable and may change over time. + * + * Generated from protobuf field string id = 2 [(.google.api.field_behavior) = OUTPUT_ONLY]; + */ + protected $id = ''; + /** + * Output only. Contains the content of the document chunk. + * + * Generated from protobuf field string content = 3 [(.google.api.field_behavior) = OUTPUT_ONLY]; + */ + protected $content = ''; + /** + * Output only. Represents metadata about the + * [Document][google.developers.knowledge.v1.Document] this chunk is from. The + * [DocumentView][google.developers.knowledge.v1.DocumentView] of this + * [Document][google.developers.knowledge.v1.Document] message will be set to + * `DOCUMENT_VIEW_BASIC`. It is included here for convenience so that clients + * do not need to call + * [DeveloperKnowledge.GetDocument][google.developers.knowledge.v1.DeveloperKnowledge.GetDocument] + * or + * [DeveloperKnowledge.BatchGetDocuments][google.developers.knowledge.v1.DeveloperKnowledge.BatchGetDocuments] + * if they only need the metadata fields. Otherwise, clients should use + * [DeveloperKnowledge.GetDocument][google.developers.knowledge.v1.DeveloperKnowledge.GetDocument] + * or + * [DeveloperKnowledge.BatchGetDocuments][google.developers.knowledge.v1.DeveloperKnowledge.BatchGetDocuments] + * to fetch the full document content. + * + * Generated from protobuf field .google.developers.knowledge.v1.Document document = 4 [(.google.api.field_behavior) = OUTPUT_ONLY]; + */ + protected $document = null; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $parent + * Output only. Contains the resource name of the document this chunk is from. + * Format: `documents/{uri_without_scheme}` + * Example: `documents/docs.cloud.google.com/storage/docs/creating-buckets` + * @type string $id + * Output only. Specifies the ID of this chunk within the document. The chunk + * ID is unique within a document, but not globally unique across documents. + * The chunk ID is not stable and may change over time. + * @type string $content + * Output only. Contains the content of the document chunk. + * @type \Google\Developers\Knowledge\V1\Document $document + * Output only. Represents metadata about the + * [Document][google.developers.knowledge.v1.Document] this chunk is from. The + * [DocumentView][google.developers.knowledge.v1.DocumentView] of this + * [Document][google.developers.knowledge.v1.Document] message will be set to + * `DOCUMENT_VIEW_BASIC`. It is included here for convenience so that clients + * do not need to call + * [DeveloperKnowledge.GetDocument][google.developers.knowledge.v1.DeveloperKnowledge.GetDocument] + * or + * [DeveloperKnowledge.BatchGetDocuments][google.developers.knowledge.v1.DeveloperKnowledge.BatchGetDocuments] + * if they only need the metadata fields. Otherwise, clients should use + * [DeveloperKnowledge.GetDocument][google.developers.knowledge.v1.DeveloperKnowledge.GetDocument] + * or + * [DeveloperKnowledge.BatchGetDocuments][google.developers.knowledge.v1.DeveloperKnowledge.BatchGetDocuments] + * to fetch the full document content. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Developers\Knowledge\V1\Developerknowledge::initOnce(); + parent::__construct($data); + } + + /** + * Output only. Contains the resource name of the document this chunk is from. + * Format: `documents/{uri_without_scheme}` + * Example: `documents/docs.cloud.google.com/storage/docs/creating-buckets` + * + * Generated from protobuf field string parent = 1 [(.google.api.field_behavior) = OUTPUT_ONLY, (.google.api.resource_reference) = { + * @return string + */ + public function getParent() + { + return $this->parent; + } + + /** + * Output only. Contains the resource name of the document this chunk is from. + * Format: `documents/{uri_without_scheme}` + * Example: `documents/docs.cloud.google.com/storage/docs/creating-buckets` + * + * Generated from protobuf field string parent = 1 [(.google.api.field_behavior) = OUTPUT_ONLY, (.google.api.resource_reference) = { + * @param string $var + * @return $this + */ + public function setParent($var) + { + GPBUtil::checkString($var, True); + $this->parent = $var; + + return $this; + } + + /** + * Output only. Specifies the ID of this chunk within the document. The chunk + * ID is unique within a document, but not globally unique across documents. + * The chunk ID is not stable and may change over time. + * + * Generated from protobuf field string id = 2 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @return string + */ + public function getId() + { + return $this->id; + } + + /** + * Output only. Specifies the ID of this chunk within the document. The chunk + * ID is unique within a document, but not globally unique across documents. + * The chunk ID is not stable and may change over time. + * + * Generated from protobuf field string id = 2 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @param string $var + * @return $this + */ + public function setId($var) + { + GPBUtil::checkString($var, True); + $this->id = $var; + + return $this; + } + + /** + * Output only. Contains the content of the document chunk. + * + * Generated from protobuf field string content = 3 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @return string + */ + public function getContent() + { + return $this->content; + } + + /** + * Output only. Contains the content of the document chunk. + * + * Generated from protobuf field string content = 3 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @param string $var + * @return $this + */ + public function setContent($var) + { + GPBUtil::checkString($var, True); + $this->content = $var; + + return $this; + } + + /** + * Output only. Represents metadata about the + * [Document][google.developers.knowledge.v1.Document] this chunk is from. The + * [DocumentView][google.developers.knowledge.v1.DocumentView] of this + * [Document][google.developers.knowledge.v1.Document] message will be set to + * `DOCUMENT_VIEW_BASIC`. It is included here for convenience so that clients + * do not need to call + * [DeveloperKnowledge.GetDocument][google.developers.knowledge.v1.DeveloperKnowledge.GetDocument] + * or + * [DeveloperKnowledge.BatchGetDocuments][google.developers.knowledge.v1.DeveloperKnowledge.BatchGetDocuments] + * if they only need the metadata fields. Otherwise, clients should use + * [DeveloperKnowledge.GetDocument][google.developers.knowledge.v1.DeveloperKnowledge.GetDocument] + * or + * [DeveloperKnowledge.BatchGetDocuments][google.developers.knowledge.v1.DeveloperKnowledge.BatchGetDocuments] + * to fetch the full document content. + * + * Generated from protobuf field .google.developers.knowledge.v1.Document document = 4 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @return \Google\Developers\Knowledge\V1\Document|null + */ + public function getDocument() + { + return $this->document; + } + + public function hasDocument() + { + return isset($this->document); + } + + public function clearDocument() + { + unset($this->document); + } + + /** + * Output only. Represents metadata about the + * [Document][google.developers.knowledge.v1.Document] this chunk is from. The + * [DocumentView][google.developers.knowledge.v1.DocumentView] of this + * [Document][google.developers.knowledge.v1.Document] message will be set to + * `DOCUMENT_VIEW_BASIC`. It is included here for convenience so that clients + * do not need to call + * [DeveloperKnowledge.GetDocument][google.developers.knowledge.v1.DeveloperKnowledge.GetDocument] + * or + * [DeveloperKnowledge.BatchGetDocuments][google.developers.knowledge.v1.DeveloperKnowledge.BatchGetDocuments] + * if they only need the metadata fields. Otherwise, clients should use + * [DeveloperKnowledge.GetDocument][google.developers.knowledge.v1.DeveloperKnowledge.GetDocument] + * or + * [DeveloperKnowledge.BatchGetDocuments][google.developers.knowledge.v1.DeveloperKnowledge.BatchGetDocuments] + * to fetch the full document content. + * + * Generated from protobuf field .google.developers.knowledge.v1.Document document = 4 [(.google.api.field_behavior) = OUTPUT_ONLY]; + * @param \Google\Developers\Knowledge\V1\Document $var + * @return $this + */ + public function setDocument($var) + { + GPBUtil::checkMessage($var, \Google\Developers\Knowledge\V1\Document::class); + $this->document = $var; + + return $this; + } + +} + diff --git a/DevelopersKnowledge/src/V1/DocumentView.php b/DevelopersKnowledge/src/V1/DocumentView.php new file mode 100644 index 000000000000..72939ed3075e --- /dev/null +++ b/DevelopersKnowledge/src/V1/DocumentView.php @@ -0,0 +1,84 @@ +google.developers.knowledge.v1.DocumentView + */ +class DocumentView +{ + /** + * The default / unset value. See each API method for its default value if + * [DocumentView][google.developers.knowledge.v1.DocumentView] is not + * specified. + * + * Generated from protobuf enum DOCUMENT_VIEW_UNSPECIFIED = 0; + */ + const DOCUMENT_VIEW_UNSPECIFIED = 0; + /** + * Includes only the basic metadata fields: + * - `name` + * - `uri` + * - `data_source` + * - `title` + * - `description` + * - `update_time` + * - `view` + * This is the default of view for + * [DeveloperKnowledge.SearchDocumentChunks][google.developers.knowledge.v1.DeveloperKnowledge.SearchDocumentChunks]. + * + * Generated from protobuf enum DOCUMENT_VIEW_BASIC = 1; + */ + const DOCUMENT_VIEW_BASIC = 1; + /** + * Includes all [Document][google.developers.knowledge.v1.Document] fields. + * + * Generated from protobuf enum DOCUMENT_VIEW_FULL = 2; + */ + const DOCUMENT_VIEW_FULL = 2; + /** + * Includes the `DOCUMENT_VIEW_BASIC` fields and the `content` field. + * This is the default of view for + * [DeveloperKnowledge.GetDocument][google.developers.knowledge.v1.DeveloperKnowledge.GetDocument] + * and + * [DeveloperKnowledge.BatchGetDocuments][google.developers.knowledge.v1.DeveloperKnowledge.BatchGetDocuments]. + * + * Generated from protobuf enum DOCUMENT_VIEW_CONTENT = 3; + */ + const DOCUMENT_VIEW_CONTENT = 3; + + private static $valueToName = [ + self::DOCUMENT_VIEW_UNSPECIFIED => 'DOCUMENT_VIEW_UNSPECIFIED', + self::DOCUMENT_VIEW_BASIC => 'DOCUMENT_VIEW_BASIC', + self::DOCUMENT_VIEW_FULL => 'DOCUMENT_VIEW_FULL', + self::DOCUMENT_VIEW_CONTENT => 'DOCUMENT_VIEW_CONTENT', + ]; + + public static function name($value) + { + if (!isset(self::$valueToName[$value])) { + throw new UnexpectedValueException(sprintf( + 'Enum %s has no name defined for value %s', __CLASS__, $value)); + } + return self::$valueToName[$value]; + } + + + public static function value($name) + { + $const = __CLASS__ . '::' . strtoupper($name); + if (!defined($const)) { + throw new UnexpectedValueException(sprintf( + 'Enum %s has no value defined for name %s', __CLASS__, $name)); + } + return constant($const); + } +} + diff --git a/DevelopersKnowledge/src/V1/GetDocumentRequest.php b/DevelopersKnowledge/src/V1/GetDocumentRequest.php new file mode 100644 index 000000000000..2b4ce5f16d9e --- /dev/null +++ b/DevelopersKnowledge/src/V1/GetDocumentRequest.php @@ -0,0 +1,142 @@ +google.developers.knowledge.v1.GetDocumentRequest + */ +class GetDocumentRequest extends \Google\Protobuf\Internal\Message +{ + /** + * Required. Specifies the name of the document to retrieve. + * Format: `documents/{uri_without_scheme}` + * Example: `documents/docs.cloud.google.com/storage/docs/creating-buckets` + * + * Generated from protobuf field string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { + */ + protected $name = ''; + /** + * Optional. Specifies the + * [DocumentView][google.developers.knowledge.v1.DocumentView] of the + * document. If unspecified, + * [DeveloperKnowledge.GetDocument][google.developers.knowledge.v1.DeveloperKnowledge.GetDocument] + * defaults to `DOCUMENT_VIEW_CONTENT`. + * + * Generated from protobuf field .google.developers.knowledge.v1.DocumentView view = 2 [(.google.api.field_behavior) = OPTIONAL]; + */ + protected $view = 0; + + /** + * @param string $name Required. Specifies the name of the document to retrieve. + * Format: `documents/{uri_without_scheme}` + * Example: `documents/docs.cloud.google.com/storage/docs/creating-buckets` + * Please see {@see DeveloperKnowledgeClient::documentName()} for help formatting this field. + * + * @return \Google\Developers\Knowledge\V1\GetDocumentRequest + * + * @experimental + */ + public static function build(string $name): self + { + return (new self()) + ->setName($name); + } + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $name + * Required. Specifies the name of the document to retrieve. + * Format: `documents/{uri_without_scheme}` + * Example: `documents/docs.cloud.google.com/storage/docs/creating-buckets` + * @type int $view + * Optional. Specifies the + * [DocumentView][google.developers.knowledge.v1.DocumentView] of the + * document. If unspecified, + * [DeveloperKnowledge.GetDocument][google.developers.knowledge.v1.DeveloperKnowledge.GetDocument] + * defaults to `DOCUMENT_VIEW_CONTENT`. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Developers\Knowledge\V1\Developerknowledge::initOnce(); + parent::__construct($data); + } + + /** + * Required. Specifies the name of the document to retrieve. + * Format: `documents/{uri_without_scheme}` + * Example: `documents/docs.cloud.google.com/storage/docs/creating-buckets` + * + * Generated from protobuf field string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Required. Specifies the name of the document to retrieve. + * Format: `documents/{uri_without_scheme}` + * Example: `documents/docs.cloud.google.com/storage/docs/creating-buckets` + * + * Generated from protobuf field string name = 1 [(.google.api.field_behavior) = REQUIRED, (.google.api.resource_reference) = { + * @param string $var + * @return $this + */ + public function setName($var) + { + GPBUtil::checkString($var, True); + $this->name = $var; + + return $this; + } + + /** + * Optional. Specifies the + * [DocumentView][google.developers.knowledge.v1.DocumentView] of the + * document. If unspecified, + * [DeveloperKnowledge.GetDocument][google.developers.knowledge.v1.DeveloperKnowledge.GetDocument] + * defaults to `DOCUMENT_VIEW_CONTENT`. + * + * Generated from protobuf field .google.developers.knowledge.v1.DocumentView view = 2 [(.google.api.field_behavior) = OPTIONAL]; + * @return int + */ + public function getView() + { + return $this->view; + } + + /** + * Optional. Specifies the + * [DocumentView][google.developers.knowledge.v1.DocumentView] of the + * document. If unspecified, + * [DeveloperKnowledge.GetDocument][google.developers.knowledge.v1.DeveloperKnowledge.GetDocument] + * defaults to `DOCUMENT_VIEW_CONTENT`. + * + * Generated from protobuf field .google.developers.knowledge.v1.DocumentView view = 2 [(.google.api.field_behavior) = OPTIONAL]; + * @param int $var + * @return $this + */ + public function setView($var) + { + GPBUtil::checkEnum($var, \Google\Developers\Knowledge\V1\DocumentView::class); + $this->view = $var; + + return $this; + } + +} + diff --git a/DevelopersKnowledge/src/V1/SearchDocumentChunksRequest.php b/DevelopersKnowledge/src/V1/SearchDocumentChunksRequest.php new file mode 100644 index 000000000000..a4e8912ce468 --- /dev/null +++ b/DevelopersKnowledge/src/V1/SearchDocumentChunksRequest.php @@ -0,0 +1,322 @@ +google.developers.knowledge.v1.SearchDocumentChunksRequest + */ +class SearchDocumentChunksRequest extends \Google\Protobuf\Internal\Message +{ + /** + * Required. Provides the raw query string provided by the user, such as "How + * to create a Cloud Storage bucket?". + * + * Generated from protobuf field string query = 1 [(.google.api.field_behavior) = REQUIRED]; + */ + protected $query = ''; + /** + * Optional. Specifies the maximum number of results to return. The service + * may return fewer than this value. + * If unspecified, at most 5 results will be returned. + * The maximum value is 20; values above 20 will result in an INVALID_ARGUMENT + * error. + * + * Generated from protobuf field int32 page_size = 2 [(.google.api.field_behavior) = OPTIONAL]; + */ + protected $page_size = 0; + /** + * Optional. Contains a page token, received from a previous + * `SearchDocumentChunks` call. Provide this to retrieve the subsequent page. + * + * Generated from protobuf field string page_token = 3 [(.google.api.field_behavior) = OPTIONAL]; + */ + protected $page_token = ''; + /** + * Optional. Applies a strict filter to the search results. The expression + * supports a subset of the syntax described at https://google.aip.dev/160. + * While `SearchDocumentChunks` returns + * [DocumentChunk][google.developers.knowledge.v1.DocumentChunk]s, the filter + * is applied to `DocumentChunk.document` fields. + * Supported fields for filtering: + * * `data_source` (STRING): The source of the document, e.g. + * `docs.cloud.google.com`. See + * https://developers.google.com/knowledge/reference/corpus-reference for + * the complete list of data sources in the corpus. + * * `update_time` (TIMESTAMP): The timestamp of when the document was last + * meaningfully updated. A meaningful update is one that changes document's + * markdown content or metadata. + * * `uri` (STRING): The document URI, e.g. + * `https://docs.cloud.google.com/bigquery/docs/tables`. + * STRING fields support `=` (equals) and `!=` (not equals) operators for + * **exact match** on the whole string. Partial match, prefix match, and + * regexp match are not supported. + * TIMESTAMP fields support `=`, `<`, `<=`, `>`, and `>=` operators. + * Timestamps must be in RFC-3339 format, e.g., `"2025-01-01T00:00:00Z"`. + * You can combine expressions using `AND`, `OR`, and `NOT` (or `-`) logical + * operators. `OR` has higher precedence than `AND`. Use parentheses for + * explicit precedence grouping. + * Examples: + * * `data_source = "docs.cloud.google.com" OR data_source = + * "firebase.google.com"` + * * `data_source != "firebase.google.com"` + * * `update_time < "2024-01-01T00:00:00Z"` + * * `update_time >= "2025-01-22T00:00:00Z" AND (data_source = + * "developer.chrome.com" OR data_source = "web.dev")` + * * `uri = "https://docs.cloud.google.com/release-notes"` + * The `filter` string must not exceed 500 characters; values longer than 500 + * characters will result in an `INVALID_ARGUMENT` error. + * + * Generated from protobuf field string filter = 4 [(.google.api.field_behavior) = OPTIONAL]; + */ + protected $filter = ''; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type string $query + * Required. Provides the raw query string provided by the user, such as "How + * to create a Cloud Storage bucket?". + * @type int $page_size + * Optional. Specifies the maximum number of results to return. The service + * may return fewer than this value. + * If unspecified, at most 5 results will be returned. + * The maximum value is 20; values above 20 will result in an INVALID_ARGUMENT + * error. + * @type string $page_token + * Optional. Contains a page token, received from a previous + * `SearchDocumentChunks` call. Provide this to retrieve the subsequent page. + * @type string $filter + * Optional. Applies a strict filter to the search results. The expression + * supports a subset of the syntax described at https://google.aip.dev/160. + * While `SearchDocumentChunks` returns + * [DocumentChunk][google.developers.knowledge.v1.DocumentChunk]s, the filter + * is applied to `DocumentChunk.document` fields. + * Supported fields for filtering: + * * `data_source` (STRING): The source of the document, e.g. + * `docs.cloud.google.com`. See + * https://developers.google.com/knowledge/reference/corpus-reference for + * the complete list of data sources in the corpus. + * * `update_time` (TIMESTAMP): The timestamp of when the document was last + * meaningfully updated. A meaningful update is one that changes document's + * markdown content or metadata. + * * `uri` (STRING): The document URI, e.g. + * `https://docs.cloud.google.com/bigquery/docs/tables`. + * STRING fields support `=` (equals) and `!=` (not equals) operators for + * **exact match** on the whole string. Partial match, prefix match, and + * regexp match are not supported. + * TIMESTAMP fields support `=`, `<`, `<=`, `>`, and `>=` operators. + * Timestamps must be in RFC-3339 format, e.g., `"2025-01-01T00:00:00Z"`. + * You can combine expressions using `AND`, `OR`, and `NOT` (or `-`) logical + * operators. `OR` has higher precedence than `AND`. Use parentheses for + * explicit precedence grouping. + * Examples: + * * `data_source = "docs.cloud.google.com" OR data_source = + * "firebase.google.com"` + * * `data_source != "firebase.google.com"` + * * `update_time < "2024-01-01T00:00:00Z"` + * * `update_time >= "2025-01-22T00:00:00Z" AND (data_source = + * "developer.chrome.com" OR data_source = "web.dev")` + * * `uri = "https://docs.cloud.google.com/release-notes"` + * The `filter` string must not exceed 500 characters; values longer than 500 + * characters will result in an `INVALID_ARGUMENT` error. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Developers\Knowledge\V1\Developerknowledge::initOnce(); + parent::__construct($data); + } + + /** + * Required. Provides the raw query string provided by the user, such as "How + * to create a Cloud Storage bucket?". + * + * Generated from protobuf field string query = 1 [(.google.api.field_behavior) = REQUIRED]; + * @return string + */ + public function getQuery() + { + return $this->query; + } + + /** + * Required. Provides the raw query string provided by the user, such as "How + * to create a Cloud Storage bucket?". + * + * Generated from protobuf field string query = 1 [(.google.api.field_behavior) = REQUIRED]; + * @param string $var + * @return $this + */ + public function setQuery($var) + { + GPBUtil::checkString($var, True); + $this->query = $var; + + return $this; + } + + /** + * Optional. Specifies the maximum number of results to return. The service + * may return fewer than this value. + * If unspecified, at most 5 results will be returned. + * The maximum value is 20; values above 20 will result in an INVALID_ARGUMENT + * error. + * + * Generated from protobuf field int32 page_size = 2 [(.google.api.field_behavior) = OPTIONAL]; + * @return int + */ + public function getPageSize() + { + return $this->page_size; + } + + /** + * Optional. Specifies the maximum number of results to return. The service + * may return fewer than this value. + * If unspecified, at most 5 results will be returned. + * The maximum value is 20; values above 20 will result in an INVALID_ARGUMENT + * error. + * + * Generated from protobuf field int32 page_size = 2 [(.google.api.field_behavior) = OPTIONAL]; + * @param int $var + * @return $this + */ + public function setPageSize($var) + { + GPBUtil::checkInt32($var); + $this->page_size = $var; + + return $this; + } + + /** + * Optional. Contains a page token, received from a previous + * `SearchDocumentChunks` call. Provide this to retrieve the subsequent page. + * + * Generated from protobuf field string page_token = 3 [(.google.api.field_behavior) = OPTIONAL]; + * @return string + */ + public function getPageToken() + { + return $this->page_token; + } + + /** + * Optional. Contains a page token, received from a previous + * `SearchDocumentChunks` call. Provide this to retrieve the subsequent page. + * + * Generated from protobuf field string page_token = 3 [(.google.api.field_behavior) = OPTIONAL]; + * @param string $var + * @return $this + */ + public function setPageToken($var) + { + GPBUtil::checkString($var, True); + $this->page_token = $var; + + return $this; + } + + /** + * Optional. Applies a strict filter to the search results. The expression + * supports a subset of the syntax described at https://google.aip.dev/160. + * While `SearchDocumentChunks` returns + * [DocumentChunk][google.developers.knowledge.v1.DocumentChunk]s, the filter + * is applied to `DocumentChunk.document` fields. + * Supported fields for filtering: + * * `data_source` (STRING): The source of the document, e.g. + * `docs.cloud.google.com`. See + * https://developers.google.com/knowledge/reference/corpus-reference for + * the complete list of data sources in the corpus. + * * `update_time` (TIMESTAMP): The timestamp of when the document was last + * meaningfully updated. A meaningful update is one that changes document's + * markdown content or metadata. + * * `uri` (STRING): The document URI, e.g. + * `https://docs.cloud.google.com/bigquery/docs/tables`. + * STRING fields support `=` (equals) and `!=` (not equals) operators for + * **exact match** on the whole string. Partial match, prefix match, and + * regexp match are not supported. + * TIMESTAMP fields support `=`, `<`, `<=`, `>`, and `>=` operators. + * Timestamps must be in RFC-3339 format, e.g., `"2025-01-01T00:00:00Z"`. + * You can combine expressions using `AND`, `OR`, and `NOT` (or `-`) logical + * operators. `OR` has higher precedence than `AND`. Use parentheses for + * explicit precedence grouping. + * Examples: + * * `data_source = "docs.cloud.google.com" OR data_source = + * "firebase.google.com"` + * * `data_source != "firebase.google.com"` + * * `update_time < "2024-01-01T00:00:00Z"` + * * `update_time >= "2025-01-22T00:00:00Z" AND (data_source = + * "developer.chrome.com" OR data_source = "web.dev")` + * * `uri = "https://docs.cloud.google.com/release-notes"` + * The `filter` string must not exceed 500 characters; values longer than 500 + * characters will result in an `INVALID_ARGUMENT` error. + * + * Generated from protobuf field string filter = 4 [(.google.api.field_behavior) = OPTIONAL]; + * @return string + */ + public function getFilter() + { + return $this->filter; + } + + /** + * Optional. Applies a strict filter to the search results. The expression + * supports a subset of the syntax described at https://google.aip.dev/160. + * While `SearchDocumentChunks` returns + * [DocumentChunk][google.developers.knowledge.v1.DocumentChunk]s, the filter + * is applied to `DocumentChunk.document` fields. + * Supported fields for filtering: + * * `data_source` (STRING): The source of the document, e.g. + * `docs.cloud.google.com`. See + * https://developers.google.com/knowledge/reference/corpus-reference for + * the complete list of data sources in the corpus. + * * `update_time` (TIMESTAMP): The timestamp of when the document was last + * meaningfully updated. A meaningful update is one that changes document's + * markdown content or metadata. + * * `uri` (STRING): The document URI, e.g. + * `https://docs.cloud.google.com/bigquery/docs/tables`. + * STRING fields support `=` (equals) and `!=` (not equals) operators for + * **exact match** on the whole string. Partial match, prefix match, and + * regexp match are not supported. + * TIMESTAMP fields support `=`, `<`, `<=`, `>`, and `>=` operators. + * Timestamps must be in RFC-3339 format, e.g., `"2025-01-01T00:00:00Z"`. + * You can combine expressions using `AND`, `OR`, and `NOT` (or `-`) logical + * operators. `OR` has higher precedence than `AND`. Use parentheses for + * explicit precedence grouping. + * Examples: + * * `data_source = "docs.cloud.google.com" OR data_source = + * "firebase.google.com"` + * * `data_source != "firebase.google.com"` + * * `update_time < "2024-01-01T00:00:00Z"` + * * `update_time >= "2025-01-22T00:00:00Z" AND (data_source = + * "developer.chrome.com" OR data_source = "web.dev")` + * * `uri = "https://docs.cloud.google.com/release-notes"` + * The `filter` string must not exceed 500 characters; values longer than 500 + * characters will result in an `INVALID_ARGUMENT` error. + * + * Generated from protobuf field string filter = 4 [(.google.api.field_behavior) = OPTIONAL]; + * @param string $var + * @return $this + */ + public function setFilter($var) + { + GPBUtil::checkString($var, True); + $this->filter = $var; + + return $this; + } + +} + diff --git a/DevelopersKnowledge/src/V1/SearchDocumentChunksResponse.php b/DevelopersKnowledge/src/V1/SearchDocumentChunksResponse.php new file mode 100644 index 000000000000..0e0a7dca389b --- /dev/null +++ b/DevelopersKnowledge/src/V1/SearchDocumentChunksResponse.php @@ -0,0 +1,138 @@ +google.developers.knowledge.v1.SearchDocumentChunksResponse + */ +class SearchDocumentChunksResponse extends \Google\Protobuf\Internal\Message +{ + /** + * Contains the search results for the given query. Each + * [DocumentChunk][google.developers.knowledge.v1.DocumentChunk] in this list + * contains a snippet of content relevant to the search query. Use the + * [DocumentChunk.parent][google.developers.knowledge.v1.DocumentChunk.parent] + * field of each result with + * [DeveloperKnowledge.GetDocument][google.developers.knowledge.v1.DeveloperKnowledge.GetDocument] + * or + * [DeveloperKnowledge.BatchGetDocuments][google.developers.knowledge.v1.DeveloperKnowledge.BatchGetDocuments] + * to retrieve the full document content. + * + * Generated from protobuf field repeated .google.developers.knowledge.v1.DocumentChunk results = 1; + */ + private $results; + /** + * Optional. Provides a token that can be sent as `page_token` to retrieve the + * next page. If this field is omitted, there are no subsequent pages. + * + * Generated from protobuf field string next_page_token = 2 [(.google.api.field_behavior) = OPTIONAL]; + */ + protected $next_page_token = ''; + + /** + * Constructor. + * + * @param array $data { + * Optional. Data for populating the Message object. + * + * @type \Google\Developers\Knowledge\V1\DocumentChunk[] $results + * Contains the search results for the given query. Each + * [DocumentChunk][google.developers.knowledge.v1.DocumentChunk] in this list + * contains a snippet of content relevant to the search query. Use the + * [DocumentChunk.parent][google.developers.knowledge.v1.DocumentChunk.parent] + * field of each result with + * [DeveloperKnowledge.GetDocument][google.developers.knowledge.v1.DeveloperKnowledge.GetDocument] + * or + * [DeveloperKnowledge.BatchGetDocuments][google.developers.knowledge.v1.DeveloperKnowledge.BatchGetDocuments] + * to retrieve the full document content. + * @type string $next_page_token + * Optional. Provides a token that can be sent as `page_token` to retrieve the + * next page. If this field is omitted, there are no subsequent pages. + * } + */ + public function __construct($data = NULL) { + \GPBMetadata\Google\Developers\Knowledge\V1\Developerknowledge::initOnce(); + parent::__construct($data); + } + + /** + * Contains the search results for the given query. Each + * [DocumentChunk][google.developers.knowledge.v1.DocumentChunk] in this list + * contains a snippet of content relevant to the search query. Use the + * [DocumentChunk.parent][google.developers.knowledge.v1.DocumentChunk.parent] + * field of each result with + * [DeveloperKnowledge.GetDocument][google.developers.knowledge.v1.DeveloperKnowledge.GetDocument] + * or + * [DeveloperKnowledge.BatchGetDocuments][google.developers.knowledge.v1.DeveloperKnowledge.BatchGetDocuments] + * to retrieve the full document content. + * + * Generated from protobuf field repeated .google.developers.knowledge.v1.DocumentChunk results = 1; + * @return RepeatedField<\Google\Developers\Knowledge\V1\DocumentChunk> + */ + public function getResults() + { + return $this->results; + } + + /** + * Contains the search results for the given query. Each + * [DocumentChunk][google.developers.knowledge.v1.DocumentChunk] in this list + * contains a snippet of content relevant to the search query. Use the + * [DocumentChunk.parent][google.developers.knowledge.v1.DocumentChunk.parent] + * field of each result with + * [DeveloperKnowledge.GetDocument][google.developers.knowledge.v1.DeveloperKnowledge.GetDocument] + * or + * [DeveloperKnowledge.BatchGetDocuments][google.developers.knowledge.v1.DeveloperKnowledge.BatchGetDocuments] + * to retrieve the full document content. + * + * Generated from protobuf field repeated .google.developers.knowledge.v1.DocumentChunk results = 1; + * @param \Google\Developers\Knowledge\V1\DocumentChunk[] $var + * @return $this + */ + public function setResults($var) + { + $arr = GPBUtil::checkRepeatedField($var, \Google\Protobuf\Internal\GPBType::MESSAGE, \Google\Developers\Knowledge\V1\DocumentChunk::class); + $this->results = $arr; + + return $this; + } + + /** + * Optional. Provides a token that can be sent as `page_token` to retrieve the + * next page. If this field is omitted, there are no subsequent pages. + * + * Generated from protobuf field string next_page_token = 2 [(.google.api.field_behavior) = OPTIONAL]; + * @return string + */ + public function getNextPageToken() + { + return $this->next_page_token; + } + + /** + * Optional. Provides a token that can be sent as `page_token` to retrieve the + * next page. If this field is omitted, there are no subsequent pages. + * + * Generated from protobuf field string next_page_token = 2 [(.google.api.field_behavior) = OPTIONAL]; + * @param string $var + * @return $this + */ + public function setNextPageToken($var) + { + GPBUtil::checkString($var, True); + $this->next_page_token = $var; + + return $this; + } + +} + diff --git a/DevelopersKnowledge/src/V1/gapic_metadata.json b/DevelopersKnowledge/src/V1/gapic_metadata.json new file mode 100644 index 000000000000..a8d3f9b8bbff --- /dev/null +++ b/DevelopersKnowledge/src/V1/gapic_metadata.json @@ -0,0 +1,33 @@ +{ + "schema": "1.0", + "comment": "This file maps proto services\/RPCs to the corresponding library clients\/methods", + "language": "php", + "protoPackage": "google.developers.knowledge.v1", + "libraryPackage": "Google\\Developers\\Knowledge\\V1", + "services": { + "DeveloperKnowledge": { + "clients": { + "grpc": { + "libraryClient": "DeveloperKnowledgeGapicClient", + "rpcs": { + "BatchGetDocuments": { + "methods": [ + "batchGetDocuments" + ] + }, + "GetDocument": { + "methods": [ + "getDocument" + ] + }, + "SearchDocumentChunks": { + "methods": [ + "searchDocumentChunks" + ] + } + } + } + } + } + } +} \ No newline at end of file diff --git a/DevelopersKnowledge/src/V1/resources/developer_knowledge_client_config.json b/DevelopersKnowledge/src/V1/resources/developer_knowledge_client_config.json new file mode 100644 index 000000000000..d2ab1a5d5c0c --- /dev/null +++ b/DevelopersKnowledge/src/V1/resources/developer_knowledge_client_config.json @@ -0,0 +1,49 @@ +{ + "interfaces": { + "google.developers.knowledge.v1.DeveloperKnowledge": { + "retry_codes": { + "no_retry_codes": [], + "retry_policy_1_codes": [ + "UNAVAILABLE" + ] + }, + "retry_params": { + "no_retry_params": { + "initial_retry_delay_millis": 0, + "retry_delay_multiplier": 0.0, + "max_retry_delay_millis": 0, + "initial_rpc_timeout_millis": 0, + "rpc_timeout_multiplier": 1.0, + "max_rpc_timeout_millis": 0, + "total_timeout_millis": 0 + }, + "retry_policy_1_params": { + "initial_retry_delay_millis": 1000, + "retry_delay_multiplier": 1.3, + "max_retry_delay_millis": 10000, + "initial_rpc_timeout_millis": 60000, + "rpc_timeout_multiplier": 1.0, + "max_rpc_timeout_millis": 60000, + "total_timeout_millis": 60000 + } + }, + "methods": { + "BatchGetDocuments": { + "timeout_millis": 60000, + "retry_codes_name": "retry_policy_1_codes", + "retry_params_name": "retry_policy_1_params" + }, + "GetDocument": { + "timeout_millis": 60000, + "retry_codes_name": "retry_policy_1_codes", + "retry_params_name": "retry_policy_1_params" + }, + "SearchDocumentChunks": { + "timeout_millis": 60000, + "retry_codes_name": "no_retry_codes", + "retry_params_name": "no_retry_params" + } + } + } + } +} diff --git a/DevelopersKnowledge/src/V1/resources/developer_knowledge_descriptor_config.php b/DevelopersKnowledge/src/V1/resources/developer_knowledge_descriptor_config.php new file mode 100644 index 000000000000..aa75b4338506 --- /dev/null +++ b/DevelopersKnowledge/src/V1/resources/developer_knowledge_descriptor_config.php @@ -0,0 +1,59 @@ + [ + 'google.developers.knowledge.v1.DeveloperKnowledge' => [ + 'BatchGetDocuments' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Developers\Knowledge\V1\BatchGetDocumentsResponse', + ], + 'GetDocument' => [ + 'callType' => \Google\ApiCore\Call::UNARY_CALL, + 'responseType' => 'Google\Developers\Knowledge\V1\Document', + 'headerParams' => [ + [ + 'keyName' => 'name', + 'fieldAccessors' => [ + 'getName', + ], + ], + ], + ], + 'SearchDocumentChunks' => [ + 'pageStreaming' => [ + 'requestPageTokenGetMethod' => 'getPageToken', + 'requestPageTokenSetMethod' => 'setPageToken', + 'requestPageSizeGetMethod' => 'getPageSize', + 'requestPageSizeSetMethod' => 'setPageSize', + 'responsePageTokenGetMethod' => 'getNextPageToken', + 'resourcesGetMethod' => 'getResults', + ], + 'callType' => \Google\ApiCore\Call::PAGINATED_CALL, + 'responseType' => 'Google\Developers\Knowledge\V1\SearchDocumentChunksResponse', + ], + 'templateMap' => [ + 'document' => 'documents/{document}', + ], + ], + ], +]; diff --git a/DevelopersKnowledge/src/V1/resources/developer_knowledge_rest_client_config.php b/DevelopersKnowledge/src/V1/resources/developer_knowledge_rest_client_config.php new file mode 100644 index 000000000000..c41ea1bc8aef --- /dev/null +++ b/DevelopersKnowledge/src/V1/resources/developer_knowledge_rest_client_config.php @@ -0,0 +1,48 @@ + [ + 'google.developers.knowledge.v1.DeveloperKnowledge' => [ + 'BatchGetDocuments' => [ + 'method' => 'get', + 'uriTemplate' => '/v1/documents:batchGet', + ], + 'GetDocument' => [ + 'method' => 'get', + 'uriTemplate' => '/v1/{name=documents/**}', + 'placeholders' => [ + 'name' => [ + 'getters' => [ + 'getName', + ], + ], + ], + ], + 'SearchDocumentChunks' => [ + 'method' => 'get', + 'uriTemplate' => '/v1/documents:searchDocumentChunks', + ], + ], + ], + 'numericEnums' => true, +]; diff --git a/DevelopersKnowledge/tests/Unit/V1/Client/DeveloperKnowledgeClientTest.php b/DevelopersKnowledge/tests/Unit/V1/Client/DeveloperKnowledgeClientTest.php new file mode 100644 index 000000000000..565d1947da84 --- /dev/null +++ b/DevelopersKnowledge/tests/Unit/V1/Client/DeveloperKnowledgeClientTest.php @@ -0,0 +1,304 @@ +getMockBuilder(CredentialsWrapper::class) + ->disableOriginalConstructor() + ->getMock(); + } + + /** @return DeveloperKnowledgeClient */ + private function createClient(array $options = []) + { + $options += [ + 'credentials' => $this->createCredentials(), + ]; + return new DeveloperKnowledgeClient($options); + } + + /** @test */ + public function batchGetDocumentsTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new BatchGetDocumentsResponse(); + $transport->addResponse($expectedResponse); + // Mock request + $formattedNames = [$gapicClient->documentName('[DOCUMENT]')]; + $request = (new BatchGetDocumentsRequest())->setNames($formattedNames); + $response = $gapicClient->batchGetDocuments($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.developers.knowledge.v1.DeveloperKnowledge/BatchGetDocuments', $actualFuncCall); + $actualValue = $actualRequestObject->getNames(); + $this->assertProtobufEquals($formattedNames, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function batchGetDocumentsExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode( + [ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], + JSON_PRETTY_PRINT + ); + $transport->addResponse(null, $status); + // Mock request + $formattedNames = [$gapicClient->documentName('[DOCUMENT]')]; + $request = (new BatchGetDocumentsRequest())->setNames($formattedNames); + try { + $gapicClient->batchGetDocuments($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getDocumentTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $name2 = 'name2-1052831874'; + $uri = 'uri116076'; + $content = 'content951530617'; + $description = 'description-1724546052'; + $dataSource = 'dataSource-1333894576'; + $title = 'title110371416'; + $expectedResponse = new Document(); + $expectedResponse->setName($name2); + $expectedResponse->setUri($uri); + $expectedResponse->setContent($content); + $expectedResponse->setDescription($description); + $expectedResponse->setDataSource($dataSource); + $expectedResponse->setTitle($title); + $transport->addResponse($expectedResponse); + // Mock request + $formattedName = $gapicClient->documentName('[DOCUMENT]'); + $request = (new GetDocumentRequest())->setName($formattedName); + $response = $gapicClient->getDocument($request); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.developers.knowledge.v1.DeveloperKnowledge/GetDocument', $actualFuncCall); + $actualValue = $actualRequestObject->getName(); + $this->assertProtobufEquals($formattedName, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function getDocumentExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode( + [ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], + JSON_PRETTY_PRINT + ); + $transport->addResponse(null, $status); + // Mock request + $formattedName = $gapicClient->documentName('[DOCUMENT]'); + $request = (new GetDocumentRequest())->setName($formattedName); + try { + $gapicClient->getDocument($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function searchDocumentChunksTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $nextPageToken = ''; + $resultsElement = new DocumentChunk(); + $results = [$resultsElement]; + $expectedResponse = new SearchDocumentChunksResponse(); + $expectedResponse->setNextPageToken($nextPageToken); + $expectedResponse->setResults($results); + $transport->addResponse($expectedResponse); + // Mock request + $query = 'query107944136'; + $request = (new SearchDocumentChunksRequest())->setQuery($query); + $response = $gapicClient->searchDocumentChunks($request); + $this->assertEquals($expectedResponse, $response->getPage()->getResponseObject()); + $resources = iterator_to_array($response->iterateAllElements()); + $this->assertSame(1, count($resources)); + $this->assertEquals($expectedResponse->getResults()[0], $resources[0]); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.developers.knowledge.v1.DeveloperKnowledge/SearchDocumentChunks', $actualFuncCall); + $actualValue = $actualRequestObject->getQuery(); + $this->assertProtobufEquals($query, $actualValue); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function searchDocumentChunksExceptionTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + $status = new stdClass(); + $status->code = Code::DATA_LOSS; + $status->details = 'internal error'; + $expectedExceptionMessage = json_encode( + [ + 'message' => 'internal error', + 'code' => Code::DATA_LOSS, + 'status' => 'DATA_LOSS', + 'details' => [], + ], + JSON_PRETTY_PRINT + ); + $transport->addResponse(null, $status); + // Mock request + $query = 'query107944136'; + $request = (new SearchDocumentChunksRequest())->setQuery($query); + try { + $gapicClient->searchDocumentChunks($request); + // If the $gapicClient method call did not throw, fail the test + $this->fail('Expected an ApiException, but no exception was thrown.'); + } catch (ApiException $ex) { + $this->assertEquals($status->code, $ex->getCode()); + $this->assertEquals($expectedExceptionMessage, $ex->getMessage()); + } + // Call popReceivedCalls to ensure the stub is exhausted + $transport->popReceivedCalls(); + $this->assertTrue($transport->isExhausted()); + } + + /** @test */ + public function batchGetDocumentsAsyncTest() + { + $transport = $this->createTransport(); + $gapicClient = $this->createClient([ + 'transport' => $transport, + ]); + $this->assertTrue($transport->isExhausted()); + // Mock response + $expectedResponse = new BatchGetDocumentsResponse(); + $transport->addResponse($expectedResponse); + // Mock request + $formattedNames = [$gapicClient->documentName('[DOCUMENT]')]; + $request = (new BatchGetDocumentsRequest())->setNames($formattedNames); + $response = $gapicClient->batchGetDocumentsAsync($request)->wait(); + $this->assertEquals($expectedResponse, $response); + $actualRequests = $transport->popReceivedCalls(); + $this->assertSame(1, count($actualRequests)); + $actualFuncCall = $actualRequests[0]->getFuncCall(); + $actualRequestObject = $actualRequests[0]->getRequestObject(); + $this->assertSame('/google.developers.knowledge.v1.DeveloperKnowledge/BatchGetDocuments', $actualFuncCall); + $actualValue = $actualRequestObject->getNames(); + $this->assertProtobufEquals($formattedNames, $actualValue); + $this->assertTrue($transport->isExhausted()); + } +} diff --git a/composer.json b/composer.json index abab0e28f9a2..1714218db7bf 100644 --- a/composer.json +++ b/composer.json @@ -282,6 +282,7 @@ "google/cloud-workflows": "1.3.0", "google/cloud-workloadmanager": "0.2.0", "google/common-protos": "4.14.0", + "google/developers-knowledge": "0.0.0", "google/geo-common-protos": "0.2.4", "google/grafeas": "1.7.0", "google/longrunning": "0.7.1", @@ -502,6 +503,7 @@ "GPBMetadata\\Google\\Dataflow\\": "Dataflow/metadata", "GPBMetadata\\Google\\Datastore\\": "Datastore/metadata", "GPBMetadata\\Google\\Datastore\\Admin\\": "DatastoreAdmin/metadata", + "GPBMetadata\\Google\\Developers\\Knowledge\\": "DevelopersKnowledge/metadata", "GPBMetadata\\Google\\Devtools\\": "CloudCommonProtos/metadata/Devtools", "GPBMetadata\\Google\\Devtools\\Artifactregistry\\": "ArtifactRegistry/metadata", "GPBMetadata\\Google\\Devtools\\Build\\": "Build/metadata", @@ -764,6 +766,7 @@ "Google\\Cloud\\WebSecurityScanner\\": "WebSecurityScanner/src", "Google\\Cloud\\Workflows\\": "Workflows/src", "Google\\Cloud\\WorkloadManager\\": "WorkloadManager/src", + "Google\\Developers\\Knowledge\\": "DevelopersKnowledge/src", "Google\\Geo\\": "GeoCommonProtos/src", "Google\\Iam\\": "CommonProtos/src/Iam", "Google\\Identity\\AccessContextManager\\": "AccessContextManager/src",