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

TDP: Error encoding when DatatableColumn.schema has zero-valued properties #197

Open
nokome opened this issue Jul 30, 2019 · 0 comments
Open
Labels

Comments

@nokome
Copy link
Member

nokome commented Jul 30, 2019

When encoding this Datatable:

{
  "type": "Datatable",
  "columns": [
    {
      "type": "DatatableColumn",
      "name": "species",
      "schema": {
        "items": {
          "type": "string",
          "enum": ["A", "B"]
        }
      },
      "values": ["A", "B", "A"]
    },
    {
      "type": "DatatableColumn",
      "name": "weight",
      "schema": {
        "items": {
          "type": "number",
          "minimum": 0,
          "maximum": 10
        }
      },
      "values": [1.2, 0.9, 1.4]
    }
  ]
}

as tdp, the generated datapackage.json is missing the minimum constraint:

{
    "profile": "tabular-data-package",
    "name": "Unnamed",
    "resources": [
        {
            "profile": "tabular-data-resource",
            "name": "Unnamed",
            "data": "species,weight\nA,1.2\nB,0.9\nA,1.4\n",
            "format": "csv",
            "mediatype": "text/csv",
            "encoding": "utf-8",
            "schema": {
                "fields": [
                    {
                        "name": "species",
                        "type": "string",
                        "format": "default",
                        "constraints": {
                            "required": true,
                            "enum": [
                                "A",
                                "B"
                            ]
                        }
                    },
                    {
                        "name": "weight",
                        "type": "number",
                        "format": "default",
                        "constraints": {
                            "required": true,
                            "maximum": 10
                        }
                    }
                ],
                "missingValues": [
                    ""
                ]
            }
        }
    ]
}

That is because we are using a non-boolean expression in the if here:

if (constraints.minimum) items.minimum = constraints.minimum

A good example of where @typescript-eslint/strict-boolean-expressions are useful, see stencila/dev-config#4.

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

No branches or pull requests

1 participant