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

Empty property removed when serializing #2087

Open
desmarest opened this issue Jan 24, 2025 · 2 comments
Open

Empty property removed when serializing #2087

desmarest opened this issue Jan 24, 2025 · 2 comments
Labels
status:needs-discussion An issue that requires more discussion internally before resolving

Comments

@desmarest
Copy link

desmarest commented Jan 24, 2025

Describe the bug
Empty properties are removed when serializing.

Repro steps

            var openApiDocument = new OpenApiDocument
            {
                Components = new OpenApiComponents
                {
                    Schemas = new Dictionary<string, OpenApiSchema>
                    {
                        ["Object"] = new OpenApiSchema
                        {
                            Type = "object",
                            Properties = new Dictionary<string, OpenApiSchema>()
                        }
                    }
                }
            };

            var test = JObject.Parse(openApiDocument.SerializeAsJson(OpenApiSpecVersion.OpenApi2_0));
            Console.WriteLine(test);

Expected result

{
  "swagger": "2.0",
  "info": {},
  "paths": {},
  "definitions": {
    "Object": {
      "type": "object"
      "properties": {}
    }
  }
}

Actual result

{
  "swagger": "2.0",
  "info": {},
  "paths": {},
  "definitions": {
    "Object": {
      "type": "object"
    }
  }
}
@RachitMalik12
Copy link

@darrelmiller do you have any thoughts?

@RachitMalik12 RachitMalik12 added the status:needs-discussion An issue that requires more discussion internally before resolving label Feb 6, 2025
@darrelmiller
Copy link
Member

There is no semantic difference between the two, so I'm not sure why for the "properties" property it matters. For properties where an empty object is semantically significant, like an empty paths object, we do keep the property. However, in this case we don't. It would be good to understand what is the concern here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:needs-discussion An issue that requires more discussion internally before resolving
Projects
None yet
Development

No branches or pull requests

3 participants