Skip to content
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

update openapi response to add html parameters #7

Merged
merged 3 commits into from
Mar 25, 2025

Conversation

vincentsarago
Copy link
Member

closes #3

intercept openapi response from stac-fastapi and update the query-parameters and accepted headers

# before
curl http://127.0.0.1:8000/api | jq '.paths."/"'
{
  "get": {
    "summary": "Landing Page",
    "description": "Endpoint.",
    "operationId": "Landing_Page__get",
    "responses": {
      "200": {
        "description": "Successful Response",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/LandingPage"
            }
          }
        }
      }
    }
  }
}


# now
curl http://127.0.0.1:8000/api | jq '.paths."/"'
{
  "get": {
    "summary": "Landing Page",
    "description": "Endpoint.",
    "operationId": "Landing_Page__get",
    "responses": {
      "200": {
        "description": "Successful Response",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/LandingPage"
            }
          },
          "text/html": {}
        }
      }
    },
    "parameters": [
      {
        "name": "f",
        "in": "query",
        "required": false,
        "schema": {
          "anyOf": [
            {
              "enum": [
                "html"
              ],
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "description": "Response MediaType.",
          "title": "F"
        },
        "description": "Response MediaType."
      }
    ]
  }
}
Screenshot 2025-03-25 at 3 16 44 PM

openapi_doc = json.loads(body.decode())
for _, path in openapi_doc.get("paths").items():
if (
path.get("get", {}).get("summary", "").lower()
Copy link
Member Author

@vincentsarago vincentsarago Mar 25, 2025

Choose a reason for hiding this comment

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

openapi will use camel case for the summary, so by using lower case we make sure the name can match the one provided in endpoint_names

@vincentsarago vincentsarago merged commit d8cd9f3 into main Mar 25, 2025
5 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.

Intercept and customize openapi.json
1 participant