Skip to content

Conversation

@lgarber-akamai
Copy link
Contributor

@lgarber-akamai lgarber-akamai commented Jul 24, 2024

📝 Description

This pull request adds support for loading the Linode OpenAPI spec as either a JSON or YAML file, which will prepare the CLI for the move away from the legacy spec publication system.

NOTE: This pull request previously included the removal of the linode-api-docs latest version resolution, but will be moved to a separate PR due to the delayed move to the akamai-apis repository.

✔️ How to Test

The following test steps assume you have pulled down this PR locally.

Installing with the TechDocs OpenAPI spec (JSON):

make SPEC="https://gist.githubusercontent.com/lgarber-akamai/06b1e4c6e3578b936e293461c03e7feb/raw/e6917ef9f54add09d2716c93e332dc11ed330932/openapi.json" install

Installing with the Legacy OpenAPI spec (YAML):

make install

Integration Testing

make testint

Unit Testing

make testunit

Manual Testing

Manual testing can be done by simply running linode-cli commands after running one of the above installation commands.

@lgarber-akamai lgarber-akamai added new-feature for new features in the changelog. do-not-merge PRs that should not be merged until the commented issue is resolved labels Jul 24, 2024
@contextlib.contextmanager
def _get_spec_file_reader(
spec_location: str,
) -> ContextManager[IO]:
Copy link
Contributor Author

@lgarber-akamai lgarber-akamai Jul 24, 2024

Choose a reason for hiding this comment

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

Given the new OpenAPI spec is so large, I used a ContextManager & stream here to avoid loading the spec into memory more times than we need to.



@contextlib.contextmanager
def open_fixture(filename: str) -> ContextManager[TextIO]:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is necessary so we can manually load raw fixture contents in unit tests

assert "not a registered plugin" in msg
assert code == 14

def test_bake_command_bad_website(self, capsys, mock_cli):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I decided to remove this error handler/test because the detailed error gives more valuable information (especially when it comes to cert issues):

Failed to load spec: HTTPSConnectionPool(host='fake.linode.com', port=443): Max retries exceeded with url: / (Caused by NameResolutionError("<urllib3.connection.HTTPSConnection object at 0x10f38a5d0>: Failed to resolve 'fake.linode.com' ([Errno 8] nodename nor servname provided, or not known)"))

@lgarber-akamai lgarber-akamai force-pushed the new/spec-target-repoint branch from e4095ce to f62c0b1 Compare July 25, 2024 14:05
@lgarber-akamai lgarber-akamai marked this pull request as ready for review July 25, 2024 14:05
@lgarber-akamai lgarber-akamai requested a review from a team as a code owner July 25, 2024 14:05
@lgarber-akamai lgarber-akamai requested review from yec-akamai and zliang-akamai and removed request for a team July 25, 2024 14:05
Comment on lines +234 to +244

with CLI._get_spec_file_reader(spec_location) as f:
parsed = CLI._parse_spec_file(f)

return OpenAPI(parsed)

@staticmethod
@contextlib.contextmanager
def _get_spec_file_reader(
spec_location: str,
) -> ContextManager[IO]:
Copy link
Member

Choose a reason for hiding this comment

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

Very cool usage of context manager!

@zliang-akamai zliang-akamai self-requested a review July 26, 2024 21:36
Copy link
Member

@zliang-akamai zliang-akamai left a comment

Choose a reason for hiding this comment

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

Works well on my side, nice work!

Copy link
Contributor

@yec-akamai yec-akamai left a comment

Choose a reason for hiding this comment

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

Tested locally and works great, nice work!

@lgarber-akamai lgarber-akamai removed the do-not-merge PRs that should not be merged until the commented issue is resolved label Aug 7, 2024
Copy link
Contributor

@yec-akamai yec-akamai left a comment

Choose a reason for hiding this comment

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

Great work!

@lgarber-akamai lgarber-akamai added the do-not-merge PRs that should not be merged until the commented issue is resolved label Aug 12, 2024
@lgarber-akamai lgarber-akamai changed the title new: Point at TechDocs OpenAPI spec location; add support for loading JSON specs new: Add support for loading JSON specs Oct 23, 2024
@lgarber-akamai lgarber-akamai changed the title new: Add support for loading JSON specs new: Add support for loading JSON OpenAPI spec files Oct 23, 2024
@lgarber-akamai lgarber-akamai force-pushed the new/spec-target-repoint branch from 357f1fd to dddc940 Compare October 23, 2024 15:31
@lgarber-akamai lgarber-akamai removed the do-not-merge PRs that should not be merged until the commented issue is resolved label Oct 23, 2024
Copy link
Contributor

@yec-akamai yec-akamai left a comment

Choose a reason for hiding this comment

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

LGTM! Just FYI when I run the integration tests with different specs, they throw some different errors. Probably because the spec versions are different and have different change.

@lgarber-akamai lgarber-akamai merged commit 19ee0b7 into linode:dev Oct 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

new-feature for new features in the changelog.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants