Skip to content

OpenAPI Source Generation for MVC#46

Merged
feO2x merged 3 commits into
mainfrom
45-openapi-source-generation-mvc
May 22, 2026
Merged

OpenAPI Source Generation for MVC#46
feO2x merged 3 commits into
mainfrom
45-openapi-source-generation-mvc

Conversation

@feO2x
Copy link
Copy Markdown
Owner

@feO2x feO2x commented May 22, 2026

Closed #45

This pull request adds support for using source-generated validation OpenAPI contracts with MVC actions, not just Minimal APIs. It introduces a new attribute (ProducesPortableValidationProblemForAttribute<TValidator>) that allows MVC controllers to automatically apply generated validation metadata, ensuring consistent OpenAPI documentation across both endpoint styles. The changes also update documentation and tests to reflect this new capability.

MVC OpenAPI Source Generation Support:

  • Added ProducesPortableValidationProblemForAttribute<TValidator> to Light.PortableResults.Validation.OpenApi, enabling MVC actions to consume generated validation OpenAPI contracts without manual duplication. The attribute applies the generated contract via the existing builder API and supports property overrides for status code, content type, format, metadata type, and unknown error codes. [1] [2]
  • Changed the constructor of PortableValidationProblemOpenApiBuilder from internal to public to allow use from the new MVC attribute.

Documentation Updates:

  • Updated the README.md and package release notes to clarify that source generation now supports both Minimal APIs and MVC, and documented the new attribute usage and customization caveats. [1] [2] [3]
  • Added a new AI plan (ai-plans/0045-open-api-source-generation-mvc-support.md) detailing the rationale, acceptance criteria, and technical approach for MVC support.
  • Improved plan-writing guidance in AGENTS.md to emphasize concise, high-level technical details.

Testing:

  • Added comprehensive tests to ensure the new attribute correctly applies generated contracts, including schema, examples, and property overrides, and that MVC OpenAPI documents are generated as expected. [1] [2] [3] [4]

These changes ensure that source-generated validation OpenAPI contracts can be used seamlessly in both Minimal API and MVC scenarios, with consistent documentation and flexible customization.

feO2x added 3 commits May 22, 2026 13:02
Signed-off-by: Kenny Pflug <kenny.pflug@live.de>
Signed-off-by: Kenny Pflug <kenny.pflug@live.de>
Signed-off-by: Kenny Pflug <kenny.pflug@live.de>
@feO2x feO2x self-assigned this May 22, 2026
@feO2x feO2x added the enhancement New feature or request label May 22, 2026
@feO2x feO2x linked an issue May 22, 2026 that may be closed by this pull request
8 tasks
@feO2x feO2x requested a review from Copilot May 22, 2026 13:37
@github-actions
Copy link
Copy Markdown

Code Coverage

Package Line Rate Branch Rate Complexity Health
Light.PortableResults 96% 94% 2301
Light.PortableResults.AspNetCore.MinimalApis 93% 80% 24
Light.PortableResults.AspNetCore.Mvc 93% 80% 24
Light.PortableResults.AspNetCore.OpenApi 93% 73% 518
Light.PortableResults.AspNetCore.Shared 100% 100% 26
Light.PortableResults.Validation 96% 89% 1757
Light.PortableResults.Validation.OpenApi 97% 88% 104
Light.PortableResults.Validation.OpenApi.SourceGeneration 88% 83% 755
Summary 95% (9343 / 9867) 89% (3943 / 4446) 5509

Minimum allowed line rate is 60%

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request extends the validation OpenAPI source-generation workflow to MVC actions by introducing an MVC-friendly attribute adapter that applies a source-generated IPortableValidationOpenApiContract to the existing PortableResults OpenAPI metadata model.

Changes:

  • Added ProducesPortableValidationProblemForAttribute<TValidator> (MVC attribute) to apply generated validation OpenAPI contracts on controller actions.
  • Made PortableValidationProblemOpenApiBuilder’s constructor public (and null-guarded) so the new attribute can reuse the existing builder API.
  • Updated docs and tests to cover MVC OpenAPI document output (schemas, examples, and overrides).

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/Light.PortableResults.Validation.OpenApi.Tests/ValidationOpenApiDocumentTestUtilities.cs Adds MVC test app factory to generate OpenAPI documents from controller actions.
tests/Light.PortableResults.Validation.OpenApi.Tests/ValidationOpenApiAttributeTests.cs Adds unit coverage ensuring the MVC attribute applies a generated contract and supports overrides.
tests/Light.PortableResults.Validation.OpenApi.Tests/GeneratedValidationOpenApiIntegrationTests.cs Adds end-to-end OpenAPI integration test for MVC controller attribute behavior (schemas/examples/overrides).
src/Light.PortableResults.Validation.OpenApi/ProducesPortableValidationProblemForAttribute.cs Introduces the new MVC attribute that applies the generated IPortableValidationOpenApiContract via the builder.
src/Light.PortableResults.Validation.OpenApi/Light.PortableResults.Validation.OpenApi.csproj Updates package release notes to reflect MVC support in the source-generation workflow.
src/Light.PortableResults.AspNetCore.OpenApi/PortableValidationProblemOpenApiBuilder.cs Makes the builder constructor public and adds null guarding for external use.
README.md Documents source-generation usage for both Minimal APIs and MVC, including MVC customization caveats.
Light.PortableResults.slnx Adds the new AI plan file to the solution items.
ai-plans/AGENTS.md Updates guidance to keep technical details concise and focused.
ai-plans/0045-open-api-source-generation-mvc-support.md Adds the plan describing rationale/criteria/approach for MVC support.

@feO2x feO2x merged commit c1d842a into main May 22, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OpenAPI Source Generation MVC Support

2 participants