* Annotations, which is how Spring and its relatives register. * * Two annotations are declined, and both for the same reason: what they carry * is not a route. * * A mapping that names no verb is a class-level prefix. `@RequestMapping(path = * "/articles")` above a controller is the first hal
(source: string)
| 171 | * for exactly the languages where they appear, so declining them loses nothing. |
| 172 | */ |
| 173 | function readAnnotationRoutes(source: string): SourceRoute[] { |
| 174 | const routes: SourceRoute[] = []; |
| 175 | for (const match of source.matchAll(ANNOTATION_PATTERN)) { |
| 176 | const args = match[2] ?? ''; |
| 177 | const path = ANNOTATION_PATH_PATTERN.exec(args)?.[1]; |
| 178 | const verb = match[1] === 'Request' |
| 179 | ? ANNOTATION_METHOD_PATTERN.exec(args)?.[1] |
| 180 | : match[1].toUpperCase(); |
| 181 | if (path === undefined || !path.startsWith('/') || verb === undefined) { |
| 182 | continue; |
| 183 | } |
| 184 | routes.push({ method: verb, path, line: lineAt(source, match.index ?? 0) }); |
| 185 | } |
| 186 | return routes; |
| 187 | } |
| 188 | |
| 189 | /** One registration reported once, even when two patterns both matched it. */ |
| 190 | function dedupe(routes: SourceRoute[]): SourceRoute[] { |
no test coverage detected