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.

OpenAPI NonBodyParameter replacement?

See original GitHub issue

I upgraded to Swashbuckle v5, and was trying to update a project that uses the Microsoft.AspNetCore.Mvc.Versioning. It uses an operation filter like such:

 public void Apply(Operation operation, OperationFilterContext context)
        {
            var apiDescription = context.ApiDescription;

            operation.Deprecated = apiDescription.IsDeprecated();

            if (operation.Parameters == null)
            {
                return;
            }

            // REF: https://github.com/domaindrivendev/Swashbuckle.AspNetCore/issues/412
            // REF: https://github.com/domaindrivendev/Swashbuckle.AspNetCore/pull/413
            foreach (var parameter in operation.Parameters.OfType<NonBodyParameter>())
            {
                var description = apiDescription.ParameterDescriptions.First(p => p.Name == parameter.Name);

                if (parameter.Description == null)
                {
                    parameter.Description = description.ModelMetadata?.Description;
                }

                if (parameter.Default == null)
                {
                    parameter.Default = description.DefaultValue;
                }

                parameter.Required |= description.IsRequired;
            }
        }

With SwaggerDocument no longer used in v5, I couldn’t find a NonBodyParameter equivalent in OpenAPI model.

Can anyone tell me the appropriate class to use for that in OpenAPI?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:7
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

7reactions
Cloudmersivecommented, Aug 7, 2020

So not cool that you decided to break everything

6reactions
matteobrunicommented, May 14, 2019

Yup, it did work w/o the OfType. However, the OpenAPI doesn’t allow you to set a default value. I think the MS API Version maintainer will have to setup the API versions as a OpenAPI options list value, and then pick the default. I punted on this for now, and just went with version-in-url pattern.

How did you change your code with RequestBody?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is there <NonBodyParameter> equivalent
I updated Swashbuckle v5 and operation.Parameters() is not valid anymore.Is there any replacement? { var apiDescription = context.ApiDescription ...
Read more >
Add Custom Parameters In Swagger Using ASP.NET Core ...
This article showed you a sample of how to add custom request parameters in Swagger using ASP.NET Core 3.1 and Swashbuckle.AspNetCore 5.0.0.
Read more >
[Solved]-Web Api How to add a Header parameter for all API ...
Add(new NonBodyParameter { Name = "X-User-Token", In = "header", ... 5) I have to change some : using System.Collections.Generic; using Microsoft.OpenApi.
Read more >
Source code for drf_yasg.openapi - drf-yasg
Source code for drf_yasg.openapi ... raise_from is EXTREMELY slow, replaced with plain raise raise AttributeError("object of class " + type(self).
Read more >
[ASP.Net Core] Swagger - Show non-declared API ...
Sometimes we don't declare the API's parameter(s) on API controller's Action, but we still want them to be shown on Swagger (OpenAPI ......
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