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

refactor(http-client-csharp): dump deprecated description properties #5154

Open
wants to merge 23 commits into
base: main
Choose a base branch
from

Conversation

archerzz
Copy link
Member

  • emitter: replace all description properties of input types with summary and doc
  • generator:
    • update json converters for the emitter schema change
    • only expose Summary and Doc properties if they are used by other classes
  • update test cases accordingly

part of #4771

- emitter: replace all `description` properties of input types with `summary` and `doc`
- generator:
  - update json converters for the emitter schema change
  - only expose `Summary` and `Doc` properties if they are used by other classes
- update test cases accordingly

part of microsoft#4771
@microsoft-github-policy-service microsoft-github-policy-service bot added the emitter:client:csharp Issue for the C# client emitter: @typespec/http-client-csharp label Nov 20, 2024
@archerzz archerzz changed the title refactor(http-client-csharp): remove filter-out-core-models option refactor(http-client-csharp): dump deprecated description properties Nov 20, 2024
@azure-sdk
Copy link
Collaborator

azure-sdk commented Nov 20, 2024

API change check

APIView has identified API level changes in this PR and created following API reviews.

Microsoft.Generator.CSharp.Input
Microsoft.Generator.CSharp

Comment on lines 17 to 21
private static readonly InputClient _animalClient = new("animal", "", "AnimalClient description", [], [], TestClientName);
private static readonly InputClient _dogClient = new("dog", "", "DogClient description", [], [], _animalClient.Name);
private static readonly InputClient _catClient = new("cat", "", "CatClient description", [], [], _animalClient.Name);
private static readonly InputClient _hawkClient = new("hawkClient", "", "HawkClient description", [], [], _animalClient.Name);
private static readonly InputClient _huskyClient = new("husky", "", "HuskyClient description", [], [], _dogClient.Name);
Copy link
Member

Choose a reason for hiding this comment

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

i think we should do string.Empty instead of "".
Also should this be null?

Copy link
Member

@ArcturusZhang ArcturusZhang Nov 21, 2024

Choose a reason for hiding this comment

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

I think it is never required to have summary or doc there these two properties should be nullable.
And there should be difference between when we have:

model Foo {}

and

@doc("")
model Foo {}

Copy link
Member Author

Choose a reason for hiding this comment

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

i think we should do string.Empty instead of "". Also should this be null?

It cannot be null, because nullable check is enabled.
image

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it is never required to have summary or doc there these two properties should be nullable. And there should be difference between when we have:

model Foo {}

and

@doc("")
model Foo {}

Zero values are the same here. You don't want to generate an empty doc anyway. Also, we're not consistent in our code base. Some defines string? and others define string. I just follow what the current codes were written.

Copy link
Member

@ArcturusZhang ArcturusZhang Nov 21, 2024

Choose a reason for hiding this comment

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

This comment follows this one: #5154 (comment)
For example an input enum type is not required to have a doc or summary or description, therefore our definition here is wrong in the first place.
We define this in this way, because previously these are defined for azure purpose, and for azure libraries, types, properties are not allowed without documentation. But in unbranded libraries, there is no such rules.

Azure part should change accordingly if we change it here - assign default value when an output type is constructed.

Copy link
Member Author

Choose a reason for hiding this comment

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

changed all Summary and Doc as string?

: base(name)
{
CrossLanguageDefinitionId = crossLanguageDefinitionId;
Accessibility = accessibility;
Deprecated = deprecated;
Description = description;
Description = string.IsNullOrEmpty(summary) ? (doc ?? string.Empty) : summary;
Copy link
Member

Choose a reason for hiding this comment

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

I think we should change this property to two new properties Summary and Doc
The classes in input types should just be the C# version of those typescript interfaces.

Copy link
Member Author

Choose a reason for hiding this comment

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

I see two different strategies regarding the input types between http-client-csharp and autorest.csharp:

  1. In http-client-csharp, we declare them as class. So, I keep the minimal interface here.
  2. In autorest.csharp, we declare them as record. So, I keep the interface like the original data schema as much as possible.

Copy link
Member

Choose a reason for hiding this comment

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

record is a class, there is no differences.
Making this change might take quite a few efforts, this I admit.
But we should not be avoiding them - I have done multiple of those when consolidating the models part.

Copy link
Member Author

Choose a reason for hiding this comment

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

removed all Description properties, replace with codes in the output model

@archerzz
Copy link
Member Author

Changes since last review:

  • Change all input types to make Summary and Doc properties as string?
  • Update type converters to not set default value during de-serialization. Set them when generating output models.
  • Some minor fixes and refactoring

@archerzz archerzz marked this pull request as ready for review November 26, 2024 09:44
@@ -424,7 +425,7 @@ private ScmMethodProvider BuildProtocolMethod(MethodProvider createRequestMethod

var methodSignature = new MethodSignature(
isAsync ? _cleanOperationName + "Async" : _cleanOperationName,
FormattableStringHelpers.FromString(Operation.Description),
DocHelpers.GetFormattableDescription(Operation.Summary, Operation.Doc) ?? FormattableStringHelpers.FromString(Operation.Name),
Copy link
Contributor

Choose a reason for hiding this comment

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

Description of MethodSignature is nullable. Why do we mock the operation.Name as its description here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Description of MethodSignature is nullable. Why do we mock the operation.Name as its description here?

It's because previously we use Operation.Name if Description is not available:

operation.Description = description ?? name; // default to name to avoid a case that we do not have description (and leads to no xml doc at all)

After discussion with Dapeng, we thought we should do less in the input type converters. So, I moved the logic in TypeSepcInputOperationConverter to the output model here.

We have similar changes elsewhere in this PR as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
emitter:client:csharp Issue for the C# client emitter: @typespec/http-client-csharp
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants