-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Swagger generation for JObject fails (due to IDictionary cast) #29
Comments
@JoschaMetze Thanks for the comment! Would you give me some example code snippet so that I can reproduce the error on my side, please? |
Hey, of course, minimal repro: [OpenApiOperation("FunctionWorks")]
[OpenApiResponseBody(HttpStatusCode.Unauthorized, "text/plain", typeof(string))]
[OpenApiResponseBody(HttpStatusCode.OK, "application/json", typeof(string))]
public static object FunctionWorks(){} does not work [OpenApiOperation("FunctionFails")]
[OpenApiResponseBody(HttpStatusCode.Unauthorized, "text/plain", typeof(string))]
[OpenApiResponseBody(HttpStatusCode.OK, "application/json", typeof(JObject))]
public static object FunctionFails(){} |
- Not to include Dictionary and JObject at the root level
@JoschaMetze Both AzureFunctions.Extensions/src/Aliencube.AzureFunctions.FunctionAppCommon/Models/SampleModel.cs Line 53 in 75c770c
AzureFunctions.Extensions/src/Aliencube.AzureFunctions.FunctionAppCommon/Models/SampleModel.cs Line 58 in 75c770c
|
@JoschaMetze I'll close this for now. If you need further discussion, please feel free to open this again. |
@JoschaMetze Now both |
Thanks for fixing that 👍 |
If a model class for an operation contains a JObject property (or JObject itself) the generation fails with an index out of bounds exception. I suppose this is linked to
schema.AdditionalProperties = type.GetGenericArguments()[1].ToOpenApiSchema();
(line 61 of OpenApiSchemaExtensions.cs) as JObject implements IDictionary but has no generic arguments itself.I suggest either checking for JObject itself (as you are already referencing Newtonsoft.Json in that file) or checking if the count of arguments from GetGenericArguments exceeds 1.
Thanks
Joscha
The text was updated successfully, but these errors were encountered: