-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Open
Description
When Route Path Contains No Placeholders, Path Parameters Declared in Request Are Still Generated (Resulting in Invalid Swagger)
Phenomenon
If a request struct declares path:"id", but the route path has no /:id (or {id}) placeholder, goctl still generates parameters with in: path, name: id in the swagger.
This creates swagger/OpenAPI semantic inconsistency: path parameters must appear in the URL template.
Minimal Reproduction
extra_path_param.api:
syntax = "v1"
info(
title: "t"
desc: "t"
author: "t"
email: "t"
)
type Req {
ID string `path:"id"`
}
@server(
prefix: /api/test
group: test
)
service t {
@handler H
get /foo (Req) returns ()
}Run:
goctl api swagger --api extra_path_param.api --dir . --filename extra_path_paramActual Result (Key Swagger Snippet)
[
{
"type": "string",
"name": "id",
"in": "path",
"required": true
}
]However, the corresponding path is /api/test/foo, which does not contain {id}.
Expected Result
- goctl should validate: only generate path parameters when the route path contains corresponding placeholders.
- Or at minimum print a warning / fail generation and prompt users to fix the
.apifile.
Possible Fix Directions (For PR Reference)
- When generating path parameters, the swagger generator should parse the route path (e.g.,
/foo) to extract the set of placeholders (id,namespace, etc.), and only keep matchingpath:"..."fields. - If request declares extra path parameters, suggest warning (and optionally error in strict mode).
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels