[Bug]: http-client-js ignores `NoAuth` in a `@useAuth` union

Aperta
#12,354 1 commento 1 reazione 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
57/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
typescript

Direzione di ricerca

Start by reading the http-client-js emitter's authentication handling and compare it with the Python emitter behavior referenced in the issue. Reproduce with the supplied @useAuth(BearerAuth | NoAuth) TypeSpec example using the listed package versions. Done means the generated constructor allows omitted credentials and an anonymous request has no Authorization header.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug emitter:client:js
Describe the bug

With @useAuth(BearerAuth | NoAuth), the client should allow anonymous requests. The emitted constructor requires a credential, and the bearer policy always sets Authorization: Bearer <token>. An empty token is not anonymous: some servers reject Authorization: Bearer with 401. Related: #6847 covers @useAuth(NoAuth) alone.

Reproduction

Every snippet uses this header:

import "@typespec/http";
using Http;
@service(#{ title: "Repro" })
@server("{endpoint}", "", { endpoint?: url = "http://localhost:3000" })
namespace Repro;

Emitted with @typespec/http-client-js (default options).

@useAuth(BearerAuth | NoAuth)
@get op read(): void;

Actual:

constructor(credential: BearerTokenCredential, options?: ReproClientOptions)

Expected: with NoAuth in the union, credential is optional, and the client sends no Authorization header without one. This matches the Python emitter (#9298).

Versions: @typespec/compiler 1.17.0, @typespec/http 1.17.0, @typespec/http-client-js 0.16.3. Also reproduced with the emitter built from main (721154b2a).

Checklist
Lingua principale
Java
Stelle
5.9k
Fork
421
Merge medio
2g 3h
PR unite (30g)
176

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di microsoft/typespec

Tutte le issue di microsoft/typespec

Issue simili

Altre issue su Java

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.