Skip to content

Generated client code response object does not correctly reference a response from a separate yaml file #695

Closed

Description

@jace1717

Summary: the response object in a the generated client code does not honor the $ref of the of response, if the $ref is referring to content in a different spec file.

Setup:

PackageA/config.yaml

package: packageA
generate:
  models: true
  embedded-spec: true
  client: true
output-options:
  skip-prune: true
import-mapping:
  ../packageB/spec.yaml: github.com/deepmap/oapi-codegen/internal/test/externalref/packageB
skip-fmt: true
output: externalref.gen.go

PackageA/spec.yaml

paths:
  /api/test:
    post:
      operationId: TestApi
      summary: test
      description: test
      responses:
        '200':
          description: 'success'
          $ref: ../packageB/spec.yaml#/components/responses/ResponseC

PackageB/spec.yaml

components:
  schemas:
    ObjectB:
      type: object
      properties:
        name:
          type: boolean
  responses:
    ResponseC:
      description: ResponseC
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ObjectB'

Generated client code for packageA
//go:generate go run github.com/deepmap/oapi-codegen/cmd/oapi-codegen --config=config.yaml spec.yaml

type TestApiResponse struct {
	Body         []byte
	HTTPResponse *http.Response
	JSON200      *ObjectB
}

Expected:

type TestApiResponse struct {
	Body         []byte
	HTTPResponse *http.Response
	JSON200      *externalRef0.ObjectB
}

I've also attached a modified version of the internal\test\externalref code that demonstrates this issue.
externalref.zip

Activity

  1. jamietanna commented on Jul 28, 2022

    @jamietanna
    Member

    This might be related to #626

  2. jamietanna commented on Jan 19, 2024

    @jamietanna
    Member

    Hey @jace1717 this issue seems to be resolved now - would you mind confirming? I've raised #1391 which takes the code you've provided and moves it to its own test directory, can you confirm if I've done anything wrong, or if it looks like it is resolved?

  3. mromaszewicz commented on Feb 7, 2026

    @mromaszewicz
    Member

    This has been resolved. External reference handling for response definitions was fixed (ensureExternalRefsInResponseDefinitions in externalref.go). Response schemas referencing types from external packages now correctly use the externalRef prefix. The maintainer also confirmed this in Jan 2024 via #1391. Closing as resolved.

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

Metadata

Metadata

Assignees

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