Skip to content

PathItem support missing #2308

Closed
Closed

Description

@cdevienne

Summary

When using import-mapping with external OpenAPI files, the generated code references response
types without the external package prefix.

Expected Behavior

Response types from external files should be prefixed with the mapped package name.

Actual Behavior

The generated code references the type directly without the package prefix.

Minimal Reproduction

api.yaml:

paths:
  /v1/version:
    $ref: './types.yaml#/components/pathitems/VersionOperations'

types.yaml:

components:
  pathitems:
    VersionOperations:
      get:
        responses:
          '200':
            $ref: '#/components/responses/VersionGetResponse'

  responses:
    VersionGetResponse: 
      content:
        application/json:
          schema:
            type: string

config.yaml:

package: api
output: api.gen.go
generate:
  models: true
  gorilla-server: true
  strict-server: true
import-mapping:
  ./types.yaml: "types"

Generated Output (Incorrect)

type GetV1Version200JSONResponse struct{ VersionGetResponseJSONResponse }

Expected Output

type GetV1Version200JSONResponse struct{ externalRef0.VersionGetResponseJSONResponse }

Activity

  1. mromaszewicz commented on Mar 27, 2026

    @mromaszewicz
    Member

    This is all related, and very similar to #2288. Externalrefs were added after the code was written, and the traversal doesn't extend to all the same schema properties. The fix for #2288 will fix this too.

  2. mromaszewicz commented on Mar 27, 2026

    @mromaszewicz
    Member

    Oh, wait, this is different.

    @cdevienne . #/components/pathitems is an OpenAPI 3.1 property. We are using kin-openapi which doesn't support OpenAPI 3.1. Until we figure out how to support 3.1, we can't actually traverse into that.

    I'm going to work a little bit on my experimental 3.1 implementation to see if it works there.

    It looks like kin-openapi inlines this $ref and I don't know it's a ref. This means this would likely work within a single specification, because the pathitems would be invisibly inlined into the operations, but I can't get it working with externalRefs

  3. cdevienne commented on Mar 30, 2026

    @cdevienne
    Author

    Candid question: isn't the 'Origin' field in the Schema type of kin-openapi supposed to tell where the data type is actually defined?

  4. changed the title [-]External reference not properly prefixed in generated response types[/-] [+]PathItem support missing[/+] on Apr 29, 2026
  5. mromaszewicz commented on May 1, 2026

    @mromaszewicz
    Member

    I've investigated this by having Claude generate and test a spec against the feat/kin-openapi-3.1 branch, and I can confirm that the bug will still be present once we merge in 3.1 support, but there will be enough information in the spec to fix it. This is the root cause:

    After kin-openapi resolves the spec:

    • pathItem.Ref = "./types.yaml#/components/pathItems/VersionOperations" (preserved ✓)
    • responseRef.Ref = "#/components/responses/VersionGetResponse" — looks local, even though it's reached via an externally-ref'd path item.

    The codegen plumbing for path-item refs is partially in place: OperationDefinition.PathItemRef is set, externalPackageFor() resolves it to the import-mapped package, and ensureExternalRefsInResponseDefinitions(&defs, pathItem.Ref) qualifies the content schema of each response.

    But the strict-server envelope wraps a name derived from ResponseDefinition.Ref, set in pkg/codegen/operations.go around GenerateResponseDefinitions:

    if IsGoTypeReference(responseOrRef.Ref) {
        refType, err := RefPathToGoType(responseOrRef.Ref)
        // "#/components/responses/VersionGetResponse" -> "VersionGetResponse"
        rd.Ref = refType
    }

    pathItemRef isn't consulted here, so RefPathToGoType treats the response ref as local. ResponseDefinition.IsExternalRef() then returns false (it just checks for a . in Ref), and strict-interface.tmpl falls into the local-ref arm:

    type {{$receiverTypeName}} struct{ {{$ref}}{{.NameTagOrContentType}}Response }

    producing the unqualified VersionGetResponseJSONResponse.

  6. added this to the v2.8.0 milestone on May 1, 2026
  7. added 4 commits that reference this issue on Jun 21, 2026
    3258696
    b200a65
    4693b81
    5b7f232
  8. added 2 commits that reference this issue on Jun 23, 2026
    7e55f2a
    56decea
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

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions