-
Notifications
You must be signed in to change notification settings - Fork 323
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
feat: swagger.yaml #2818
feat: swagger.yaml #2818
Conversation
@gregnuj can you provide more context on why we want this PR? Is there an issue this closes? What does the "lcd swagger.yaml file" do? |
The swagger.yaml file describes the available endpoints to your developers and provides them a ui to test api endpoints. This is standard practice in cosmos-sdk which, given the proper path to the file in the code, will provide an interface as linked above when enabled via the app.toml file or via the cli option for example:
|
As far as issues I see none open in github, but search your discord for "swagger", multiple inquiries regarding the missing swagger doc. |
What does lcd stand for? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution! Confirmed Osmosis and Cosmos Hub have something similar:
- https://github.com/osmosis-labs/osmosis/blob/main/client/docs/config.json
- https://github.com/cosmos/gaia/blob/be7129bb6bdf3099e000b9786b15b98ec1defe54/client/docs/config.json
so I think we want this, but I want to verify the generated config.json before approving. Is there an easy way to do that?
the scripts generates a file called "swagger.yaml" the config.json file is just some instructions how to structure the output file... |
lcd = light client daemon, although technically the name of the rest client in cosmos-sdk has been renamed from lcd to grpc-gateway |
run the script and you can test it here https://editor.swagger.io |
1 similar comment
run the script and you can test it here https://editor.swagger.io |
Codecov Report
@@ Coverage Diff @@
## main #2818 +/- ##
=======================================
Coverage 19.80% 19.80%
=======================================
Files 144 144
Lines 17398 17398
=======================================
Hits 3446 3446
Misses 13631 13631
Partials 321 321 |
When I put https://github.com/gregnuj/celestia-app/blob/main/docs/swagger-ui/swagger.yaml into https://editor.swagger.io/ I observe errors: |
Converting to draft until this error is resolved ^ |
c5c566e
to
c917e5c
Compare
WalkthroughThe changes involve updates to scripts used for generating Swagger documentation from Protoc files. A Python script Changes
TipsChat with CodeRabbit Bot (
|
I added a title, I cannot resolve the other error without removing valid endpoints /cosmos/auth/v1beta1/bech32/{address_bytes}: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 7
Configuration used: CodeRabbit UI
Files ignored due to filter (1)
- docs/swagger-ui/swagger.yaml
Files selected for processing (2)
- scripts/merge_swagger.py (1 hunks)
- scripts/protoc-swagger-gen.sh (1 hunks)
parser.add_argument('-d', '--directory', help='Directory containing swagger files') | ||
parser.add_argument('-t', '--title', help='Title for the swagger file') | ||
parser.add_argument('-v', '--version', help='Version for the swagger file') | ||
parser.add_argument('-o', '--output', help='Output file') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The script should validate that all required command-line arguments are provided and handle cases where they are not, to prevent runtime errors.
with open(os.path.join(project_root, "go.mod"), "r") as f: | ||
for line in f.readlines(): | ||
if line.startswith("module"): | ||
version = line.split("/")[-1].strip() | ||
break | ||
|
||
if not version: | ||
print("Could not find version in go.mod") | ||
exit(1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding exception handling around file operations to gracefully handle cases where the go.mod
file does not exist or cannot be read due to permissions or other issues.
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
# This script generates the swagger.yaml documentation for the rest API on port 1317 | ||
# | ||
# Prior to running this script, please install the following: | ||
# - Install Go 1.21+ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Go version specified in the comment is 1.21+, which does not exist. Please correct it to a valid Go version, such as 1.21 (if it's a typo) or the actual minimum required version.
|
||
set -eo pipefail | ||
|
||
work_dir="$(dirname "$(dirname "$(realpath "$0")")")" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The realpath
command is not available by default on all systems, such as macOS. Consider using a more portable alternative or ensure that realpath
is installed as part of the prerequisites.
go build -o $tmp_dir/protoc-gen-swagger protoc-gen-swagger/main.go | ||
cd $tmp_dir | ||
|
||
PATH=./:$PATH |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding the current directory to the PATH can be a security risk. Consider specifying the full path to the protoc-gen-swagger
binary instead of modifying the PATH.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I run this script locally, I observe changes to the generated swagger.yaml. See https://pastebin.com/K05t1qbr
I would expect no changes. Can we update the generator or swagger.yaml so that subsequent invocations to ./scripts/protoc-swagger-gen.sh
don't cause a dirty git diff.
Even though it's late in the review process, I think a GitHub issue with more context on what this PR is attempting to address would help. Ideally the GitHub issue would contain context, a problem statement, a proposal for how to resolve, etc.
# | ||
# Prior to running this script, please install the following: | ||
# - Install Go 1.21+ | ||
# - Install pyyaml: `pip3 install pyyaml` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there anyway to do this via Go or bash so that maintainers don't have to set up Python to run this? AFAIK no other files in this repo use Python so it would be preferable to not introduce a new language / environment set up.
Co-authored-by: Rootul P <[email protected]>
for key in data["definitions"]: | ||
definitions[key] = data["definitions"][key] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The script still merges definitions without checking for duplicates, which could lead to data loss if two definitions with the same key but different contents exist. Consider adding a check similar to the one for paths to handle duplicate definitions appropriately.
+ if key in definitions and definitions[key] != data["definitions"][key]:
+ print(f"Duplicate definition found for {key}, which may lead to unexpected behavior.")
+ continue
+ definitions[key] = data["definitions"][key]
Committable suggestion
❗ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
for key in data["definitions"]: | |
definitions[key] = data["definitions"][key] | |
for key in data["definitions"]: | |
if key in definitions and definitions[key] != data["definitions"][key]: | |
print(f"Duplicate definition found for {key}, which may lead to unexpected behavior.") | |
continue | |
definitions[key] = data["definitions"][key] |
Closing because stale. If this is still something we want, please re-open the PR or create a GH issue. |
Overview
Add cosmos sdk standard scripts/protoc-swagger-gen.sh and supporting config.json file to enable the generation of lcd swagger.yaml file
Checklist