-
Notifications
You must be signed in to change notification settings - Fork 146
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
new: Changes for CLI/TechDocs spec compatibility #624
new: Changes for CLI/TechDocs spec compatibility #624
Conversation
# matches the path of this column | ||
if col == attr.name: |
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.
Breaking change to resolve the following from giving an unexpected placement_group.id
output:
linode-cli linodes ls --format id
I would consider the previous functionality to technically be broken so I'm thinking this change might be for the best in the long run. If we do end up making this change, we should definitely communicate it through our release notes (and maybe add a warning)?
If anyone else has any ideas definitely let me know 🙂
See: https://github.com/linode/linode-cli/pull/624/files#r1664858657
@@ -244,7 +244,7 @@ def get_user_id(): | |||
"--delimiter", | |||
",", | |||
"--format", | |||
"id", | |||
"username", |
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.
This test passed at some point because a --format
string with an invalid field will give all of the results starting with username. This doesn't seem to be the case anymore so I adjusted it accordingly 👍
tests/integration/cli/test_help.py
Outdated
"API Documentation: https://www.linode.com/docs/api/linode-instances/#linodes-list", | ||
"API Documentation: https://www.linode.com/docs/api/linode-instances/#list-linodes", |
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.
There are some minor (but valid) changes to the help pages/descriptions for certain endpoint methods. I updated the tests accordingly to ensure everything will be backwards compatible
tests/integration/helpers.py
Outdated
@@ -34,7 +39,9 @@ def exec_test_command(args: List[str]): | |||
return process | |||
|
|||
|
|||
def exec_failing_test_command(args: List[str], expected_code: int = 1): | |||
def exec_failing_test_command( | |||
args: List[str], expected_code: int = ExitCodes.REQUEST_FAILED |
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.
Inherited from #625
@@ -73,7 +73,7 @@ def test_create_linode_with_backup_disabled( | |||
"list", | |||
"--id", | |||
linode_id, | |||
"--format=id,enabled", | |||
"--format=id,backups.enabled", |
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.
This is the effect of the breaking change mentioned above
38abfbb
to
630e434
Compare
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.
Everything is working as intended. Nice work!
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.
Tests work well! Just a minor typing suggestion, otherwise looks great!
Co-authored-by: Zhiwei Liang <[email protected]>
2024ba4
to
1677e08
Compare
1677e08
to
621c928
Compare
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.
Tested discovered issues work perfectly now. Great work!
# Matches on pattern [link title](https://.../) | ||
REGEX_MARKDOWN_LINK = re.compile(r"\[(?P<text>.*?)]\((?P<link>.*?)\)") | ||
|
||
MARKDOWN_RICH_TRANSLATION = [ |
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.
I was originally trying to use the Rich Markdown
renderable but there were a bunch of small issues relating to grouping and styles that heavily complicated things. For the time being this should work 🙂
description_rich, description = process_arg_description( | ||
schema.description or "" | ||
) | ||
|
||
#: The description of this argument for Markdown/plaintext display | ||
self.description = description | ||
|
||
#: The description of this argument for display on the help page | ||
self.description_rich = description_rich |
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.
We're now baking the rendered descriptions directly into the request for re-use and optimization purposes.
NOTE: The description
field is preserved here in preparation for potential docs generation down the road.
def _sub_handler(match: re.Match) -> str: | ||
link = match["link"] | ||
if link.startswith("/"): | ||
link = f"https://linode.com{link}" |
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 TechDocs spec does not use relative paths so this is necessary to maintain for backwards compatibility purposes
description, links = extract_markdown_links(result) | ||
|
||
if len(links) > 0: | ||
description += f" See: {'; '.join(links)}" |
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.
Links are now extracted and appended to the end of an argument's description:
--region (required): The region where the Linode will be located. See: https://techdocs.akamai.com/linode-api/reference/get-regions
Previously links were embedded inline after the display text, but this made thing super unreadable with TechDocs due to long the new URLs are.
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.
LGTM, integration tests and reported issues verified locally. Nice work!
📝 Description
This pull request resolves a few issues in the OpenAPI spec generation/baking logic that prevented it from being compatible with the upcoming new TechDocs OpenAPI spec. The changes in this PR were also made to be backwards compatible to make sure the transition between specs goes smoothly 🙂
Because this PR needed to be all-encompassing, it also includes a bunch of minor fixes that should get previously failing integration tests passing.
Additionally this PR requires a few minor changes to the internal documentation linked in TPT-3016.
✔️ How to Test
NOTE: You will need to opt into Linode Managed for the managed-related tests to pass. If you would like to subsequently opt-out of Linode Managed, see the description of TPT-3016.
The following test steps assume you have pulled down this PR locally.
Building & Installing the CLI
With the TechDocs OpenAPI Spec
openapi-techdocs.yaml
(see TPT-3016's description).From here you should be able to run and test arbitrary commands using
linode-cli
.With the Legacy (linode-api-docs) OpenAPI Spec
SPEC
argument:From here you should be able to run and test arbitrary commands using
linode-cli
.Integration Testing
NOTE: This test command should be run for both versions of the CLI installed above.
NOTE: The following tests are expected to fail when running against the legacy spec due to bug fixes that were only applied to the TechDocs spec:
Unit Testing