[Go] OAuth client credentials: an optional enum grant_type in the token request makes the SDK fail to compile

Aperta
#18,316 0 commenti 0 reazioni 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
68/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
go, openapi, typescript

Direzione di ricerca

Start in generators/go-v2/sdk/src/client/ClientGenerator.ts near the reported line 902 and trace how optional enum grant_type values are emitted. Use the OpenAPI repro and run fern generate --local --group go --force, then go build ./... in the generated SDK. Done when the generated request uses the enum pointer value and the Go SDK builds.

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

Descrizione

The following is AI-written (Claude Opus 5.5). It found this in charter's conformance projects, reduced it to the repro below, and checked it on the versions named.

Component

SDK generation (OAuth client credentials)

SDK Language(s)

Go

Versions

  • Fern CLI 5.158.0, fern generate --local
  • fernapi/fern-go-sdk 1.70.5 (the newest today)
  • Go 1.27.1

Repro

fern/fern.config.json

{ "organization": "repro", "version": "5.158.0" }

fern/openapi.yml

openapi: 3.1.0
info: { title: Repro, version: 1.0.0 }
servers: [{ url: https://api.example.com }]
components:
  securitySchemes:
    OAuth:
      type: oauth2
      flows:
        clientCredentials:
          tokenUrl: /oauth/token
          scopes: {}
paths:
  /oauth/token:
    post:
      operationId: getToken
      tags: [auth]
      security: []
      requestBody:
        required: true
        content:
          application/x-www-form-urlencoded:
            schema:
              type: object
              properties:
                grant_type: { type: string, enum: [client_credentials] }
                client_id: { type: string }
                client_secret: { type: string }
      responses:
        "200":
          description: token
          content:
            application/json:
              schema:
                type: object
                required: [access_token, expires_in]
                properties:
                  access_token: { type: string }
                  expires_in: { type: integer }
  /ping:
    get:
      operationId: ping
      security: [{ OAuth: [] }]
      responses:
        "200":
          description: ok
          content:
            application/json:
              schema: { type: string }

fern/generators.yml

api:
  specs:
    - openapi: openapi.yml
  auth-schemes:
    OAuth:
      scheme: oauth
      type: client-credentials
      get-token:
        endpoint: "POST /oauth/token"
        request-properties:
          client-id: $request.client_id
          client-secret: $request.client_secret
        response-properties:
          access-token: $response.access_token
          expires-in: $response.expires_in
  auth: OAuth
groups:
  go:
    generators:
      - name: fernapi/fern-go-sdk
        version: 1.70.5
        output:
          location: local-file-system
          path: ../sdk/go
        config:
          module:
            path: example.com/repro
            version: "1.22"
          packageName: repro

Command

fern generate --local --group go --force
cd sdk/go && go build ./...

Output

# example.com/repro/client
client/client.go:43:16: cannot use repro.String("client_credentials") (value of type *string) as *repro.GetTokenRequestGrantType value in struct literal

The generated token request in client/client.go:

GrantType: repro.String(
	"client_credentials",
),

The field is GrantType *GetTokenRequestGrantType, and GetTokenRequestGrantTypeClientCredentials is generated.

Expected

The SDK compiles, for example with GrantType: repro.GetTokenRequestGrantTypeClientCredentials.Ptr().

Notes

  • With grant_type: { type: string } the same spec passes go build and go vet.
  • With required: [grant_type] and the enum kept, it compiles (GrantType: "client_credentials").
  • On main, generators/go-v2/sdk/src/client/ClientGenerator.ts (around line 902, added in #17076) writes <pkg>.String("client_credentials") for every pointer grant_type that is not a literal, enum or not.

How charter works around it: grant_type is an optional plain string, and its server refuses any other grant with a 400.

Lingua principale
TypeScript
Stelle
3.8k
Fork
376
Merge medio
9h 15m
PR unite (30g)
171

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

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 fern-api/fern

Tutte le issue di fern-api/fern

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.