Skip to content

External references are not dereferenced in header->schema #2060

@radhus

Description

@radhus

When generating server response models, external package imports are not being set on the referenced header types when their schema specifications are also refs. Similar, but not equal, to issue #1087.

I took a quick look at the code but couldn't very easily figure out where to fix it. Might have time to look over it in more detail at a later time and see if I can produce a fix myself.

Reproducing steps

Building on the import-mapping/multipackages examples.

Full example committed here: radhus@695a09a

Add a header and schema in common/api.yml:

components:
  schemas:
    [...]
    ETagSchema:
      type: string
      description: RFC 7232

  headers:
    ETag:
      description: Custom header
      schema:
        $ref: "#/components/schemas/ETagSchema"

Use header in admin/api.yml:

paths:
  /admin/user/{id}:
    get:
      [...]
      responses:
        200:
          [...]
          headers:
            ETag:
              $ref: '../common/api.yaml#/components/headers/ETag'

Struct with wrong type

Regenerate with strict-server: true to get the response structs generated. Look at admin/server.gen.go

type GetUserById200ResponseHeaders struct {
	ETag ETagSchema
}

Expected result

The schema should be referenced from the other package:

type GetUserById200ResponseHeaders struct {
	ETag externalRef0.ETagSchema
}

Metadata

Metadata

Assignees

No one assigned

    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