Skip to content

Fix nesteddict2yaml not to fumble empty dict values #1

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

Merged
merged 1 commit into from
Dec 12, 2024

Conversation

@sakurai-youhei
Copy link
Author

@stj Could you consider merging this PR and tagging? Thank you.

@stj
Copy link
Owner

stj commented Dec 11, 2024

@sakurai-youhei the upstream project is dead. It says it looks for maintainers. It hasn't had an update in 3 years I believe.
Opening issues upstream might not be worth a lot.

Copy link
Owner

@stj stj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So an empty dict becomes nothing in yaml?
Is the result accurate if you do a JSON to YAML to JSON conversion?
I expect to see {} in the YAML, but this change will result in an empty dict being None, right?
@sakurai-youhei

@sakurai-youhei
Copy link
Author

@stj Yeah, I had a faint hope that if I sent a PR, it might be taken in, but looking at the current situation, it seems that there is no possibility of a revival.

So an empty dict becomes nothing in yaml?

Yes. I believe that is inpreferable behavior addressed in this PR.

Current behavior

Definition:

definitions = dict(
    test={
        "type": "object",
        "properties": {"prop": {"type": "object", "default": dict()}},
    }
)

JSON:

{
  "openapi": "3.0.1",
  "info": {
    "title": "Swagger API",
    "description": "Swagger API definition",
    "version": "1.0.0"
  },
  "servers": [
    {
      "url": "/"
    }
  ],
  "components": {
    "schemas": {
      "test": {
        "type": "object",
        "properties": {
          "prop": {
            "type": "object",
            "default": null
          }
        }
      }
    }
  },
  "paths": {}
}

YAML:

openapi: 3.0.1
info:
  title: Swagger API
  description: Swagger API definition
  version: 1.0.0
servers:
- url: "/"
components:
  schemas:
    test:
      type: object
      properties:
        prop:
          type: object
          default: 
paths: {}

Expected behavior

Definition: Same

JSON:

{
  "openapi": "3.0.1",
  "info": {
    "title": "Swagger API",
    "description": "Swagger API definition",
    "version": "1.0.0"
  },
  "servers": [
    {
      "url": "/"
    }
  ],
  "components": {
    "schemas": {
      "test": {
        "type": "object",
        "properties": {
          "prop": {
            "type": "object",
            "default": {}
          }
        }
      }
    }
  },
  "paths": {}
}

YAML:

openapi: 3.0.1
info:
  title: Swagger API
  description: Swagger API definition
  version: 1.0.0
servers:
- url: "/"
components:
  schemas:
    test:
      type: object
      properties:
        prop:
          type: object
          default: {}
paths: {}

Is the result accurate if you do a JSON to YAML to JSON conversion?

Yes.

I expect to see {} in the YAML, but this change will result in an empty dict being None, right?

I have the same expectation as yours. So this change will correct the current behavior to be aligned to our expectation - an empty dict being not None but {}.

@stj stj merged commit 79a63f2 into stj:master Dec 12, 2024
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.

2 participants