question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Export additional models

See original GitHub issue

I’m using NSwag in my ASP.NET Core project (app.UseOpenApi()).

Is it possible to add additional models, which are not used in any controller action, to the generated api descriptions?

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:14 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
FerdinandBrunauercommented, Sep 14, 2022

Here’s an example processor for those who would like to use one.

/// <summary>
///  Registers additional types that cannot be directly seen from Web API, like SignalR messages.
/// </summary>
public sealed class AddAdditionalTypeProcessor<T>: IDocumentProcessor where T : class
{
    public void Process(DocumentProcessorContext context)
    {
        context.SchemaResolver.AddSchema(typeof(T), isIntegerEnumeration: false, JsonSchema.FromType<T>());
    }
}

And usage:

services.AddSwaggerDocument(settings =>
{
    settings.DocumentProcessors.Add(new AddAdditionalTypeProcessor<MyTypeToExport>());
});

This example does have problems with nested types. Solution was to change the implementation to the following:

public sealed class AddAdditionalTypeProcessor<T> : IDocumentProcessor where T : class
{
    public void Process(DocumentProcessorContext context)
    {
        context.SchemaGenerator.Generate(typeof(T).ToContextualType(), context.SchemaResolver);
    }
}
4reactions
lahmacommented, Oct 26, 2022

Here’s an example processor for those who would like to use one.

/// <summary>
///  Registers additional types that cannot be directly seen from Web API, like SignalR messages.
/// </summary>
public sealed class AddAdditionalTypeProcessor<T>: IDocumentProcessor where T : class
{
    public void Process(DocumentProcessorContext context)
    {
        context.SchemaResolver.AddSchema(typeof(T), isIntegerEnumeration: false, JsonSchema.FromType<T>());
    }
}

And usage:

services.AddSwaggerDocument(settings =>
{
    settings.DocumentProcessors.Add(new AddAdditionalTypeProcessor<MyTypeToExport>());
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

Export your models
Learn how to export your creations so you can use them in other applications. Export is an important part of the Modeler pipeline....
Read more >
How to: Export and Import a Model | Microsoft Learn
You can use either Windows PowerShell cmdlets or the AXUtil command-line utility to export models to model files and import model files into...
Read more >
Export a model—ArcGIS CityEngine Resources | Documentation
The model exporter is independent of the generated models in the current scene and can export large scenes. This means that you do...
Read more >
Export models | BigQuery
Find and click the model that you're exporting. On the right side of the window, click Export Model. Export model. In the Export...
Read more >
Export 🤗 Transformers Models
In this guide, we'll show you how to export Transformers models in two widely ... model to ONNX, you'll first need to install...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found