Skip to content

[Analyzer] Route syntax analyzer #44315

@JamesNK

Description

@JamesNK

Background and Motivation

A route is a string that has a standard syntax. An invalid route string errors at runtime when parsed. This typically happens at app startup. We want to tighten the dev loop and tell people their route is invalid in the IDE.

Proposed API

An analyzer that inspects route strings for invalid content.

A route string is indicated by [StringSyntax("Route")] on the property, method argument, or constructor argument.

Usage Examples

public IEndpointConventionBuilder MapGet(
    IEndpointRouteBuilder builder,
    [StringSyntax("Route")] string pattern,
    Delegate delegate)
{
    // ...
}

endpoints.MapGet("{**slug?}", () => "hello world"); // <- invalid because parameter can't be catchall and optional
endpoints.MapGet("//login", () => "hello world"); // <- invalid because can't have consecutive forward slashes
endpoints.MapGet("{id}/{id}", () => "hello world"); // <- invalid because can't have duplicate parameter names

Alternative Designs

Risks

Metadata

Metadata

Assignees

No one assigned

    Labels

    api-approvedAPI was approved in API review, it can be implementedapi-suggestionEarly API idea and discussion, it is NOT ready for implementation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions