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

Fix our proto code and swagger generation. #2167

Merged
merged 13 commits into from
Oct 7, 2024
Merged

Conversation

SpicyLemon
Copy link
Contributor

@SpicyLemon SpicyLemon commented Oct 4, 2024

Description

closes: #2135

This PR does the following:

  • Bumps the proto image version to 0.15.1 (from 0.14.0) and switches us to use openapiv2 instead of swagger.
  • Cleans up some of our proto-related Makefile targets.
  • Updates our proto code gen and swagger gen scripts.
  • Adds the ibchooks queries to the swagger page.
  • Updates the client/docs/swagger-ui/swagger.yaml file and regenerates all the go code from our proto files.

Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

  • Targeted PR against correct branch (see CONTRIBUTING.md).
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Wrote unit and integration tests
  • Updated relevant documentation (docs/) or specification (x/<module>/spec/).
  • Added relevant godoc comments.
  • Added relevant changelog entries under .changelog/unreleased (see Adding Changes).
  • Re-reviewed Files changed in the Github PR explorer.
  • Review Codecov Report in the comment section below once CI passes.

Summary by CodeRabbit

  • New Features

    • Restored functionality for protocol (proto) generation.
    • Added new API entry for "IBC Hooks" with updated operation IDs for existing endpoints.
  • Bug Fixes

    • Addressed issue related to proto generation.
  • Refactor

    • Simplified Docker commands for Protobuf generation.
    • Updated API documentation generation configuration from Swagger to OpenAPI v2.
    • Enhanced scripts for better readability and functionality.
  • Chores

    • Updated Protobuf Docker image version.

Copy link
Contributor

coderabbitai bot commented Oct 4, 2024

Walkthrough

The changes in this pull request focus on restoring the Protobuf generation functionality and transitioning from Swagger to OpenAPI v2 for API documentation. The Makefile has been updated to streamline Docker commands, and several scripts have been modified to enhance functionality and readability. Additionally, the configuration files have been adjusted to reflect new API endpoints and renaming of operation IDs. The changes address issue #2135, ensuring successful execution of the make proto-gen and make proto-swagger-gen commands.

Changes

File Change Summary
.changelog/unreleased/bug-fixes/2135-openapiv2.md Added a note indicating restoration of proto generation functionality.
Makefile Updated Protobuf version, simplified Docker commands, and removed conditional logic.
client/docs/config.json Added new API entry for "IBC Hooks" and renamed several operation IDs for existing endpoints.
proto/buf.gen.swagger.yaml Changed plugin name from swagger to openapiv2 and updated related options.
scripts/protoc-swagger-gen.sh Standardized variables, improved file processing logic, and enhanced output feedback.
scripts/protocgen.sh Removed protoc_gen_gocosmos function and added verbose flag handling.

Assessment against linked issues

Objective Addressed Explanation
Bump the proto image version to 0.15.0 (2135)
Update proto/buf.gen.swagger.yaml to use openapiv2 (2135)
Review proto related make targets and scripts (2135)
Ensure successful execution of make proto-gen and make proto-swagger-gen (2135)

Possibly related PRs

  • Fix proto to markdown generation. #2169: This PR addresses the generation of proto markdown documentation, which is directly related to the changes in the main PR that also involve Protobuf handling and documentation processes.

Suggested reviewers

  • Taztingo
  • iramiller

Poem

🐰 In the meadow where the protocols play,
The rabbits hop and dance all day.
With OpenAPI shining bright,
Our docs now gleam with pure delight!
Protobufs in Docker, oh what a sight,
Hopping to success, everything feels right! 🌼


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@SpicyLemon SpicyLemon changed the title Switch to openapiv2 (from swagger). Fix our proto generation stuff. Oct 4, 2024
@SpicyLemon SpicyLemon marked this pull request as ready for review October 4, 2024 02:20
@SpicyLemon SpicyLemon requested a review from a team as a code owner October 4, 2024 02:20
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🧹 Outside diff range and nitpick comments (12)
proto/buf.gen.swagger.yaml (1)

Verified Removal of strategy: all Option

The strategy: all option has been successfully removed from the proto/buf.gen.swagger.yaml file as shown in the latest changes.

Clarification Needed for json_names_for_fields=false

Please provide more details on the purpose and impact of the json_names_for_fields=false option to ensure it aligns with our project's requirements.

🔗 Analysis chain

Line range hint 1-11: Summary of OpenAPI v2 transition

The changes in this file successfully transition the API documentation generation from Swagger to OpenAPI v2, addressing the main objective of the PR. The plugin name and options have been appropriately updated to reflect this change.

However, there are a couple of points that require attention:

  1. The new option json_names_for_fields=false needs clarification (as mentioned in the previous comment).
  2. The AI summary mentions the removal of the strategy: all option, but this change is not visible in the provided code snippet.

To ensure all changes are accounted for, please run the following command to display the full diff of this file:

This will help verify if there are any additional modifications not visible in the current snippet, such as the removal of the strategy: all option.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

git diff origin/main -- proto/buf.gen.swagger.yaml

Length of output: 553

scripts/protoc-swagger-gen.sh (5)

6-11: Improved path management with centralized variable declarations

The introduction of standardized variables for directory and file paths enhances readability and maintainability. This change makes it easier to modify paths in the future if needed.

Consider using double quotes for all variable assignments to ensure consistency and handle potential spaces in paths. For example:

-proto_dir='./proto'
+proto_dir="./proto"

16-20: Improved proto file processing

The updated logic for finding and processing proto files enhances reliability and efficiency:

  1. Using find with -type f and -print0 improves handling of filenames with spaces.
  2. Filtering for files with service definitions prevents processing unnecessary files.
  3. The simplified loop structure improves readability.

Consider adding a check to ensure proto_files is not empty before proceeding with the loop:

if [ -z "$proto_files" ]; then
  echo "No proto files with service definitions found."
  exit 1
fi

This would provide better error handling if no suitable proto files are found.


24-30: Enhanced feedback with warnings for unreferenced files

The new section that outputs warnings for generated files not referenced in the config file is a valuable addition. It improves the script's feedback mechanism and helps identify potential issues where generated files are not being included in the final output.

Consider adding a counter for the number of warnings and display a summary at the end:

warning_count=0
for file in $swagger_files; do
  if ! grep -Fq "\"url\": \"$file\"" "$config_file"; then
      printf '\033[93mWARNING\033[0m: "%s" not referenced in %s\n' "$file" "$config_file"
      ((warning_count++))
  fi
done

if [ $warning_count -gt 0 ]; then
  echo "Total warnings: $warning_count"
fi

This would provide a quick overview of how many files were not referenced.


42-45: Improved cleanup and finalization process

The changes in this section enhance the script's consistency and readability:

  1. Using -e for multiple patterns in grep improves clarity.
  2. Directing output to $output_file maintains consistency with variable declarations.
  3. Using $VERBOSE for the cleanup message aligns with the rest of the script.

Consider adding a final success message when the script completes without errors:

echo "Swagger generation completed successfully. Output file: $output_file"

This would provide clear confirmation that the script has finished its task as expected.


1-45: Overall improvements align well with PR objectives

This script has undergone significant enhancements that align well with the PR objectives and the requirements outlined in the linked issue #2135:

  1. The script now uses standardized variables for paths and flags, improving maintainability.
  2. Proto file processing has been optimized to handle only relevant files with service definitions.
  3. The addition of warnings for unreferenced generated files enhances the feedback mechanism.
  4. The use of swagger-combine with the updated config file supports the transition to OpenAPI v2.
  5. The cleanup process has been improved for consistency and clarity.

These changes contribute to resolving the issues with proto generation and support the transition from Swagger to OpenAPI v2. The script is now more robust and easier to maintain, which should help address the problems mentioned in issue #2135.

To further improve the script's robustness and alignment with best practices, consider:

  1. Adding error handling for critical operations (e.g., directory creation, file operations).
  2. Implementing a --help option to display usage information.
  3. Using a cleanup trap to ensure temporary files are removed even if the script exits unexpectedly.

Example:

trap 'rm -rf "$temp_dir"' EXIT

These additions would make the script more resilient and user-friendly.

client/docs/config.json (3)

244-256: LGTM! Consider adding a comment for clarity.

The addition of the IBC Hooks API entry is well-structured and consistent with other entries. It aligns with the PR objective to include ibchooks queries in the Swagger documentation.

Consider adding a comment above this entry to explain its purpose and any specific considerations for the IBC Hooks API. This would improve maintainability and provide context for future developers.

+    // IBC Hooks API - Added to support queries related to IBC hooks functionality
     {
       "url": "./tmp-swagger-gen/provenance/ibchooks/v1/query.swagger.json",
       "tags": {
         "add": [
           "IBC Hooks"
         ]
       },
       "operationIds": {
         "rename": {
           "Params": "IBCHooksParams"
         }
       }
     },

Line range hint 1-243: LGTM! Consider standardizing tag naming convention.

The changes to existing entries, including the renaming of operation IDs and the addition of tags, improve the clarity and organization of the Swagger documentation. These modifications align well with the PR objectives.

For improved consistency, consider standardizing the tag naming convention. Most tags are singular (e.g., "Attribute", "Exchange"), but "IBC Hooks" is plural. Consider changing it to singular form:

     {
       "url": "./tmp-swagger-gen/provenance/ibchooks/v1/query.swagger.json",
       "tags": {
         "add": [
-          "IBC Hooks"
+          "IBC Hook"
         ]
       },
       "operationIds": {
         "rename": {
           "Params": "IBCHooksParams"
         }
       }
     },

This change would maintain consistency across all API tags in the configuration.

Also applies to: 257-283


Action Required: Missing Transaction APIs and Inconsistent Operation IDs

The verification process identified several issues that need attention:

  • Missing Transaction APIs:

    • hold transaction API is missing
    • sanction query and transaction APIs are missing
    • quarantine query and transaction APIs are missing
  • Inconsistent Operation ID Renaming:

    • Some 'Params' operation IDs may not have been renamed

Please address these issues to ensure the Swagger configuration is complete and consistent.

🔗 Analysis chain

Line range hint 1-283: Overall, excellent improvements to Swagger configuration.

The changes in this file significantly contribute to the PR objectives of fixing proto generation and improving Swagger documentation. The addition of the IBC Hooks API, renaming of operation IDs, and categorization of APIs with tags enhance the clarity and organization of the Swagger documentation.

A few minor suggestions have been made for further improvement:

  1. Adding a comment for the new IBC Hooks API entry.
  2. Standardizing the tag naming convention.

These changes align well with the transition from Swagger to OpenAPI v2 and the overall cleanup of proto-related configurations.

To ensure all necessary APIs are included and properly configured, please run the following verification script:

This script will help ensure that all expected APIs are included, operation IDs are consistently renamed, and tags follow a singular naming convention.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the completeness and consistency of API entries in the Swagger configuration.

# Test 1: Check if all expected API modules are present
expected_modules=("attribute" "exchange" "hold" "ibchooks" "ibcratelimit" "marker" "metadata" "msgfees" "name" "oracle" "sanction" "quarantine" "trigger")
for module in "${expected_modules[@]}"; do
    if ! grep -q "provenance/$module/v1/query.swagger.json" client/docs/config.json; then
        echo "Warning: $module query API is missing"
    fi
    if ! grep -q "provenance/$module/v1/tx.swagger.json" client/docs/config.json; then
        echo "Warning: $module transaction API is missing"
    fi
done

# Test 2: Verify consistent operation ID renaming
if grep -q '"Params":' client/docs/config.json; then
    echo "Warning: Some 'Params' operation IDs may not have been renamed"
fi

# Test 3: Check for consistent tag naming (singular form)
plural_tags=$(grep -oP '"add": \[\K"[^"]+ [^"]+"' client/docs/config.json)
if [ ! -z "$plural_tags" ]; then
    echo "Warning: The following tags may be in plural form: $plural_tags"
fi

echo "Verification complete. Please review any warnings."

Length of output: 3479

Makefile (3)

489-492: Simplified proto-gen target with improved modularity

The proto-gen target has been streamlined, which aligns with the PR objective of cleaning up proto-related Makefile targets. The use of a single Docker command simplifies the process and reduces potential points of failure.

Consider extracting the go.mod backup and restore commands into a separate function or target for better modularity and reusability. This could be useful if other targets need similar functionality in the future.

define backup-restore-go-mod
	cp go.mod .go.mod.bak
	$(1)
	mv .go.mod.bak go.mod
	$(GO) mod tidy
endef

proto-gen:
	@echo "Generating Protobuf files"
	$(call backup-restore-go-mod,$(protoImage) sh ./scripts/protocgen.sh)

498-517: Streamlined proto-related targets

The proto-format, proto-lint, proto-check-breaking, and proto-check-breaking-third-party targets have been simplified, which aligns with the PR objective of cleaning up proto-related Makefile targets. The use of a single Docker command for each target simplifies the process and reduces potential points of failure.

For consistency and improved readability, consider using multi-line commands for the proto-lint, proto-check-breaking, and proto-check-breaking-third-party targets, similar to the proto-format target. This would make the Makefile more uniform and easier to maintain. For example:

proto-lint:
	@echo "Linting Protobuf files"
	$(protoImage) buf lint \
		--error-format=json

proto-check-breaking:
	@echo "Check breaking Protobuf files"
	$(protoImage) buf breaking proto \
		--against '$(HTTPS_GIT)#branch=main,subdir=proto' \
		--error-format=json

proto-check-breaking-third-party:
	@echo "Check breaking 3rd party Protobuf files"
	$(protoImage) buf breaking third_party/proto \
		--against '$(HTTPS_GIT)#branch=main,subdir=third_party/proto' \
		--error-format=json

480-517: Overall improvements in proto-related Makefile targets

The changes made to the Makefile, particularly in the proto-related targets, significantly improve the overall structure and maintainability of the build process. Key improvements include:

  1. Updating the proto builder version to 0.15.1.
  2. Simplifying variable names and reducing redundancy.
  3. Streamlining Docker commands for proto generation, formatting, linting, and breaking changes checks.
  4. Improving the handling of go.mod during proto generation to prevent unintended changes.

These changes align well with the PR objectives of cleaning up proto-related Makefile targets, upgrading the proto image version, and transitioning to OpenAPI v2.

To further improve the Makefile's maintainability and flexibility:

  1. Consider creating a separate include file for proto-related targets and variables. This would help keep the main Makefile cleaner and make it easier to manage proto-specific configurations.
  2. Implement a versioning system for the Makefile itself, which could help track changes over time and make it easier to roll back if needed.
  3. Add comments explaining the purpose and functionality of each major target, especially for the more complex ones. This would improve the onboarding experience for new contributors.
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 13b0a5e and cdb2ff4.

