Using the Swagger CLI tool I can generate the swagger file with this command:
swagger tofile --output swagger.json MyApi.dll v1
For this command to work it is necessary that the API DLL contains the Swagger packages and configured like this:
builder.Services.AddSwaggerGen();
Is it possible to generate the Swagger file from an API DLL that doesn't contains the Swagger packages and configuration using Swagger CLI or any other tool?
The main reason for this is that I have a lot of APIs and I don't want to modify the APIs adding Swagger packages and configurations just to generate the swagger.json file. Also, I would like to do this during automated build, so I decided on the command line approach.
I'm not aware of any tools that can generate OpenAPI definitions by DLL inspection. All known OpenAPI-from-code generators (such as Swashbuckle or Swagger-Net) are libraries that need to be included in the app.
Without modifying the code, your best option is probably to record traffic to your API and generate an OpenAPI file from that. There are a few tools that can do that. Check out the examples of using Optic and Akita to get an idea of how this works.
Or if you have an existing Postman collection for your API, there are Postman-to-OpenAPI converters such as APIMatic Transformer (note: requires an account).