OpenAPI Spec at Build Time?
# package-development
w
Has anyone managed to build an OpenAPI/Swagger JSON document at C# Build time as opposed to having SwashBuckle serve it dynamically from the server?
I am just trying to improve the flow a little so that the openapi doc is saved to disk and can be versioned controlled in git and also so that the TypeScript generation does not depend on the website being running to generate a new TS HTTP API client
I have seen this https://khalidabuhakmeh.com/generate-aspnet-core-openapi-spec-at-build-time I can't get it to work with my RCL project though :S
m
Are you planing to point hey-api/openapi-ts to this static file to build the typescript-stuff or are you looking to use any other tool? I used to have a setup where a console app would build my ts-files (for AngularJS), but I must say that I',m not that bortherd by the "official" setup with having to run "npm generate:api" after a change has been made.
w
Yeh it’s fine for me
I was just trying to help simplify the dotnet new template
It’s another thing you need to know about
So if MSbuild can create the yank/json
Then the node is scripts for build/dev could regenerate the TS api everytime
So it’s one thing less to know/worry about was my thinking for new people.
I can get it to work but just not in an RCL project as it needs a C# Apphost/entrypoint and this RCL & client side dotnet new template won’t be able to do. So for now parked this idea unlesss anyone has smart thoughts.
d
Just stumbled on this which may be useful

https://youtu.be/8yI4gD1HruY?si=zVxiUBZyI4T7E84R

w
Swashbuckle & NSwag community packages is being replaced in .NET9 with their own stuff
3 Views