Getting route data from a WebAPI without Swagger
The way I'm currently generating TS clients, is I use NSwag to get the OpenAPI spec, then I have a tool written in JS that parses that json and generates TS clients. I was thinking of eliminating some steps from that, though.
The way I see it, I should be able to make a console app that references my WebAPI project, and somehow get the route data from there. All nicely typed and all. Bypassing Swagger completely.
Can't figure out how, though
9 Replies
Could look through NSwag's source to see how it generates the OpenAPI spec?
Huh, good idea, didn't think of that
Yeah that's not happening, NSWag is spread actoss like 70 different projects, I ain't tracking down what does the route infor gathering lol
Maybe Swashbuckle is simpler...
oof
yeah i looked at swashbuckle and it seemed simpler
If you don't use minimal APIs you could maybe use Roslyn and scan the assembly for all
[Route]
attributes.Or for
[Http...]
ones, another good idea, thanksYou would probably need to look for the Controller and then work your way down and check each method.
But Roslyn would also give you direct access to all the parameters and other attributes for return typing.
you mean like rest should do, responses that give routings (or rather fragments) in headers? so that you can explore endpoints
No, not quite
What I want is, for example
mmh i remember asp net has an api to list registered controllers, although i never actually used it
maybe it's
IActionDescriptorCollectionProvider
?
maybe you can just recover all the controllers by d.i. and exploring them with reflection?
im curious now, i will try it tomorrow