⛔ Files ignored due to path filters (25)
  • x/attribute/types/query.pb.go is excluded by !**/*.pb.go
  • x/attribute/types/tx.pb.go is excluded by !**/*.pb.go
  • x/exchange/query.pb.go is excluded by !**/*.pb.go
  • x/exchange/tx.pb.go is excluded by !**/*.pb.go
  • x/hold/query.pb.go is excluded by !**/*.pb.go
  • x/ibchooks/types/query.pb.go is excluded by !**/*.pb.go
  • x/ibchooks/types/tx.pb.go is excluded by !**/*.pb.go
  • x/ibcratelimit/query.pb.go is excluded by !**/*.pb.go
  • x/ibcratelimit/tx.pb.go is excluded by !**/*.pb.go
  • x/marker/types/query.pb.go is excluded by !**/*.pb.go
  • x/marker/types/tx.pb.go is excluded by !**/*.pb.go
  • x/metadata/types/query.pb.go is excluded by !**/*.pb.go
  • x/metadata/types/tx.pb.go is excluded by !**/*.pb.go
  • x/msgfees/types/query.pb.go is excluded by !**/*.pb.go
  • x/msgfees/types/tx.pb.go is excluded by !**/*.pb.go
  • x/name/types/query.pb.go is excluded by !**/*.pb.go
  • x/name/types/tx.pb.go is excluded by !**/*.pb.go
  • x/oracle/types/query.pb.go is excluded by !**/*.pb.go
  • x/oracle/types/tx.pb.go is excluded by !**/*.pb.go
  • x/quarantine/query.pb.go is excluded by !**/*.pb.go
  • x/quarantine/tx.pb.go is excluded by !**/*.pb.go
  • x/sanction/query.pb.go is excluded by !**/*.pb.go
  • x/sanction/tx.pb.go is excluded by !**/*.pb.go
  • x/trigger/types/query.pb.go is excluded by !**/*.pb.go
  • x/trigger/types/tx.pb.go is excluded by !**/*.pb.go
📒 Files selected for processing (6)
  • .changelog/unreleased/bug-fixes/2135-openapiv2.md (1 hunks)
  • Makefile (1 hunks)
  • client/docs/config.json (1 hunks)
  • proto/buf.gen.swagger.yaml (1 hunks)
  • scripts/protoc-swagger-gen.sh (1 hunks)
  • scripts/protocgen.sh (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • .changelog/unreleased/bug-fixes/2135-openapiv2.md
🔇 Additional comments (7)
proto/buf.gen.swagger.yaml (3)

4-4: Excellent transition to OpenAPI v2

The change from swagger to openapiv2 as the plugin name is a crucial step in addressing the PR's main objective. This modification aligns the configuration with the new OpenAPI v2 standard, resolving the compatibility issues mentioned in the linked issue #2135.


8-8: Correct adaptation of fully qualified names option

The update from fqn_for_swagger_name=true to fqn_for_openapi_name=true is a necessary adjustment to maintain the use of fully qualified names in the new OpenAPI v2 format. This change ensures consistency in naming conventions throughout the generated documentation.


10-10: Clarify the purpose of the new JSON names option

A new option json_names_for_fields=false has been added. While this aligns with the overall goal of updating the OpenAPI configuration, it wasn't explicitly mentioned in the PR objectives or linked issue.

Could you please clarify:

  1. The specific reason for adding this option?
  2. How does this affect the generated OpenAPI documentation?
  3. Are there any potential impacts on existing integrations or clients that we should be aware of?

This information will help ensure that the change aligns with the project's documentation standards and doesn't introduce unexpected behavior.

scripts/protoc-swagger-gen.sh (3)

3-5: Improved verbose flag handling

The introduction of the VERBOSE variable and support for both short (-v) and long (--verbose) options enhances the script's usability and follows bash conventions.


15-15: Consistent use of temporary directory variable

The use of $temp_dir for creating the temporary directory aligns with the new variable declarations, improving consistency and maintainability.


36-36: Improved clarity in swagger file combination

The use of defined variables $config_file and $temp_file in the swagger-combine command enhances clarity and maintains consistency with the rest of the script. This change improves maintainability.

Makefile (1)

480-482: Proto builder version updated and variables simplified

The proto builder version has been updated from 0.14.0 to 0.15.1, which aligns with the PR objective of upgrading the proto image version. The variable names have been simplified, which improves readability and maintainability.

Makefile Show resolved Hide resolved
scripts/protocgen.sh Outdated Show resolved Hide resolved
scripts/protocgen.sh Show resolved Hide resolved
scripts/protocgen.sh Show resolved Hide resolved
iramiller
iramiller previously approved these changes Oct 4, 2024
Copy link
Member

@iramiller iramiller left a comment

Choose a reason for hiding this comment

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

Nice. The docker proto stuff was a mess for me recently but I presumed it was my rancher setup and ran protoc directly.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (6)
scripts/protocgen.sh (1)

Line range hint 1-24: Consider adding documentation for the new workflow

The changes to this script align well with the PR objectives of updating proto-related scripts. The removal of the protoc_gen_gocosmos function and the addition of new logic for verbose output and proto file processing improve the script's focus and efficiency.

However, it might be beneficial to add some comments or documentation explaining:

  1. The purpose of using buf generate instead of the previous method.
  2. The significance of the option go_package.*provenance pattern in selecting proto files.
  3. Any prerequisites or setup required for this new workflow.

This additional documentation would help future maintainers understand the rationale behind these changes and how to use or modify the script effectively.

scripts/protoc-swagger-gen.sh (5)

6-11: LGTM: Improved variable declarations for better maintainability

The introduction of these variables significantly improves the script's readability and maintainability. Using variables instead of hardcoded paths is a best practice in shell scripting.

Consider adding comments for each variable to explain their purpose, especially for less obvious ones like temp_file and template_file. This would further enhance the script's maintainability.


15-20: LGTM: Improved proto file processing logic

The new approach for finding and processing proto files is more robust and efficient. It correctly identifies only the relevant files containing service definitions.

For added robustness, consider quoting the $file variable in the loop to handle potential spaces in filenames:

for file in $proto_files; do
  [ -n "$VERBOSE" ] && printf 'Generating swagger file for [%s].\n' "$file"
  buf generate --template "$template_file" "$file"
done

24-31: LGTM: Valuable addition of warnings for unused generated files

This new section is a great addition to the script. It helps identify potential issues where generated Swagger files are not being included in the final output, which could lead to incomplete API documentation.

For consistency with the rest of the script, consider using the VERBOSE flag here as well. This would allow users to control the verbosity of these warnings:

if [ -n "$VERBOSE" ]; then
  for file in $swagger_files; do
    if ! grep -Fq "\"url\": \"$file\"" "$config_file"; then
      printf '\033[93mWARNING\033[0m: "%s" not referenced in %s\n' "$file" "$config_file"
    fi
  done
fi

42-42: LGTM: Effective tag removal from Swagger file

The grep command effectively removes the 'Query' and 'Service' tags from the combined Swagger file. The use of variables for input and output files is good practice.

For improved readability, consider breaking the long line into multiple lines:

grep -v \
  -e '        - Query' \
  -e '        - Service' \
  "$temp_file" > "$output_file"

This makes the patterns easier to read and modify if needed in the future.


1-45: Overall excellent improvements to the script

This refactoring of the protoc-swagger-gen.sh script has resulted in significant improvements:

  1. Better variable management and naming conventions
  2. More robust proto file discovery and processing
  3. Addition of warnings for unused generated files
  4. Improved readability and maintainability throughout

These changes align well with the PR objectives, particularly in updating the Swagger generation process and improving the overall code quality. The script now provides a more reliable and maintainable solution for generating Swagger/OpenAPI documentation.

Consider adding a brief comment at the top of the script explaining its purpose and any dependencies (like the swagger-combine tool). This would help future maintainers quickly understand the script's role in the project's build process.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between cdb2ff4 and 1ca8ea0.

📒 Files selected for processing (2)
  • scripts/protoc-swagger-gen.sh (1 hunks)
  • scripts/protocgen.sh (1 hunks)
🧰 Additional context used
📓 Learnings (1)
scripts/protocgen.sh (2)
Learnt from: SpicyLemon
PR: provenance-io/provenance#2167
File: scripts/protocgen.sh:13-14
Timestamp: 2024-10-04T16:17:48.021Z
Learning: In `scripts/protocgen.sh`, the regex pattern `'option go_package.*provenance'` is sufficient for selecting the necessary proto files and does not need modification.
Learnt from: SpicyLemon
PR: provenance-io/provenance#2167
File: scripts/protocgen.sh:15-17
Timestamp: 2024-10-04T16:14:41.003Z
Learning: In the `scripts/protocgen.sh` script within the Provenance project, the paths involved will not have spaces, so handling spaces in filenames is not necessary.
🔇 Additional comments (6)
scripts/protocgen.sh (3)

9-11: LGTM: Proper implementation of verbose flag check

The implementation of the verbose flag check is correct and follows POSIX-compliant shell scripting practices. Good job on using = for string comparison instead of ==.


13-14: LGTM: Efficient proto file selection

The implementation for finding proto files is correct and efficient. The regex pattern 'option go_package.*provenance' is sufficient for selecting the necessary proto files in this project context.


15-17: LGTM: Effective proto file processing

The implementation for processing each proto file is correct and appropriate for this project's context. While the loop doesn't handle filenames with spaces, it's understood that this is not a concern in this codebase. The use of the $VERBOSE flag for conditional output is a good practice.

scripts/protoc-swagger-gen.sh (3)

3-5: LGTM: Improved verbose mode implementation

The introduction of the VERBOSE flag with support for both -v and --verbose options is a good improvement. It follows bash conventions and provides better flexibility for users.


36-36: LGTM: Proper use of swagger-combine command

The swagger-combine command is well-structured and uses the appropriate options. The use of variables makes the command more readable and maintainable.


44-45: LGTM: Proper cleanup with verbose output

The cleanup command is well-implemented. It correctly uses the VERBOSE flag for output and uses the defined variable for the temporary directory. This ensures a clean workspace after script execution.

@SpicyLemon SpicyLemon enabled auto-merge (squash) October 4, 2024 16:25
@SpicyLemon SpicyLemon enabled auto-merge (squash) October 4, 2024 17:00
@SpicyLemon SpicyLemon changed the title Fix our proto generation stuff. Fix our proto code and swagger generation. Oct 4, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 1ca8ea0 and 32c0cf7.

📒 Files selected for processing (1)
  • Makefile (1 hunks)
🧰 Additional context used
📓 Learnings (1)
Makefile (1)
Learnt from: SpicyLemon
PR: provenance-io/provenance#2167
File: Makefile:494-497
Timestamp: 2024-10-04T16:14:19.504Z
Learning: Swagger 2.0 is equivalent to OpenAPI v2, so files with 'swagger: "2.0"' are correctly using OpenAPI v2 specification.
🔇 Additional comments (5)
Makefile (5)

480-482: Improved Variable Naming and Docker Command Simplification

The introduction of protoVer, protoImageName, and protoImage variables enhances clarity and simplifies the Docker commands used for Protobuf generation. This refactoring promotes maintainability and readability across the Makefile.


490-490: Consistent Use of Docker Image for Protobuf Code Generation

Utilizing $(protoImage) in the proto-gen target ensures that Protobuf code generation is consistently executed within the specified Docker environment. This approach enhances reproducibility and minimizes environment-specific issues during the build process.


496-496: Consistent Use of Docker Image for Swagger Generation

Applying $(protoImage) in the proto-swagger-gen target standardizes the execution of Swagger generation within the Docker container. This consistency improves the reliability of the Swagger generation process.


513-513: Consistent Linting of Protobuf Files Using Docker

The use of $(protoImage) to execute buf lint ensures that Protobuf files are linted within a consistent Docker environment. This practice promotes uniformity and reduces discrepancies caused by local development environments.


504-509: Verify Availability of 'clang-format' in the Docker Image

The proto-format target invokes clang-format within the Docker container specified by $(protoImage). Please ensure that clang-format is installed and accessible in the $(protoImageName) Docker image to prevent formatting errors during the Protobuf formatting step.

Run the following script to verify that clang-format is available in the Docker image:

Makefile Show resolved Hide resolved
@SpicyLemon SpicyLemon merged commit 363eb32 into main Oct 7, 2024
34 checks passed
@SpicyLemon SpicyLemon deleted the dwedul/2135-openapiv2 branch October 7, 2024 17:39
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.

Switch to OpenAPI v2 (instead of swagger) to fix API page generation.
3 participants