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.

Adding custom operations

See original GitHub issue

I’m trying to add Owin OAuth authorization server’s token endpoint to the swagger api docs, but Swashbuckle can only read operations from the IApiExplorer. Owin uses a custom middleware to create the OAuth token endpoint with app.UseOAuthAuthorizationServer(options) call, so it won’t appear on the IApiExplorer.

I need something like this:

swaggerConfig.operations.Add(new Operation() {
    operationId = "auth/token",
    consumes = new List<string>
    {
        "application/x-www-form-urlencoded"
    },
    parameters = new List<Parameter> {
        new Parameter
        {
            type = "string",
            name = "grant_type",
            required = true,
            @in = "formData"
        },
        new Parameter
        {
            type = "string",
            name = "username",
            required = false,
            @in = "formData"
        },
        new Parameter
        {
            type = "string",
            name = "password",
            required = false,
            @in = "formData"
        }
    }
});

How could I manually add custom operations to the docs?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:1
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

8reactions
henkoschcommented, May 16, 2015

Thank you!

I was able to add the custom operation like this:

class AuthTokenOperation : IDocumentFilter
{
    public void Apply(SwaggerDocument swaggerDoc, SchemaRegistry schemaRegistry, IApiExplorer apiExplorer)
    {
        swaggerDoc.paths.Add("/auth/token", new PathItem
        {
            post = new Operation
            {
                tags = new List<string> { "Auth" },
                consumes = new List<string>
                {
                    "application/x-www-form-urlencoded"
                },
                parameters = new List<Parameter> {
                    new Parameter
                    {
                        type = "string",
                        name = "grant_type",
                        required = true,
                        @in = "formData"
                    },
                    new Parameter
                    {
                        type = "string",
                        name = "username",
                        required = false,
                        @in = "formData"
                    },
                    new Parameter
                    {
                        type = "string",
                        name = "password",
                        required = false,
                        @in = "formData"
                    }
                }
            }
        });
    }
}

httpConfig.EnableSwagger(c =>
{
    c.DocumentFilter<AuthTokenOperation>();
});
0reactions
TermanEmilcommented, Oct 11, 2019

Hey Is it possible to make a custom operation with raw URL input? I need it to document some OData endpoints.

For example: /odata/People?$select=Id,Name&$expand=Passport($select=IDNP)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Custom operators | onnxruntime
Custom operators can be defined in a separate shared library (e.g., a .dll on Windows or a .so on Linux). A custom operator...
Read more >
Creating Custom Operations
You use this procedure to define custom operations in order to perform operations on instances or hosts based on these definitions.
Read more >
Adding custom operations with hook_entity_operation()
I'm trying to add a custom entity operation to taxonomy terms of a specific vocabulary. I've found documentation on using hook_entity_operation ...
Read more >
How to Create Custom Operations and Custom Hooks
In this post you will learn what custom operations and custom hooks are and what you can do with them. You will also...
Read more >
Operation Guide: How to Use Custom Operations
This custom operation allows you to add any/all applicable course permission tags to a user with a single action. Learn more about how...
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