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

[linter]discourage to use anonymous model and always give a model name #1727

Open
4 tasks done
MaryGao opened this issue Oct 23, 2024 · 0 comments
Open
4 tasks done
Labels
lib:tcgc Issues for @azure-tools/typespec-client-generator-core library

Comments

@MaryGao
Copy link
Member

MaryGao commented Oct 23, 2024

Clear and concise description of the problem

Close typespec one filed an issue in typespec-azure repo.

Offline discussed with @ArcturusZhang and we think anomymous model may not be a good practice and we should encourage to give a name for models especially for exposed public APIs.

Most of downstreaming language emitters may not have ability to handle inline expressions like typespec so they need to GUESS a name for anomymous models. This could introduce uncertainty if downstreaming name rule is different and for example the name rule introduced breakings between m4 and tcgc and one issue happened in common types is tracked here.

Even we could find a name rule and these names could be fragile and it would be changed with its context or code order if conflicting happened.

For example in TCGC we try to guess this name according to context, including parent model name + property name + model type. So the name could be changed once any of these factors changed. Also we may name some models during conflicting and any code order changes would impact the generated code.

model Ab {
  c: {
    foo: string;
  };
}

// vs
model A {
  b: {
    c: {
      foo: string;
    };
  };
}

Can we add a linter to discourage the anonymous model in typespec? Especially in azure could we avoid using anonymous model then?

Checklist

  • Follow our Code of Conduct
  • Check that this issue is about the Azure libraries for typespec. For feature request in the typespec language or core libraries file it in the TypeSpec repo
  • Read the docs.
  • Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lib:tcgc Issues for @azure-tools/typespec-client-generator-core library
Projects
None yet
Development

No branches or pull requests

2 participants