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

Implement resource detection and generate ReourceData #47730

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

Conversation

live1206
Copy link
Member

@live1206 live1206 commented Jan 7, 2025

Resolves #47743

@github-actions github-actions bot added Client This issue points to a problem in the data-plane of the library. CodeGen Issues that relate to code generation labels Jan 7, 2025
@live1206 live1206 changed the title Implement Mgmt resource Implement resource detection and generate ReourceData Jan 9, 2025
@live1206 live1206 marked this pull request as ready for review January 9, 2025 08:14
{
if (inputType is InputModelType inputModel
&& typeProvider is ModelProvider modelProvider
&& AzureClientPlugin.Instance.OutputLibrary.IsResource(StringHelpers.ToCleanName(inputType.Name))
Copy link
Member

Choose a reason for hiding this comment

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

Can we not use the modelProvider.Name?

Copy link
Member Author

@live1206 live1206 Jan 10, 2025

Choose a reason for hiding this comment

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

updated to use inputModel.Name directly

// get the result from cache
if (_resourceDataSchemaCache.TryGetValue(set.RequestPath, out var resourceSchemaTuple))
{
resourceSpecName = resourceSchemaTuple is null ? null : StringHelpers.ToCleanName(resourceSchemaTuple?.Name!);
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need to call ToCleanName 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.

Yeah, given we always have InputModel while checking for resource, we can just keep the original InputModel name.

Copy link
Member Author

Choose a reason for hiding this comment

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

Then, the only usage of ToCleanName is in the test, which I can live with using const string instead of it.

}
}

return idPropertyFound && typePropertyFound && namePropertyFound;
Copy link
Member

Choose a reason for hiding this comment

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

Should we add a check for this after the switch within the foreach loop to short-circuit?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sounds good.
Added the check before the switch, if the switch case is hit it will skip the rest of the loop anyway.

{
}

protected override string BuildName() => $"{base.BuildName()}Data";
Copy link
Member

Choose a reason for hiding this comment

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

Could this be handled with a visitor instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

same reason as #47730 (comment)


protected override string BuildName() => $"{base.BuildName()}Data";

protected override string BuildRelativeFilePath() => Path.Combine("src", "Generated", $"{Name}.Serialization.cs");
Copy link
Member

Choose a reason for hiding this comment

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

Does this need to be overriden?

Copy link
Member Author

Choose a reason for hiding this comment

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

do you suggest using visitor to change the file location?

if (inputType is InputModelType inputModel
&& typeProvider is ModelProvider modelProvider
&& AzureClientPlugin.Instance.OutputLibrary.IsResource(StringHelpers.ToCleanName(inputType.Name))
&& inputModel.Usage.HasFlag(InputModelTypeUsage.Json))
Copy link
Member

Choose a reason for hiding this comment

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

Wondering if this logic can be moved into a visitor.

Copy link
Member Author

@live1206 live1206 Jan 10, 2025

Choose a reason for hiding this comment

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

Given the visitor is applied after all the type providers actually created.
If we want to change an existing type provider, we need to visit all the references they have been used, which is cumbersome.

Copy link
Member Author

Choose a reason for hiding this comment

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

What I wrote above is concern about ModelProvider -> ResourceDataProvider.
For serialization, they might be fine since they are not referenced in other providers.
But then, do we want to treat them differently?
And should the sub-plugin have the ability to handle the serialization differently?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Client This issue points to a problem in the data-plane of the library. CodeGen Issues that relate to code generation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement resource detection
2 participants