Possible issue: "url" query/path parameter shadows the url module import in typescript-fetch generator
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 78/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Tranquilla
- Stack tecnologico
- typescript
- Ambito
- tooling
Direzione di ricerca
Iniziare in modules/swagger-codegen/src/main/resources/typescript-fetch/api.mustache esaminando l’importazione di url e le relative chiamate a parse/format. Generare il client typescript-fetch dal repro minimo di Swagger 2.0 salvato, con un parametro denominato url, quindi verificare che il codice generato venga compilato con tsc senza modificare i nomi pubblici dei parametri.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
What's broken: In modules/swagger-codegen/src/main/resources/typescript-fetch/api.mustache, the file does import * as url from "url"; (line 5) and later calls url.parse(...) (line 104) and url.format(...) (line 238) inside each generated operation method. But generated method parameters are named directly from the OpenAPI spec's parameter names (line 93), with no collision check against url. AbstractTypeScriptClientCodegen's reserved-word list (lines 53-58) covers TS keywords and a few internal names but not url, and TypeScriptFetchClientCodegen doesn't add it either.
Result: Any operation with a parameter literally named url (e.g. GET /webhooks?url=...) generates a method like:
listWebhooks(url?: string, options: any = {}): FetchArgs {
const localVarUrlObj = url.parse(localVarPath, true); // url = the string param, not the module
...
return { url: url.format(localVarUrlObj), options: localVarRequestOptions };
}
Because the parameter is typed string, this isn't a subtle runtime issue — it's a hard tsc compile error: Property 'parse' does not exist on type 'string'.
Repro spec: minimal Swagger 2.0 doc with one GET operation taking a query param named url — included in full in the saved file.
Related prior art: #6698 (closed, fixed by PR #6717) fixed an almost identical collision for a parameter named path, but only by renaming the template's local variables to localVar*-prefixed names. That fix never touched the import * as url from "url" binding, so this specific case slipped through and is still present on current master (c7dd2fc, pom 2.4.53-SNAPSHOT).
Suggested fix (recommended): alias the import, e.g. import * as _nodeUrl from "url";, and use _nodeUrl.parse/_nodeUrl.format in the template — fixes the whole class of import-vs-parameter-name collisions without touching generated public API (param names, FetchArgs.url, etc. stay the same). Alternatives: add url to the reserved-word list so it gets escaped like other reserved names, or stop relying on a bare top-level import that any parameter name can shadow.
- Lingua principale
- Mustache
- Stelle
- 17.8k
- Fork
- 6k
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di swagger-api/swagger-codegen
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
swagger-api/swagger-codegen#12445 ·
-
security vulnerability
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 62/100
swagger-api/swagger-codegen#11942 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
swagger-api/swagger-codegen#11812 · 1 reazione ·
-
security vulnerability
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
swagger-api/swagger-codegen#11594 ·
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 62/100
swagger-api/swagger-codegen#10969 ·
Tutte le issue di swagger-api/swagger-codegen
Issue simili
-
good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
block/artifact-swap#174 ·
-
app CLI enhancement TUI windows-os
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
use-agent-os/agent-os#3417 · 1 commento ·
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
apple/swift-async-algorithms#458 ·