This example keeps generated models and methods in separate projects so that
System.Text.Json can generate metadata for all model types:
SourceGeneratorNativeAot.Modelsgenerates the API models and theJsonSerializerContextTypesaggregation type.SourceGeneratorNativeAot.Clientreferences the models project, definesSourceGenerationContext, and generates the client methods and constructors.SourceGeneratorNativeAot.Testsverifies that the generated client context applies AutoSDK's generated converters to top-leveloneOf,anyOf, and enum payloads.
The client generator composes SourceGenerationContext.Default with the
converters emitted by AutoSDK. Consumers do not need to duplicate the generated
converter list in JsonSourceGenerationOptions.
The source generator reports informational diagnostic OAG003 with the
generated converters composed into each wrapper context. See the
root diagnostic guidance
for project-level suppression and .editorconfig severity configuration.
The models and client projects enable trimming and NativeAOT analyzers. All projects are
included in AutoSDK.slnx, so the repository build continuously verifies this
example:
dotnet test examples/SourceGeneratorNativeAot/SourceGeneratorNativeAot.Tests/SourceGeneratorNativeAot.Tests.csprojWhen copying this pattern outside the AutoSDK repository, replace the local
analyzer project references and imports with the AutoSDK.SourceGenerators
package described in the root README.