Skip to content

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

@jace1717

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions