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

[regression] nullabillity problems wih dictionaries since 6.3.0 #2436

Closed
RouR opened this issue Jun 9, 2022 · 2 comments
Closed

[regression] nullabillity problems wih dictionaries since 6.3.0 #2436

RouR opened this issue Jun 9, 2022 · 2 comments

Comments

@RouR
Copy link

RouR commented Jun 9, 2022

I have some class

public class Class1
{
	public class Class1Request
	{          
		public Dictionary<string, int> Data { get; set; }
	}
}

Also I have

//https://github.com/domaindrivendev/Swashbuckle.AspNetCore/issues/1502
    public class AdditionalParametersDocumentFilter : IDocumentFilter
    {
        public void Apply(OpenApiDocument openApiDoc, DocumentFilterContext context)
        {
            foreach (var schema in context.SchemaRepository.Schemas)
            {
                if (schema.Value.AdditionalProperties == null)
                {
                    schema.Value.AdditionalPropertiesAllowed = false;
                }
            }
        }
    }

Generated result

6.2.3

"Class1Request": {
	"type": "object",
	"properties": {
	  "idempotencyKey": {
		"$ref": "#/components/schemas/IdempotencyKey"
	  },
	  "userId": {
		"$ref": "#/components/schemas/UserId"
	  },
	  "data": {
		"type": "object",
		"additionalProperties": {
		  "type": "integer",
		  "format": "int32"
		},
		"nullable": true
	  }
	},
	"additionalProperties": false
},		
public System.Collections.Generic.IDictionary<string, int> Data { get; set; }

6.3.0 and 6.3.1

"Class1Request": {
	"type": "object",
	"properties": {          
	  "data": {
		"type": "object",
		"additionalProperties": {
		  "type": "integer",
		  "format": "int32",
		  "nullable": true
		},
		"nullable": true
	  }
	},
	"additionalProperties": false
},
	  
public System.Collections.Generic.IDictionary<string, int?> Data { get; set; }	

I guess it was broken in
#2166

Expected result

public System.Collections.Generic.IDictionary<string, int> Data { get; set; }
@WebGL3D
Copy link

WebGL3D commented Feb 22, 2023

After some investigation, and running into this same issue myself, it seems if Class1Request.Data is of type IDictionary<string, int>, this becomes a non-issue. I have not dug into the source to investigate why, but switching to IDictionary is a reasonable workaround for me.

@martincostello
Copy link
Collaborator

To make issue tracking a bit less overwhelming for the new maintainers (see #2778), I've created a new tracking issue to roll-up various nullability issues here: #2793.

We'll refer back to this issue from there and include it as part of resolving that issue, but I'm going to close this one to help prune the backlog.

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

No branches or pull requests

3 participants