Skip to content

Conversation

@tisnik
Copy link
Contributor

@tisnik tisnik commented Sep 2, 2025

Description

Elementary OpenAPI integration tests

Type of change

  • Refactor
  • New feature
  • Bug fix
  • CVE fix
  • Optimization
  • Documentation Update
  • Configuration Update
  • Bump-up service version
  • Bump-up dependent library
  • Bump-up library or tool used for development (does not change the final image)
  • CI configuration change
  • Konflux configuration change
  • Unit tests improvement
  • Integration tests improvement
  • End to end tests improvement

Implements: LCORE-628

Summary by CodeRabbit

  • Tests
    • Added integration tests that validate the published OpenAPI document, verifying top-level metadata, a non-empty servers list, and that declared paths/methods include expected response codes.
    • Improves confidence that the API specification remains accurate and complete, helping clients and tooling rely on up-to-date documentation and consistent behaviors.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 2, 2025

Walkthrough

Adds a new integration test module that loads docs/openapi.json and validates top-level OpenAPI metadata, presence of servers, and parametrized path/method/response-code expectations.

Changes

Cohort / File(s) Summary of changes
Integration tests for OpenAPI validation
tests/integration/test_openapi_json.py
Adds OPENAPI_FILE, a _load_openapi_spec() helper, a module-scoped spec pytest fixture, and tests verifying OpenAPI top-level fields, non-empty servers, and parametrized checks for paths, HTTP methods, and expected response codes against docs/openapi.json.

Sequence Diagram(s)

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

A rabbit hops through specs so fine,
Noses the JSON, line by line.
Paths and codes all neatly aligned,
Servers present, contracts signed.
With whiskered zeal and tiny grin,
“Your OpenAPI passes—let’s hop in!” 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 827524d and 3d22371.

📒 Files selected for processing (1)
  • tests/integration/test_openapi_json.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/integration/test_openapi_json.py
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: build-pr
  • GitHub Check: e2e_tests
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit 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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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.

@tisnik tisnik changed the title Elementary OpenAPI integration tests LCORE-628: Elementary OpenAPI integration tests Sep 2, 2025
@tisnik tisnik force-pushed the openapi_integration_tests branch from c4b5e9a to 827524d Compare September 2, 2025 08:08
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

🧹 Nitpick comments (8)
tests/integration/test_openapi_json.py (8)

1-6: Add a module docstring to satisfy linter C0114 and describe intent.

+"""Integration tests validating docs/openapi.json structure and key endpoints."""
+
 import json
 from pathlib import Path
 import typing as t
 
 import pytest

7-13: Strategy comment mentions components checks, but no tests cover them. Consider adding a minimal schema presence test.

@@
 #   * presence and key attributes of important component schemas (enums, required fields)
@@
 
 OPENAPI_FILE = "docs/openapi.json"
 
+
+def test_components_schemas_present(spec: dict):
+    """Ensure components/schemas section exists and is non-empty."""
+    components = spec.get("components") or {}
+    schemas = components.get("schemas") or {}
+    assert isinstance(schemas, dict) and schemas, "components.schemas must be a non-empty object"
+

17-25: Remove R1710 (inconsistent return) and provide clearer failures, including JSON decode errors.

 def _load_openapi_spec() -> dict:
     """Load OpenAPI specification from configured path."""
     path = Path(OPENAPI_FILE)
-    if path.is_file():
-        with path.open("r", encoding="utf-8") as f:
-            return json.load(f)
-
-    pytest.fail("OpenAPI spec not found")
+    if not path.is_file():
+        pytest.fail(f"OpenAPI spec not found at {path}")
+    try:
+        with path.open("r", encoding="utf-8") as f:
+            return json.load(f)
+    except json.JSONDecodeError as e:
+        pytest.fail(f"Invalid JSON in OpenAPI spec at {path}: {e}")
 

27-31: Rename fixture ‘spec’ to ‘openapi_spec’ to silence redefined-outer-name warnings and improve clarity; update callsites.

 @pytest.fixture(scope="module")
-def spec() -> dict:
+def openapi_spec() -> dict:
     """Fixture containing OpenAPI specification represented as a dictionary."""
     return _load_openapi_spec()
 
@@
-def test_openapi_top_level_info(spec: dict):
+def test_openapi_top_level_info(openapi_spec: dict):
     """Test all top level informations stored in OpenAPI specification."""
-    assert spec.get("openapi") == "3.1.0"
+    assert openapi_spec.get("openapi") == "3.1.0"
 
-    info = spec.get("info") or {}
+    info = openapi_spec.get("info") or {}
@@
-def test_servers_section_present(spec: dict):
+def test_servers_section_present(openapi_spec: dict):
     """Test the servers section stored in OpenAPI specification."""
-    servers = spec.get("servers")
+    servers = openapi_spec.get("servers")
@@
-def test_paths_and_responses_exist(
-    spec: dict, path: str, method: str, expected_codes: t.Set[str]
-):
+def test_paths_and_responses_exist(
+    openapi_spec: dict, path: str, method: str, expected_codes: t.Set[str]
+):
     """Tests all paths defined in OpenAPI specification."""
-    paths = spec.get("paths") or {}
+    paths = openapi_spec.get("paths") or {}

Also applies to: 33-47, 49-53, 76-90


33-47: Strengthen top-level assertions and avoid shadowing built-in ‘license’.

-    assert spec.get("openapi") == "3.1.0"
+    # Accept any 3.1.x patch version to reduce brittleness
+    assert (openapi_spec.get("openapi") or "").startswith("3.1."), "Expected OpenAPI 3.1.x"
@@
-    contact = info.get("contact") or {}
-    assert contact is not None
+    contact = info.get("contact") or {}
+    assert isinstance(contact, dict) and contact, "info.contact must be a non-empty object"
@@
-    license = info.get("license") or {}
-    assert license.get("name") == "Apache 2.0"
-    assert "apache.org/licenses" in (license.get("url") or "")
+    license_info = info.get("license") or {}
+    assert license_info.get("name") == "Apache 2.0"
+    assert "apache.org/licenses" in (license_info.get("url") or "")

49-53: Validate server objects contain non-empty ‘url’ fields.

     servers = spec.get("servers")
     assert isinstance(servers, list) and servers, "servers must be a non-empty list"
+    for s in servers:
+        assert isinstance(s, dict) and s.get("url"), "each server must define a non-empty 'url'"

76-90: Make method lookup case-insensitive; assert responses presence; show all missing codes at once.

-    op = (paths[path] or {}).get(method)
+    op = (paths[path] or {}).get(method.lower())
     assert isinstance(op, dict), f"Missing method {method.upper()} for path {path}"
-    responses = op.get("responses") or {}
-    got_codes = set(responses.keys())
-    for code in expected_codes:
-        assert (
-            code in got_codes
-        ), f"Missing response code {code} for {method.upper()} {path}"
+    assert "responses" in op and isinstance(op["responses"], dict) and op["responses"], \
+        f"Missing or empty responses for {method.upper()} {path}"
+    responses = op["responses"]
+    got_codes = set(responses.keys())
+    missing = expected_codes - got_codes
+    assert not missing, f"Missing response codes {sorted(missing)} for {method.upper()} {path}"

55-75: Optional: add ids=… to parametrize for clearer test names in reports.

Example:

  • ids like "GET /v1/info", "POST /v1/query", etc., matching each tuple.
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 2e39274 and 827524d.

📒 Files selected for processing (1)
  • tests/integration/test_openapi_json.py (1 hunks)
🧰 Additional context used
🪛 GitHub Actions: Python linter
tests/integration/test_openapi_json.py

[warning] 1-1: Missing module docstring (C0114).


[warning] 17-17: Inconsistent return statements (R1710).


[warning] 33-33: Redefining name 'spec' from outer scope (redefined-outer-name).


[warning] 44-44: Redefining built-in 'license' (redefined-builtin).


[warning] 49-49: Redefining name 'spec' from outer scope (redefined-outer-name).


[warning] 77-77: Redefining name 'spec' from outer scope (redefined-outer-name).

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: build-pr
  • GitHub Check: e2e_tests

@tisnik tisnik force-pushed the openapi_integration_tests branch from 827524d to 3d22371 Compare September 2, 2025 08:17
@tisnik tisnik merged commit b0ae4ea into lightspeed-core:main Sep 2, 2025
19 checks passed
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.

1 participant