feat: code-first defaults initialization - #192
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces support for "code-first" (contract-based) configuration schema derivation and validation for .NET projects. It adds new infrastructure for building, running, and extracting schemas from host projects, and integrates this workflow into the validation and scaffolding pipelines. The changes ensure that projects using option contracts (instead of component-based schemas) can benefit from the same tooling as traditional projects, including schema-based defaults and IDE integration.
The most important changes are:
Code-first schema derivation and validation:
DotnetOptionsRunnerandDotnetOptionsSchemaComposerclasses to build the host project, invoke the validation runner, and extract the JSON schema from option contracts. This enables dynamic schema generation for code-first projects. [1] [2]DotnetOptionsValidatorto use the new runner and schema composer infrastructure, removing redundant build and runner logic from the validator.Pipeline and middleware integration:
RestoreDotnetSchemaMiddlewarein the DI container and pipeline, ensuring that schema scaffolding and validation for code-first projects use the derived schema. [1] [2]RestoreProjectMiddlewareto detect code-first projects and compose/store their schemas using the new infrastructure, bypassing the component-based schema logic when appropriate.Schema export enhancements:
SchemaExportto surface property initializers as schema defaults, allowing scaffolding tools to generate configuration files with real default values. This includes caching type instances and extracting default values only when they differ from CLR defaults. [1] [2] [3]Validation runner improvements:
Dependency and usings updates:
usingstatements for new types and features introduced in the code-first validation workflow. [1] [2]These changes collectively enable robust support for contract-based configuration in .NET projects, aligning the developer experience for both code-first and component-based approaches.