Skip to content

Invalid OpenAPI JSON - path parameter collection_id missing in PUT and POST #416

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

Closed
robintw opened this issue Jun 24, 2022 · 2 comments · Fixed by #425
Closed

Invalid OpenAPI JSON - path parameter collection_id missing in PUT and POST #416

robintw opened this issue Jun 24, 2022 · 2 comments · Fixed by #425

Comments

@robintw
Copy link
Contributor

robintw commented Jun 24, 2022

I'm trying to use the OpenAPI JSON produced by stac-fastapi to set up the API in Azure API Management. When validating the OpenAPI JSON, I get the following error

Declared path parameter "collection_id" needs to be defined within every operation in the path (missing in "put", "post"), or moved to the path-level parameters object

This can be fixed by manually editing the OpenAPI JSON and adding:

"parameters": [
    {
        "description": "Collection ID",
        "required": true,
        "schema": {
            "title": "Collection Id",
            "type": "string",
            "description": "Collection ID"
        },
        "name": "collection_id",
        "in": "path"
    }
],

into the definitions for the PUT and POST requests for /collections/{collection_id}/items.

I've tried to work out how to fix this myself, and have tracked it down to the differences between the code in register_get_item_collection in app.py and register_create_item and register_update_item in transaction.py. The former defines a request model:

request_model = create_request_model(
            "ItemCollectionURI",
            base_model=ItemCollectionUri,
            mixins=[get_pagination_model],
        )

that specifies the collection_id path parameter. But the latter only specify a request model of Item which doesn't have that path parameter.

I've tried creating a new request model of:

class ItemWithCollectionPathParam(stac_types.Item):
    collection_id: str = attr.ib(default=Path(..., description="Collection ID"))

and using that as the request model as follows:

def register_create_item(self):
        """Register create item endpoint (POST /collections/{collection_id}/items)."""
        self.router.add_api_route(
            name="Create Item",
            path="/collections/{collection_id}/items",
            response_model=Item if self.settings.enable_response_models else None,
            response_class=self.response_class,
            response_model_exclude_unset=True,
            response_model_exclude_none=True,
            methods=["POST"],
            endpoint=self._create_endpoint(self.client.create_item, ItemWithCollectionPathParam),
        )

But that doesn't seem to fix the OpenAPI JSON.

I'm happy to put in a PR to fix this, if someone can give me some advice on where/how to fix it.

@duckontheweb
Copy link
Contributor

@robintw I believe this is actually related to #406 and #384. Those endpoints did not include the {collection_id} in the request model, and I am guessing that is why they do not show up in the OpenAPI JSON. I'm working on a PR to address those issues and I'll let you know if it fixes this one as well.

@robintw
Copy link
Contributor Author

robintw commented Jul 20, 2022

That sounds great, thanks @duckontheweb

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 a pull request may close this issue.

2 participants