Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhanced Generator Code to generate Endpoints using OpenSearch API Specifications #194

Merged
merged 1 commit into from
May 29, 2024

Conversation

saimedhi
Copy link
Collaborator

@saimedhi saimedhi commented May 28, 2024

Description

Enhanced Generator Code to generate Endpoints using OpenSearch API Specifications.

  • Follow the steps below to run the generator:
php util/GenerateEndpoints.php   (to run the generator)
composer run php-cs            (to format)
  • View the Generated Endpoints here. Subsequent PRs will address any minor adjustments needed in the generated endpoints.
  • The OpenSearch API specification repository can be found here.
  • The specification can be downloaded from the releases section.

Issues Resolved

Related to #97

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

…ecifications

Signed-off-by: saimedhi <saimedhi@amazon.com>
@saimedhi
Copy link
Collaborator Author

@shyim, @dblock, @VachaShah please take a look. Thank you.

  • View the Generated Endpoints in PR 195.
  • Subsequent PRs will address any minor adjustments needed in the generated endpoints.

Copy link
Member

@dblock dblock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks pretty good, I'd gladly merge it as is.

Generally try to get rid of any code that tries to edit code in-place. Generated files should be generated from a template and have a "THIS FILE IS DYNAMICALLY GENERATED" warning so nobody edits them. An ideal generator takes the spec, a bunch of templates, then dumps all output. No fixing, replacing, or editing of anything in-place.

@@ -4,6 +4,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

## [Unreleased]
### Added
- Enhanced Generator Code to generate Endpoints using OpenSearch API Specifications ([#194](https://github.com/opensearch-project/opensearch-php/pull/194))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: "Enhanced Generator Code " is kinda redundant, simplify "Generate endpoints from OpenSearch OpenAPI spec" or something like that.

@@ -164,6 +359,8 @@

printf("Copying the generated files to %s\n", $destDir);
cleanFolders();
fix_license_header($outputDir . "/Namespaces");
fix_license_header($outputDir . "/Endpoints");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a 1-time thing? Meaning once the headers are fixed, will this ever run?

Generally all code should be generated from a template that already has the license header, and be 1-way, overwriting whatever we had before, rather than trying to patch/merge existing files.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • If the endpoint exists before and have header I am keeping the same header to the newly generated corresponding endpoint. Relavant code is here.

    • This is necessary because the existing files contain two types of headers. For example, security endpoints have an OpenSearch license header, while cat endpoints have an Elasticsearch license header.
  • At last after entire generation is done, checking if any files doesnot have header and adding opensearch license header for it by calling fix_license_header. Corresponding code is here.

  • Please let me know if any changes are needed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense.

* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*
* Elasticsearch PHP client
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OpenSearch client.

Keep the licensed to ES part for all existing files, but it should not be added to new ones.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @dblock, after this PR gets merged, I'll be changing Elasticsearch PHP client to OpenSearch PHP client in all 279 files at once. This should make it easier for reviewers. Let me know if any more changes are needed for this PR to get merged. Thank you.

@dblock dblock merged commit 73bceb8 into opensearch-project:main May 29, 2024
46 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants