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.

OpenApiResponseWithBody containing property named `parameters` throws exception

See original GitHub issue

Describe the issue Using a class that contains a property named parameters in the OpenApiResponseWithBody attribute crashes the ../swagger.json endpoint.

Using version 1.3.0.

To Reproduce Decorate a function with this:

[OpenApiOperation]
[OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, contentType: "application/json", bodyType: typeof(Output))]

The class Output looks like this

public class Output
{
    public string parameters { get; set; }
}

Returns this when calling /swagger.json endpoint:

Cannot cast Newtonsoft.Json.Linq.JObject to Newtonsoft.Json.Linq.JToken.

   at Newtonsoft.Json.Linq.Extensions.Convert[T,U](T token)
   at Newtonsoft.Json.Linq.Extensions.Convert[T,U](IEnumerable`1 source)+MoveNext()
   at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.MoveNext()
   at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.MoveNext()
   at System.Linq.Enumerable.WhereEnumerableIterator`1.ToList()
   at Microsoft.Azure.WebJobs.Extensions.OpenApi.Document.Render(OpenApiSpecVersion version, OpenApiFormat format)
   at Microsoft.Azure.WebJobs.Extensions.OpenApi.Document.<>c__DisplayClass18_0.<RenderAsync>b__0()
   at System.Threading.Tasks.Task`1.InnerInvoke()
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
--- End of stack trace from previous location ---
   at Microsoft.Azure.WebJobs.Extensions.OpenApi.Document.RenderAsync(OpenApiSpecVersion version, OpenApiFormat format)
   at Microsoft.Azure.WebJobs.Extensions.OpenApi.OpenApiTriggerFunctionProvider.RenderSwaggerDocument(HttpRequest req, String extension, ExecutionContext ctx, ILogger log)

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
singingknightcommented, Jan 5, 2023

Got the same issue using version 1.5.0.

Downgrading to version 1.1.0 solved the issue which seems to have been introduced in 1.2.0

0reactions
jcezardasilvacommented, Mar 20, 2023

I have a similar issue. I’m trying to use a multipart/form-data with:

[OpenApiRequestBody(contentType: "multipart/form-data", bodyType: typeof(MultiPartFormData))]

the MultiPartFormData is like:

public class MultiPartFormData
    {
        public byte[] File { get; set; }
    }

Using [Microsoft.Azure.WebJobs.Extensions.OpenApi] version 1.1.0 and .Net6 the parameter is not shown in the swagger. Upgrading [Microsoft.Azure.WebJobs.Extensions.OpenApi] to 1.2.0 or earlier then throw the exception:

Cannot cast Newtonsoft.Json.Linq.JObject to Newtonsoft.Json.Linq.JToken.
Read more comments on GitHub >

github_iconTop Results From Across the Web

Azure Function - ServiceBusTrigger - Exception Binding ...
Exception while executing function: <functionName>. Microsoft.Azure.WebJobs.Host: Exception binding parameter 'message'. System.Private.CoreLib: ...
Read more >
How to troubleshoot Azure Function HTTP Trigger 404 Error
If the name parameter is missing, this function will return a 404 error with the message "The resource you are looking for has...
Read more >
Listener for Azure function was unable to start error while ...
I have one Azure function app and I am trying to run that locally but getting the below error. I have the storage...
Read more >
Describing Responses
An API can respond with various media types. JSON is the most common format for data exchange, but not the only one possible....
Read more >
Azure Functions v3 migration guide from .NET Core 3.1 to ...
This guide will help you migrate from a project with Azure Functions v3 on .NET Core 3.1 to the new Azure Functions Isolated...
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