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
asked 19 days ago268 views
2 Answers
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
EXPERT
answered 19 days ago
profile picture
EXPERT
reviewed 19 days ago
0

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

Paige
answered 18 days ago
  • Does my answer solve your question or do I misunderstand your issue?

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions