Skip to content
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

Resolves a null pointer exception when returning a Dictionary containing known keys #2373

Merged
merged 1 commit into from
Nov 15, 2022

Conversation

Eneuman
Copy link
Contributor

@Eneuman Eneuman commented Mar 14, 2022

This PR fixes a null pointer exception when having a API returning av Dictionary containing known keys
(ie a Dictionary<Enum, string>).

The problem was that the code tried to set schema.AdditionalProperties.Nullable without first checking if schema.AdditionalPropertiesAllowed was true. This resulted in a null point exception since schema.AdditionalProperties is null when schema.AdditionalPropertiesAllowed is false.

Fixes #2368

@Eneuman Eneuman changed the title Resolves a null pointer exception when using NewtonsoftSupport Resolves a null pointer exception in the Dictionary handling Mar 14, 2022
@Eneuman Eneuman changed the title Resolves a null pointer exception in the Dictionary handling Resolves a null pointer exception when returning a Dictionary containing known keys Mar 14, 2022
@Eneuman
Copy link
Contributor Author

Eneuman commented Apr 26, 2022

@domaindrivendev Ping :)

@jelical
Copy link

jelical commented May 2, 2022

Hello, there @domaindrivendev :) Any news on this?

@sergey-litvinov
Copy link

@domaindrivendev is there any update on this PR and related issue? i'm having the same problem related to Dictionary and NRE during schema generation

@cezkc
Copy link

cezkc commented Jun 27, 2022

I just have the same problem here, using an example with
MapType<Dictionary<string, JToken>>(() => new OpenApiSchema { Example = new OpenApiObject { ["customerName"] = new OpenApiObject { ["+150000000000"] = new OpenApiString("Jon"), ["+160000000000"] = new OpenApiString("Doe"), ["default"] = new OpenApiString("there"), }, ["orderNumber"] = new OpenApiObject { ["+150000000000"] = new OpenApiString("1234"), ["+160000000000"] = new OpenApiString("4321"), ["default"] = new OpenApiString("0000"), }, }, Properties = new Dictionary<string, OpenApiSchema> { {"customerName", new OpenApiSchema{ Type="object" } }, {"orderNumber", new OpenApiSchema{ Type="object" } }, }, Type = "object" });

I had to add an empty AdditionalProperties to not throw an error again:
AdditionalProperties = new OpenApiSchema { }

Is there any fix for that? On previous versions (<=6.2.3) it was working fine

using
Swashbuckle.AspNetCore.SwaggerUI 6.3.1
Swashbuckle.AspNetCore.Annotations 6.3.1

@Eneuman
Copy link
Contributor Author

Eneuman commented Jul 4, 2022

@domaindrivendev ping

@tomhreb
Copy link

tomhreb commented Aug 4, 2022

Hi @domaindrivendev, @JakubHolovsky -- any news on this please?

@plutora-steve-g
Copy link

The issue is still present in 6.4.0

@asmcpluss
Copy link

Any updates here?

@B-DAP
Copy link

B-DAP commented Sep 8, 2022

bump

@jason-daly
Copy link

I just tripped over this issue after updating to 6.4.0. Would be nice to see it fixed.

@plachor
Copy link

plachor commented Sep 15, 2022

Looking forward fix as well.

@fschick
Copy link

fschick commented Sep 19, 2022

Same issue here. Can't update to 6.4.0.

@JakubHolovsky
Copy link

Hi @domaindrivendev, @JakubHolovsky -- any news on this please?

I am not the maintainer but trying to get all the attention to this so it finally gets merged. Stuck on older version here as well.

@sergei-lobanov
Copy link

@domaindrivendev hello, could you please approve this PR? We are all waiting months...

@domaindrivendev domaindrivendev merged commit 2da3a72 into domaindrivendev:master Nov 15, 2022
@hecerinc
Copy link

@domaindrivendev could we possibly get a release with this fix in? Thank you!

@angelaki
Copy link
Contributor

angelaki commented Dec 2, 2022

Waiting for this fix, too. Soon deploy would be awesome!

@sguryev
Copy link

sguryev commented Dec 12, 2022

We have made Dictionary enum key nullable Dictionary<Enum?, Model> and SwaggerUI looks this way now
image
Waiting for the release 🤞🏼

@oyzar
Copy link

oyzar commented Dec 14, 2022

When will a version with this fix be released?

@vitaliy-orlov
Copy link

Waiting for this fix, too!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Potential problems with 6.3.0