Skip to content

[Source Gen] Create JSON directly instead of using anonymous type #1191

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

Merged
merged 7 commits into from
Dec 1, 2022

Conversation

satvu
Copy link
Member

@satvu satvu commented Nov 21, 2022

Issue describing the changes in this PR

resolves #1188

Pull request checklist

  • My changes do not require documentation changes
    • Otherwise: Documentation issue linked to PR
  • My changes should not be added to the release notes for the next release
    • Otherwise: I've added my notes to release_notes.md
  • My changes do not need to be backported to a previous version
    • Otherwise: Backport tracked by issue/PR #issue_or_pr
  • I have added all required tests (Unit tests, E2E tests)

Additional information

Additional PR information

Sorry, something went wrong.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
@satvu satvu changed the title wip, httptrigger tested [Source Gen] Create JSON directly instead of using anonymous type Nov 21, 2022
@satvu
Copy link
Member Author

satvu commented Nov 21, 2022

Pushing out initial prototype quickly for cold-start testing, but to do:

  • Fix generation test cases
  • Clean up casing logic. I think we can drop uppercasing the first letter since we are no longer using an anonymous type and just going straight to a JSON string.
  • Only E2E tested one HTTP Trigger so need to make sure others are working as expected.

@satvu satvu requested review from kshyju and jviau and removed request for kshyju November 21, 2022 21:00
@@ -21,6 +21,6 @@ internal class GeneratorFunctionMetadata

public IDictionary<string, object> Properties { get; set; } = new Dictionary<string, object>();

public IList<IDictionary<string, string>> RawBindings { get; set; } = new List<IDictionary<string, string>>(); // List of <propertyName, propertyValue> bindings.
public IList<IDictionary<string, object>> RawBindings { get; set; } = new List<IDictionary<string, object>>(); // List of <propertyName, propertyValue> bindings.
Copy link
Member Author

Choose a reason for hiding this comment

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

string -> object change is due to switching to JSON serialization. Previously, arrays were stored as a string that would be written right to the generated file, but now we need the actual array object.

</PropertyGroup>

<Import Project="..\..\build\Common.props" />

<ItemGroup>
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="5.0.0" PrivateAssets="all" GeneratePathProperty="true" />
Copy link
Member Author

Choose a reason for hiding this comment

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

This package and the one below it are dependencies of System.Text.Json - we have to include these explicitly.

@satvu satvu marked this pull request as ready for review November 28, 2022 18:18
@satvu satvu requested review from fabiocav and jviau November 28, 2022 18:20
Copy link
Contributor

@jviau jviau left a comment

Choose a reason for hiding this comment

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

This is great to see! Much simpler in the end I think.

<ItemGroup>
<!-- Package the generator in the analyzer directory of the nuget package -->
<None Include="$(OutputPath)\$(AssemblyName).dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />

<None Include="$(PKGSystem_Text_Json)\lib\netstandard2.0\*.dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
Copy link
Contributor

Choose a reason for hiding this comment

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

I can see you are using this package, but where/why are the other two needed? Are they dependencies of STJ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes they're dependencies of STJ and they won't get loaded with STJ ... had to add each package associated with a "couldn't find file or assembly" until the generator built successfully.

@satvu
Copy link
Member Author

satvu commented Dec 1, 2022

/check-enforcer evaluate

@satvu satvu merged commit 0a57480 into main Dec 1, 2022
@satvu satvu deleted the satvu/remove-anonymous-serialization branch December 1, 2022 19:53
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.

[Source Gen] Refactor to create json strings directly instead of using anonymous type
4 participants