Skip to content

[Go] generated OAuth wire test references undefined type "<module>.Request" for a form-encoded client-credentials token endpoint #18200

Open

Description

@robbyblack2

Summary

With an OAuth client-credentials auth-schemes block pointing at a token endpoint whose request body is application/x-www-form-urlencoded, fern-go-sdk 1.70.0 emits a wire test (<group>/oauth_wire_test/oauth_wire_test.go) that references <module>.Request, a type that is never generated. The SDK itself compiles and every other wire test (which authenticates through option.WithClientCredentials) passes; only this test package fails go vet / go test.

Versions

  • Fern CLI 5.149.0, fern generate --local
  • fernapi/fern-go-sdk 1.70.0
  • OpenAPI 3.1 spec, operation oauthToken = POST /api/v1/oauth/token, request body application/x-www-form-urlencoded → $ref: OauthTokenRequest (properties grant_type (required, enum), client_id, client_secret, scope, code, code_verifier, redirect_uri, refresh_token), response OauthTokenResponse (access_token, token_type, expires_in, scope, refresh_token)

generators.yml

api:
  auth: OAuth
  specs:
    - openapi: ../../../stable/openapi.json
auth-schemes:
  OAuth:
    scheme: oauth
    type: client-credentials
    client-id-env: PANGEASHIELD_CLIENT_ID
    client-secret-env: PANGEASHIELD_CLIENT_SECRET
    get-token:
      endpoint: "POST /api/v1/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
groups:
  go:
    generators:
      - name: fernapi/fern-go-sdk
        version: 1.70.0
        output:
          location: local-file-system
          path: ../../../build/stable/go
        config:
          module:
            path: github.com/PangeaShield/pangeashield-sdk-go
          enableWireTests: true

Generated test (serviceaccounts/oauth_wire_test/oauth_wire_test.go, lines 60–75)

func TestOAuthGetTokenFormEncodedBody(t *testing.T) {
	transport := &requestCapturingTransport{}
	httpClient := &http.Client{Transport: transport}

	c := client.NewClient(
		option.WithBaseURL("http://localhost:8080"),
		option.WithHTTPClient(httpClient),
		option.WithClientCredentials("test_client_id", "test_client_secret"),
	)

	request := &pangeashieldsdkgo.Request{          // <-- undefined
		ClientID:     pangeashieldsdkgo.String("test_client_id"),
		ClientSecret: pangeashieldsdkgo.String("test_client_secret"),
	}

	_, err := c.ServiceAccounts.OauthToken(context.Background(), request)

The generated client method expects the real type:

func (c *Client) OauthToken(ctx context.Context, request *pangeashieldsdkgo.OauthTokenRequest, opts ...option.RequestOption) (*pangeashieldsdkgo.OauthTokenResponse, error)

Error

vet: serviceaccounts/oauth_wire_test/oauth_wire_test.go:70:32: undefined: pangeashieldsdkgo.Request

(the same reference appears again at line 119)

Expected

The test should construct &pangeashieldsdkgo.OauthTokenRequest{...} (the request-body type of the token endpoint, including its required GrantType field), or the test should be skipped when the token request is form-encoded if that is unsupported.

Workaround

CI runs go vet/go test on $(go list ./... | grep -v /oauth_wire_test).

Activity

  1. changed the title [-][Go] generated OAuth wire test references undefined type for a form-encoded client-credentials token endpoint[/-] [+][Go] generated OAuth wire test references undefined type "<module>.Request" for a form-encoded client-credentials token endpoint[/+] on Oct 9, 2026
  2. joeblew999 commented on Oct 15, 2026

    @joeblew999

    The following is AI-written (Claude Opus 5.5). It found this in charter's conformance projects and checked it again today.

    Still reproduces with fernapi/fern-go-sdk 1.70.5 and Fern CLI 5.158.0, in a smaller case:

    • a form-encoded token endpoint (tagged auth) whose body is $ref: "#/components/schemas/TokenRequest";
    • with only optional string grant_type, client_id and client_secret.

    go build ./... passes, but go vet ./... gives vet: auth/oauth_wire_test/oauth_wire_test.go:70:20: undefined: repro.Request. Renaming the schema (e.g. Credentials) gives the same repro.Request, so the name the test uses does not come from the schema. The test is generated without enableWireTests set. With the schema inline instead of a $ref, the test compiles.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions