-
Notifications
You must be signed in to change notification settings - Fork 59
Standalone swagger.json generation
Rudolf M. Schreier edited this page Jul 19, 2017
·
1 revision
If you would prefer not to make your Swagger definitions available as a Nancy route, you can also generate the swagger.json at server startup time:
Generating a string holding the contents of your swagger.json is as easy as extending your Nancy bootstrapper:
public class ExampleBootstrapper : DefaultNancyBootstrapper
{
private bool hasRun = false;
protected override void ConfigureRequestContainer(TinyIoCContainer container, NancyContext context)
{
base.ConfigureRequestContainer(container, context);
if (!hasRun)
{
var provider = container.Resolve<ISwaggerMetadataProvider>();
var swaggerJson = provider.GetSwaggerJson(context);
File.WriteAllText("swagger.json", swaggerJson.ToJson());
hasRun = true;
}
}
}