Skip to content

Commit

Permalink
Merge pull request #469 from tdakkota/fix/path-parsing
Browse files Browse the repository at this point in the history
fix(parser): ensure that paths are not duplicated
  • Loading branch information
ernado authored Jul 8, 2022
2 parents 2776a44 + a2d78bb commit 7a0510e
Show file tree
Hide file tree
Showing 7 changed files with 203 additions and 109 deletions.
152 changes: 75 additions & 77 deletions _testdata/examples/superset.json
Original file line number Diff line number Diff line change
Expand Up @@ -12172,18 +12172,16 @@
"tags": [
"Dashboards"
]
}
},
"/api/v1/dashboard/{id_or_slug}/charts": {
"get": {
"description": "Get the chart definitions for a given dashboard",
},
"delete": {
"description": "Deletes a Dashboard.",
"parameters": [
{
"in": "path",
"name": "id_or_slug",
"required": true,
"schema": {
"type": "string"
"type": "integer"
}
}
],
Expand All @@ -12193,24 +12191,15 @@
"application/json": {
"schema": {
"properties": {
"result": {
"items": {
"$ref": "#/components/schemas/ChartEntityResponseSchema"
},
"type": "array"
"message": {
"type": "string"
}
},
"type": "object"
}
}
},
"description": "Dashboard chart definitions"
},
"302": {
"description": "Redirects to the current digest"
},
"400": {
"$ref": "#/components/responses/400"
"description": "Dashboard deleted"
},
"401": {
"$ref": "#/components/responses/401"
Expand All @@ -12220,6 +12209,12 @@
},
"404": {
"$ref": "#/components/responses/404"
},
"422": {
"$ref": "#/components/responses/422"
},
"500": {
"$ref": "#/components/responses/500"
}
},
"security": [
Expand All @@ -12230,43 +12225,51 @@
"tags": [
"Dashboards"
]
}
},
"/api/v1/dashboard/{id_or_slug}/datasets": {
"get": {
"description": "Returns a list of a dashboard's datasets. Each dataset includes only the information necessary to render the dashboard's charts.",
},
"put": {
"description": "Changes a Dashboard.",
"parameters": [
{
"description": "Either the id of the dashboard, or its slug",
"in": "path",
"name": "id_or_slug",
"required": true,
"schema": {
"type": "string"
"type": "integer"
}
}
],
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/DashboardRestApi.put"
}
}
},
"description": "Dashboard schema",
"required": true
},
"responses": {
"200": {
"content": {
"application/json": {
"schema": {
"properties": {
"id": {
"type": "number"
},
"last_modified_time": {
"type": "number"
},
"result": {
"items": {
"$ref": "#/components/schemas/DashboardDatasetSchema"
},
"type": "array"
"$ref": "#/components/schemas/DashboardRestApi.put"
}
},
"type": "object"
}
}
},
"description": "Dashboard dataset definitions"
},
"302": {
"description": "Redirects to the current digest"
"description": "Dashboard changed"
},
"400": {
"$ref": "#/components/responses/400"
Expand All @@ -12279,6 +12282,12 @@
},
"404": {
"$ref": "#/components/responses/404"
},
"422": {
"$ref": "#/components/responses/422"
},
"500": {
"$ref": "#/components/responses/500"
}
},
"security": [
Expand All @@ -12291,16 +12300,16 @@
]
}
},
"/api/v1/dashboard/{pk}": {
"delete": {
"description": "Deletes a Dashboard.",
"/api/v1/dashboard/{id_or_slug}/charts": {
"get": {
"description": "Get the chart definitions for a given dashboard",
"parameters": [
{
"in": "path",
"name": "pk",
"name": "id_or_slug",
"required": true,
"schema": {
"type": "integer"
"type": "string"
}
}
],
Expand All @@ -12310,15 +12319,24 @@
"application/json": {
"schema": {
"properties": {
"message": {
"type": "string"
"result": {
"items": {
"$ref": "#/components/schemas/ChartEntityResponseSchema"
},
"type": "array"
}
},
"type": "object"
}
}
},
"description": "Dashboard deleted"
"description": "Dashboard chart definitions"
},
"302": {
"description": "Redirects to the current digest"
},
"400": {
"$ref": "#/components/responses/400"
},
"401": {
"$ref": "#/components/responses/401"
Expand All @@ -12328,12 +12346,6 @@
},
"404": {
"$ref": "#/components/responses/404"
},
"422": {
"$ref": "#/components/responses/422"
},
"500": {
"$ref": "#/components/responses/500"
}
},
"security": [
Expand All @@ -12344,51 +12356,43 @@
"tags": [
"Dashboards"
]
},
"put": {
"description": "Changes a Dashboard.",
}
},
"/api/v1/dashboard/{id_or_slug}/datasets": {
"get": {
"description": "Returns a list of a dashboard's datasets. Each dataset includes only the information necessary to render the dashboard's charts.",
"parameters": [
{
"description": "Either the id of the dashboard, or its slug",
"in": "path",
"name": "pk",
"name": "id_or_slug",
"required": true,
"schema": {
"type": "integer"
"type": "string"
}
}
],
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/DashboardRestApi.put"
}
}
},
"description": "Dashboard schema",
"required": true
},
"responses": {
"200": {
"content": {
"application/json": {
"schema": {
"properties": {
"id": {
"type": "number"
},
"last_modified_time": {
"type": "number"
},
"result": {
"$ref": "#/components/schemas/DashboardRestApi.put"
"items": {
"$ref": "#/components/schemas/DashboardDatasetSchema"
},
"type": "array"
}
},
"type": "object"
}
}
},
"description": "Dashboard changed"
"description": "Dashboard dataset definitions"
},
"302": {
"description": "Redirects to the current digest"
},
"400": {
"$ref": "#/components/responses/400"
Expand All @@ -12401,12 +12405,6 @@
},
"404": {
"$ref": "#/components/responses/404"
},
"422": {
"$ref": "#/components/responses/422"
},
"500": {
"$ref": "#/components/responses/500"
}
},
"security": [
Expand Down
47 changes: 47 additions & 0 deletions _testdata/negative/paths/duplicate_path_item.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"openapi": "3.0.3",
"info": {
"title": "title",
"version": "v0.1.0"
},
"paths": {
"/foo/{param1}": {
"parameters": [
{
"name": "param1",
"in": "path",
"required": true,
"schema": {
"type": "string"
}
}
],
"get": {
"responses": {
"200": {
"description": "User info"
}
}
}
},
"/foo/{param2}": {
"parameters": [
{
"name": "param2",
"in": "path",
"required": true,
"schema": {
"type": "string"
}
}
],
"get": {
"responses": {
"200": {
"description": "User info"
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"components": {
"parameters": {
"Parameter": {
"name": "parm",
"name": "param",
"in": "path",
"required": false,
"schema": {
Expand Down
14 changes: 14 additions & 0 deletions openapi/operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,20 @@ type Operation struct {
// Path is an operation path.
type Path []PathPart

// ID returns path, but without parameter names.
//
// For example, if path is "/users/{id}", ID returns "/users/{}".
func (p Path) ID() (path string) {
for _, part := range p {
if part.Raw != "" {
path += part.Raw
continue
}
path += "{}"
}
return
}

// String implements fmt.Stringer.
func (p Path) String() (path string) {
for _, part := range p {
Expand Down
Loading

0 comments on commit 7a0510e

Please sign in to comment.