-
Notifications
You must be signed in to change notification settings - Fork 152
new: Add support for loading JSON OpenAPI spec files #629
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: Add support for loading JSON OpenAPI spec files #629
Conversation
| @contextlib.contextmanager | ||
| def _get_spec_file_reader( | ||
| spec_location: str, | ||
| ) -> ContextManager[IO]: |
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.
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]: |
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 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): |
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 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)"))
e4095ce to
f62c0b1
Compare
|
|
||
| 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]: |
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.
Very cool usage of context manager!
zliang-akamai
left a comment
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.
Works well on my side, nice work!
yec-akamai
left a comment
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 locally and works great, nice work!
yec-akamai
left a comment
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.
Great work!
357f1fd to
dddc940
Compare
yec-akamai
left a comment
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! 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.
📝 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):
Installing with the Legacy OpenAPI spec (YAML):
Integration Testing
Unit Testing
Manual Testing
Manual testing can be done by simply running
linode-clicommands after running one of the above installation commands.