Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failing to create json schemas for Ocktokit types #1847

Open
elios264 opened this issue Jan 11, 2024 · 1 comment
Open

Failing to create json schemas for Ocktokit types #1847

elios264 opened this issue Jan 11, 2024 · 1 comment
Labels

Comments

@elios264
Copy link

This is the error:

[email protected]/node_modules/ts-json-schema-generator/src/ChainNodeParser.ts:50
        throw new UnknownNodeError(node, context.getReference());
              ^
UnknownNodeError: Unknown node " import("@octokit/types").RequestInterface<object>" of kind "LastTypeNode"
    at ChainNodeParser.getNodeParser (node_modules/.pnpm/[email protected]/node_modules/ts-json-schema-generator/src/ChainNodeParser.ts:50:15)
    at ChainNodeParser.createType (node_modules/.pnpm/[email protected]/node_modules/ts-json-schema-generator/src/ChainNodeParser.ts:35:25)
    at TypeofNodeParser.createType (node_modules/.pnpm/[email protected]/node_modules/ts-json-schema-generator/src/NodeParser/TypeofNodeParser.ts:38:45)
    at ChainNodeParser.createType (node_modules/.pnpm/[email protected]/node_modules/ts-json-schema-generator/src/ChainNodeParser.ts:35:54)
    at AnnotatedNodeParser.createType (node_modules/.pnpm/[email protected]/node_modules/ts-json-schema-generator/src/NodeParser/AnnotatedNodeParser.ts:34:47)
    at /User.pnpm/[email protected]/node_modules/ts-json-schema-generator/src/NodeParser/InterfaceAndClassNodeParser.ts:145:46
    at Array.map (<anonymous>)
    at InterfaceAndClassNodeParser.getProperties (node_modules/.pnpm/[email protected]/node_modules/ts-json-schema-generator/src/NodeParser/InterfaceAndClassNodeParser.ts:141:14)
    at InterfaceAndClassNodeParser.createType (node_modules/.pnpm/[email protected]/node_modules/ts-json-schema-generator/src/NodeParser/InterfaceAndClassNodeParser.ts:47:33)
    at AnnotatedNodeParser.createType (node_modules/.pnpm/[email protected]/node_modules/ts-json-schema-generator/src/NodeParser/AnnotatedNodeParser.ts:34:47) {
  node: <ref *1> NodeObject {
    pos: 29,
    end: 79,
    flags: 33554432,
    modifierFlagsCache: 0,
    transformFlags: 1,
    parent: NodeObject {
      pos: 20,
      end: 79,
      flags: 33554432,
      modifierFlagsCache: 536870912,
      transformFlags: 1,
      parent: [NodeObject],
      kind: 260,
      symbol: [SymbolObject],
      localSymbol: [SymbolObject],
      name: [IdentifierObject],
      exclamationToken: undefined,
      type: [Circular *1],
      initializer: undefined,
      jsDoc: undefined
    },
    kind: 205,
    argument: NodeObject {
      pos: 37,
      end: 53,
      flags: 33554432,
      modifierFlagsCache: 0,
      transformFlags: 1,
      parent: [Circular *1],
      kind: 201,
      literal: [NodeObject]
    },
    attributes: undefined,
    qualifier: IdentifierObject {
      pos: 55,
      end: 71,
      flags: 33554432,
      modifierFlagsCache: 0,
      transformFlags: 0,
      parent: [Circular *1],
      kind: 80,
      escapedText: 'RequestInterface',
      jsDoc: undefined,
      flowNode: [Object],
      symbol: undefined
    },
    typeArguments: [
      [TokenObject],
      pos: 72,
      end: 78,
      hasTrailingComma: false,
      transformFlags: 1
    ],
    isTypeOf: false
  },
  reference: <ref *2> NodeObject {
    pos: 905,
    end: 917,
    flags: 0,
    modifierFlagsCache: 0,
    transformFlags: 1,
    parent: NodeObject {
      pos: 905,
      end: 926,
      flags: 0,
      modifierFlagsCache: 0,
      transformFlags: 1,
      parent: [NodeObject],
      kind: 199,
      objectType: [Circular *2],
      indexType: [NodeObject],
      id: 80070
    },
    kind: 183,
    typeName: IdentifierObject {
      pos: 905,
      end: 917,
      flags: 0,
      modifierFlagsCache: 0,
      transformFlags: 0,
      parent: [Circular *2],
      kind: 80,
      escapedText: 'OctokitType',
      jsDoc: undefined,
      flowNode: [Object],
      symbol: undefined
    },
    typeArguments: undefined,
    id: 80069
  }
}

this is the fike:

import { Octokit } from '@octokit/rest';

type PromiseType<T extends Promise<unknown>> = T extends Promise<infer U>
    ? U
    : never;
type OctokitType = InstanceType<typeof Octokit>;
type ApiReturnType<T extends (...args: any) => Promise<any>> = PromiseType<
    ReturnType<T>
>['data'];

type GetBranchProtection = OctokitType['repos']['getBranchProtection'];
type GetRepos = OctokitType['apps']['listReposAccessibleToInstallation'];
type GetInstallation = OctokitType['apps']['getInstallation'];
type ListMembers = OctokitType['orgs']['listMembers'];
type ListCollaborators = OctokitType['repos']['listCollaborators'];
type BranchProtection = ApiReturnType<GetBranchProtection>;
type UserBase = ApiReturnType<ListMembers>['0'];
type CollaboratorBase = ApiReturnType<ListCollaborators>[0];
type RepositoryBase = ApiReturnType<GetRepos>['repositories'][0];

export type AuthInfo = {
    app: ApiReturnType<GetInstallation>;
    api: Octokit;
};

export interface Member extends UserBase {
    repository_name?: string;
}
export interface Collaborator extends CollaboratorBase {
    has_restrictions?: boolean;

    repository_name?: string;
}
export interface User extends UserBase {}
export interface Repository extends RepositoryBase {
    protected_branch?: BranchProtection;
    members?: Member[];

    collaborators?: Collaborator[];
}
@domoritz
Copy link
Member

Thanks for the report. Can you provide a minimal reproducible example that demonstrates the issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants