-
Notifications
You must be signed in to change notification settings - Fork 54
LCORE-433: Support for all OpenAPI metadata #387
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,13 +2,25 @@ | |
| "openapi": "3.1.0", | ||
| "info": { | ||
| "title": "Lightspeed Core Service (LCS) service - OpenAPI", | ||
| "summary": "Lightspeed Core Service (LCS) service API specification.", | ||
| "description": "Lightspeed Core Service (LCS) service API specification.", | ||
| "contact": { | ||
| "name": "Pavel Tisnovsky", | ||
| "url": "https://github.com/tisnik/", | ||
| "email": "ptisnovs@redhat.com" | ||
| }, | ||
| "license": { | ||
| "name": "Apache 2.0", | ||
| "url": "https://www.apache.org/licenses/LICENSE-2.0.html" | ||
| }, | ||
| "version": "0.1.3" | ||
| }, | ||
| "servers": [ | ||
| { | ||
| "url": "http://localhost:8080/", | ||
| "description": "Locally running service" | ||
| } | ||
| ], | ||
|
Comment on lines
+18
to
+23
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainProvide multi-environment servers and/or use templated server variables Shipping only a localhost server in published OpenAPI can mislead consumers and some tooling will attempt to call localhost by default. Recommend adding a generic templated server and keeping localhost for dev. Apply this diff: - "servers": [
- {
- "url": "http://localhost:8080/",
- "description": "Locally running service"
- }
- ],
+ "servers": [
+ {
+ "url": "{scheme}://{host}{basePath}",
+ "description": "Default environment",
+ "variables": {
+ "scheme": { "default": "https", "enum": ["http", "https"] },
+ "host": { "default": "api.example.com" },
+ "basePath": { "default": "/" }
+ }
+ },
+ {
+ "url": "http://localhost:8080",
+ "description": "Locally running service"
+ }
+ ],To verify that the new metadata (summary/contact/servers) is sourced from code and the checked-in docs aren’t drifting from the generator, run: 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "Searching for OpenAPI generation and FastAPI app metadata in the repo..."
echo "— Files with get_openapi or FastAPI instantiation —"
rg -n -A3 -B3 'get_openapi|FastAPI\(' || true
echo
echo "— Potential contact/servers wiring in Python —"
rg -n -A2 -B2 'contact=|servers=|summary=' || true
echo
echo "— Current contact and servers in docs/openapi.json —"
rg -n -A3 -B1 '"contact"|^ {0,}"servers": \[' docs/openapi.json || trueLength of output: 9029 Update FastAPI servers in application code • File: src/app/main.py (around lines 38–40) Suggested diff in --- a/src/app/main.py
@@ app = FastAPI(
- servers=[{"url": "http://localhost:8080/", "description": "Locally running service"}],
+ servers=[
+ {
+ "url": "{scheme}://{host}{basePath}",
+ "description": "Default environment",
+ "variables": {
+ "scheme": {"default": "https", "enum": ["http", "https"]},
+ "host": {"default": "api.example.com"},
+ "basePath": {"default": "/"}
+ }
+ },
+ {
+ "url": "http://localhost:8080/",
+ "description": "Locally running service"
+ }
+ ],🤖 Prompt for AI Agents |
||
| "paths": { | ||
| "/": { | ||
| "get": { | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -35,6 +35,7 @@ dependencies = [ | |||
| "authlib>=1.6.0", | ||||
| "openai==1.99.1", | ||||
| "sqlalchemy>=2.0.42", | ||||
| "email-validator>=2.2.0", | ||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainValidate the need for FastAPI/OpenAPI contact email does not require this package. Keep it only if you use Pydantic’s Run this repo scan to confirm actual usage before merging: 🏁 Script executed: #!/bin/bash
# Find references to EmailStr or email validation usage
rg -n --hidden --glob '!**/dist/**' --glob '!**/build/**' --glob '!**/node_modules/**' $'\\bEmailStr\\b|email-validator'Length of output: 321 🏁 Script executed: #!/bin/bash
# Search for direct imports or usage of the email-validator library
rg -n -E --hidden --glob '!**/dist/**' --glob '!**/build/**' --glob '!**/node_modules/**' '\b(email_validator|validate_email)\b'Length of output: 537 Consider removing the • File to update:
📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||
| ] | ||||
|
|
||||
| [tool.pyright] | ||||
|
|
||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -67,11 +67,14 @@ def read_version_from_pyproject(): | |||||||||||||||||||||||||||||||||||||||||||||||||
| # retrieve OpenAPI schema via initialized app | ||||||||||||||||||||||||||||||||||||||||||||||||||
| open_api = get_openapi( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| title=app.title, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| summary=app.summary, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| version=app.version, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| openapi_version=app.openapi_version, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| description=app.description, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| routes=app.routes, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| license_info=app.license_info, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| servers=app.servers, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| contact=app.contact, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
68
to
78
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainConfirm
Suggested change: open_api = get_openapi(
title=app.title,
- summary=app.summary,
+ summary=getattr(app, "summary", None),
version=app.version,
openapi_version=app.openapi_version,
description=app.description,
routes=app.routes,
+ terms_of_service=getattr(app, "terms_of_service", None),
+ tags=getattr(app, "openapi_tags", None),
license_info=app.license_info,
servers=app.servers,
contact=app.contact,
)To verify signature support: 🌐 Web query: 💡 Result: Yes. fastapi.openapi.utils.get_openapi accepts a summary parameter, and it’s supported starting from FastAPI 0.99.0 (with OpenAPI 3.1.0 support). The docs note: “The parameter summary is available in OpenAPI 3.1.0 and above, supported by FastAPI 0.99.0 and above.”[1]
Citations:
Confirm Locations to update:
Suggested diff: scripts/generate_openapi_schema.py
@@ -68,6 +68,8 @@
open_api = get_openapi(
title=app.title,
- summary=app.summary,
+ summary=getattr(app, "summary", None),
version=app.version,
openapi_version=app.openapi_version,
description=app.description,
routes=app.routes,
+ terms_of_service=getattr(app, "terms_of_service", None),
+ tags=getattr(app, "openapi_tags", None),
license_info=app.license_info,
servers=app.servers,
contact=app.contact,
)Note: The 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| # dump the schema into file | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,12 +23,21 @@ | |
|
|
||
| app = FastAPI( | ||
| title=f"{service_name} service - OpenAPI", | ||
| summary=f"{service_name} service API specification.", | ||
| description=f"{service_name} service API specification.", | ||
| version=version.__version__, | ||
| contact={ | ||
| "name": "Pavel Tisnovsky", | ||
| "url": "https://github.com/tisnik/", | ||
| "email": "ptisnovs@redhat.com", | ||
| }, | ||
| license_info={ | ||
| "name": "Apache 2.0", | ||
| "url": "https://www.apache.org/licenses/LICENSE-2.0.html", | ||
| }, | ||
| servers=[ | ||
| {"url": "http://localhost:8080/", "description": "Locally running service"} | ||
| ], | ||
|
Comment on lines
+38
to
+40
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent ❓ Verification inconclusiveAvoid hard-coded localhost server and trailing slash in OpenAPI servers
Minimal change: - servers=[
- {"url": "http://localhost:8080/", "description": "Locally running service"}
- ],
+ servers=[
+ {"url": "http://localhost:8080", "description": "Locally running service"}
+ ],Optional improvement (outside this hunk): compute at runtime # e.g., prefer relative base for portability
servers=[{"url": "/", "description": "Same origin"}]
# or, if you must include localhost for docs only, gate it via env/configRemove hard-coded localhost server URL and trailing slash Hard-coding
- servers=[
- {"url": "http://localhost:8080/", "description": "Locally running service"}
- ],
+ servers=[
+ {"url": "http://localhost:8080", "description": "Locally running service"}
+ ],Optional refactor ideas (outside this hunk): # Use same-origin for portability
servers = [{"url": "/", "description": "Same origin"}]
# Or drive via env/config for docs only
servers = [{"url": os.getenv("API_BASE_URL", "/"), "description": "API base URL"}]🤖 Prompt for AI Agents |
||
| ) | ||
|
|
||
| app.add_middleware( | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
Avoid publishing a personal email in OpenAPI contact metadata
Including an individual’s corporate email in public API docs can create PII/privacy concerns and spam. Prefer a role-based alias or omit email until one exists.
Option A — switch to a team contact and project URL:
Option B — remove the email field and keep current name/url:
📝 Committable suggestion
🤖 Prompt for AI Agents