Can you have multiple dynamic paths in API Gateway, defined by an OpenAPI spec?

1

I have an open API 3.0 spec that I am trying to upload into API Gateway. I have two paths that are both dynamic, but one has more variables than the other. For example:

paths:
  /{a_path}
    get:
     ...
  /{b_path}/{x}/{y}/{z} 
    get:
      ...

When I try to import my spec into API Gateway I get the following error,

Unable to create resource at path '/{b_path}/{x}/{y}/{z}': A sibling ({a_path}) of this resource already has a variable path part -- only one is allowed

Is this allowed? Any recommendation on how to change my spec to allow for these multiple dynamic paths? This pattern has worked on GCP, so I am assuming that this is not an Open API restriction.

Paige
已提問 1 個月前檢視次數 287 次
2 個答案
1

Hi,

Yes, It is possible to have multiple dynamic paths, as long as the path variables are the same. I assume that the API Gateway will validate the route path by path, and there can be no ambiguities.

{
  "openapi" : "3.0.1",
  "info" : {
    "title" : "Test",
  },
  "paths" : {
    "/{a}" : {
      "get" : {
        "parameters" : [ {
          "name" : "a",
          "in" : "path",
          "required" : true,
          "schema" : {
            "type" : "string"
          }
        } ],
        "responses" : {
          "200" : {
            "description" : "200 response",
            "content" : {
              "application/json" : {
                "schema" : {
                  "$ref" : "#/components/schemas/Empty"
                }
              }
            }
          }
        }
      }
    },

    "/{a}/{b}" : {
      "get" : {
        "parameters" : [ {
          "name" : "a",
          "in" : "path",
          "required" : true,
          "schema" : {
            "type" : "string"
          }
        }, {
          "name" : "b",
          "in" : "path",
          "required" : true,
          "schema" : {
            "type" : "string"
          }
        } ],
        "responses" : {
          "200" : {
            "description" : "200 response",
            "content" : {
              "application/json" : {
                "schema" : {
                  "$ref" : "#/components/schemas/Empty"
                }
              }
            }
          }
        }
      }
    },
  },
  "components" : {
    "schemas" : {
      "Empty" : {
        "title" : "Empty Schema",
        "type" : "object"
      }
    }
  }
}

profile picture
專家
已回答 1 個月前
profile picture
專家
已審閱 1 個月前
0

The non-matching path variables was my issue, thank you for the response!

Paige
已回答 1 個月前
  • Does my answer solve your question or do I misunderstand your issue?

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南