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

feat: add Source FileName for DefinitionType, used by TopRefNodeParser and ExposeNodeParser. #1056

Draft
wants to merge 2 commits into
base: next
Choose a base branch
from

Conversation

charlzyx
Copy link

@charlzyx charlzyx commented Dec 7, 2021

For this idea #1018

This is same PR with #1019 , but cause by my Incorrect operation, i have to resbumit this one. #1019 discuss at the bottom.

And here is custome DefinitionTypeFormatter example

import {
  BaseType,
  Definition,
  DefinitionType,
  SubTypeFormatter,
  TypeFormatter,
  uniqueArray,
} from 'ts-json-schema-generator';

export class DefinitionTypeFormatter implements SubTypeFormatter {
  public constructor(
    private childTypeFormatter: TypeFormatter,
    private encodeRefs: boolean,
  ) {}

  public supportsType(type: DefinitionType): boolean {
    return type instanceof DefinitionType;
  }
  public getDefinition(type: DefinitionType): Definition {
    // so that you can see the name here.
    console.log(type.sourceFileName);
    return {
      $ref: `#/definitions/${this.encodeRefs ? encodeURIComponent(type) : type}`,
    };
  }

}

github com_vega_ts-json-schema-generator_pull_1019_files

@domoritz
Copy link
Member

domoritz commented Dec 7, 2021

Why a new pull request? You can push to the branch you made your other pull request from and it'll update.

@domoritz
Copy link
Member

domoritz commented Dec 7, 2021

This is the same pull request now. Please dort force push next time since it makes it hard to review for me.

@domoritz domoritz closed this Dec 7, 2021
@domoritz domoritz reopened this Dec 8, 2021
* and ExposeNodeParser. So that, You can override DefinitionFormatter
* to custome your self DefinitionType name by fileName.
*/
private sourceFileName?: string
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't feel clean. Can we make sourceFileName an argument to the DefinitionType constructor?

Originally posted by @domoritz in #1019 (comment)

@domoritz
Copy link
Member

domoritz commented Dec 9, 2021

making as draft since there are open comments

@domoritz domoritz marked this pull request as draft December 9, 2021 14:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants