Skip to content

$ref in responses is not adding the imported reference properly #2113

@angelcervera

Description

@angelcervera

Using this model definition as an example:

openapi: 3.0.4

components:
  schemas:
    ProblemDetails:
      type: object
      description: RFC 7807 Problem Details
      properties:
        type:
          type: string
          format: uri
          description: A URI reference that identifies the problem type
        title:
          type: string
          description: A short, human-readable summary of the problem type
        status:
          type: integer
          description: The HTTP status code
      required: [title, status]
  responses:
    StandardError:
      description: Error response using RFC 7807 Problem Details
      content:
        application/problem+json:
          schema:
            $ref: "#/components/schemas/ProblemDetails"

Next definition is working fine:

        default:
          description: Error (RFC 7807)
          content:
            application/problem+json:
              schema:
                $ref: "./common/problemdetails.yaml#/components/schemas/ProblemDetails"

generating this code:

import externalRef3 "github.com/XXXXXX/YYYYYY/generated/go/common/problemdetails"

type UsersListdefaultApplicationProblemPlusJSONResponse struct {
	Body       externalRef3.ProblemDetails
	StatusCode int
}

But this definition is not generating the right code :

        default:
          $ref: "./common/problemdetails.yaml#/components/responses/StandardError"

generating this code, where is not using the reference to access to the model:

import externalRef3 "github.com/XXXXXX/YYYYYY/generated/go/common/problemdetails"

type UsersListdefaultApplicationProblemPlusJSONResponse struct {
	Body       ProblemDetails // FAILING HERE. Should be externalRef3.ProblemDetails
	StatusCode int
}

Next is the config file:

package: users
output: ../../../../generated/go/users/handlers.chi.gen.go
generate:
  models: true
  embedded-spec: true
  strict-server: true
  chi-server: true
output-options:
  skip-prune: true
import-mapping:
  ./common/problemdetails.yaml: "github.com/XXXXXX/YYYYYY/generated/go/common/problemdetails"

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