Skip to content

[BUG] Golang - When using import mappings, import mapping is not properly generated when using composition plus slice pointer type #2008

Closed

Description

@chaslain

one.yaml

schemas:
  Thing:
          type: object
          properties:
           Property: value
  Example:
    properties:
      Thing
        type: array
        items: $ref "#/components/schemas/Thing"
          

two.yaml

schemas:
   MyThing:
     allOf:
       - $ref: "one.yaml#/components/schemas/Example'
       - type: object
          properties: # whatever one might add here...

Output when generating two.yaml:

type MyThing struct {
    Thing *[]Thing
}

Expected output generating two.yaml:

type MyThing struct {
    Thing *[]externalRef0.Thing
}
Steps to reproduce
  1. create two specs, one referencing the other
  2. Reference a slice type from 1 to another
  3. optional reference a non slice type to see desired behavior
  4. write configuration file to point import mapping of spec 2 to spec 1's output generation
  5. Run the generator
Suggest a fix

Use same external mapping logic when type is a slice pointer.

Activity

  1. changed the title [-][BUG] Golang - When using import mappings, import mapping is not properly generated when using composition plus slice type[/-] [+][BUG] Golang - When using import mappings, import mapping is not properly generated when using composition plus slice pointer type[/+] on Jun 20, 2025
  2. chaslain commented on Jun 23, 2025

    @chaslain
    Author

    This issue does not appear in master - is it time for another release?

    Cannot access master without forking.

  3. LarsStegman commented on Sep 15, 2025

    @LarsStegman

    Are you sure this doesn't happen in master? I tried it with the master build, but it isn't working for me.

  4. mromaszewicz commented on May 1, 2026

    @mromaszewicz
    Member

    Issue #2008 reports that allOf composition with an external ref produces unqualified array item types (e.g., *[]Thing instead of *[]externalRef0.Thing). PR #2299 (commit 1c89479, merged 2026-04-29) added propagateRemoteRefs() in pkg/codegen/merge_schemas.go, which recursively rewrites local #/... refs — including array item refs — to include the remote component path when an external schema is flattened via allOf. A repro spec built from the issue description generates the correct *[]externalRef0.Thing output on current HEAD, and the regression test in internal/test/externalref/packageA confirms *[]externalRef0.Role is correctly generated. The first commenter on the issue noted 3 days after opening that it didn't reproduce on master, consistent with this being fixed before any release.

    Closing as fixed. If you can still reproduce on a recent release, please reopen with the exact spec and version used.

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