Fix extraneous lines in webapi .http file using source modifiers#65318
Fix extraneous lines in webapi .http file using source modifiers#65318mikekistler merged 7 commits intomainfrom
Conversation
Co-authored-by: mikekistler <85643503+mikekistler@users.noreply.github.com>
|
@copilot Is there no way to include this content conditionally? |
Co-authored-by: mikekistler <85643503+mikekistler@users.noreply.github.com>
Co-authored-by: mikekistler <85643503+mikekistler@users.noreply.github.com>
Yes! I've implemented conditional inclusion using With this approach:
|
|
@copilot Can you add a test that verifies the behavior both with and without --no-openapi |
Co-authored-by: mikekistler <85643503+mikekistler@users.noreply.github.com>
Added two tests in commit f9cd978:
Both tests verify that no template directives ( |
|
@copilot This looks good. Please move this PR as ready for review and tag the appropriate folks to review. |
I don't have the ability to change the PR status or tag reviewers directly. The PR is complete with:
You'll need to mark the PR as ready for review and tag the appropriate reviewers through the GitHub UI. |
There was a problem hiding this comment.
Pull request overview
Fixes conditional template directives (#if (EnableOpenAPI) / #endif) being emitted as literal text in generated webapi .http files by enabling conditional processing for **/*.http files in the WebApi C# template and adding regression tests.
Changes:
- Configure the template engine to process conditional directives in
.httpfiles viaSpecialCustomOperationsin the WebApi-CSharptemplate.json. - Add tests verifying the generated
.httpfile includes the OpenAPI request by default and excludes it when--no-openapiis used. - Ensure no template directives remain in the generated
.httpfile in either configuration.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/ProjectTemplates/test/Templates.Mvc.Tests/WebApiTemplateTest.cs | Adds regression coverage for .http generation with OpenAPI enabled/disabled. |
| src/ProjectTemplates/Web.ProjectTemplates/content/WebApi-CSharp/.template.config/template.json | Enables conditional directive processing for **/*.http files so #if/#endif blocks are evaluated rather than emitted. |
| "SpecialCustomOperations": { | ||
| "**/*.http": { | ||
| "operations": [ | ||
| { | ||
| "type": "conditional", | ||
| "configuration": { | ||
| "if": ["#if"], | ||
| "else": ["#else"], | ||
| "elseif": ["#elseif", "#elif"], | ||
| "endif": ["#endif"], | ||
| "trim": true, | ||
| "wholeLine": true | ||
| } | ||
| } | ||
| ] | ||
| } | ||
| }, |
There was a problem hiding this comment.
Optional: this file’s top-level keys are otherwise lower camelCase (e.g., primaryOutputs, defaultName). SpecialCustomOperations introduces a different casing style; if the template schema/engine supports specialCustomOperations, consider using that casing for consistency and better schema/tooling alignment.
Co-authored-by: mikekistler <85643503+mikekistler@users.noreply.github.com>
Fix extraneous lines in webapi .http file
Description
The webapi template's
.httpfile contained#if (EnableOpenAPI)and#endifdirectives that were not being processed by the template engine, resulting in these lines appearing verbatim in generated projects.Root Cause: The template engine only processes
#if/#endifconditionals in file types it recognizes (e.g..cs). For.httpfiles, these directives pass through as literal text.Solution: Use source modifiers (conditional exclude/rename) in
template.jsonto select between two.httpfile variants — the same pattern already used in this template forProgram.cs/Program.Main.cs/Program.MinimalAPIs.*.cs.Changes:
Company.WebApplication1.http— Removed#if/#endifdirectives; contains the OpenAPI endpoint (used by default)Company.WebApplication1.NoOpenAPI.http— New file without the OpenAPI endpoint, renamed toCompany.WebApplication1.httpwhen--no-openapiis usedtemplate.json— Added source modifiers for conditional.httpfile selection; removed unusedSpecialCustomOperationssectionWebApiTemplateTest.cs— Added two tests verifying.httpfile content with and without--no-openapiFixes #65317