Skip to content

Sub-refs in external refs results in incorrect and broken imports in generated models #968

Open
@caseyfw

Description

@caseyfw

Using a ref to refer to an object in a secondary file, that also uses refs to refer to other sibling objects results in strange incorrect imports in generated models.

For example, given the following spec:

# spec.yaml
components:
  schemas:
    LocalParent:
      $ref: './types.yaml#/components/schemas/Parent'

and the following secondary file:

# types.yaml
components:
  schemas:
    Parent:
      type: object
      properties:
        childA:
          $ref: '#/components/schemas/Child'
        childB:
          $ref: '#/components/schemas/Child'
    Child:
      type: string

Results in the following model with an import referencing a non-existent file:

# LocalParent.ts
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */

import type { LocalParent_properties_childA } from './LocalParent_properties_childA';

export type LocalParent = {
    childA?: string;
    childB?: LocalParent_properties_childA;
};

I'd like to resolve this myself, but have no idea where to start - I looked into the ref parser, but it seems to be returning a correct inventory. If you could nudge me in the right direction, I'm happy to do the legwork.

Thanks @ferdikoomen !

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions