PassFort / json-schema-to-flow-type

69 stars 17 forks source link

TypeError: Property internalSlots expected type of array but got boolean #27

Open natramov opened 6 years ago

natramov commented 6 years ago

Hi, in version 0.4.0 i get this type error:

TypeError: Property internalSlots expected type of array but got boolean at validate (/Users/admin/WebstormProjects/flow-swagger/node_modules/@babel/types/lib/definitions/utils.js:161:13) at Object.validate (/Users/admin/WebstormProjects/flow-swagger/node_modules/@babel/types/lib/definitions/utils.js:172:7) at validate (/Users/admin/WebstormProjects/flow-swagger/node_modules/@babel/types/lib/validators/validate.js:17:9) at builder (/Users/admin/WebstormProjects/flow-swagger/node_modules/@babel/types/lib/builders/builder.js:46:27) at ObjectTypeAnnotation (/Users/admin/WebstormProjects/flow-swagger/node_modules/@babel/types/lib/builders/generated/index.js:649:31) at processObjectSchema (/Users/admin/WebstormProjects/flow-swagger/node_modules/json-schema-to-flow-type/lib/FlowTypeGenerator.js:43:12) at exports.toFlowType.flowSchema (/Users/admin/WebstormProjects/flow-swagger/node_modules/json-schema-to-flow-type/lib/FlowTypeGenerator.js:60:12) at exports.toFlow.flowSchema (/Users/admin/WebstormProjects/flow-swagger/node_modules/json-schema-to-flow-type/lib/index.js:33:194) at exports.schemaToFlow.flowSchema (/Users/admin/WebstormProjects/flow-swagger/node_modules/json-schema-to-flow-type/lib/index.js:35:139) at /Users/admin/WebstormProjects/flow-swagger/node_modules/lodash/lodash.js:5138:35

wmonk commented 6 years ago

Please can you provide some more detail as how to reproduce this error.

benjamine commented 6 years ago

+1, I avoided it downgrading to 0.2.6 (the previous version I was using)

wmonk commented 6 years ago

@benjamine @natramov can you provide more information. Would be helpful to have the schema that is causing this issue. Closing until that point.

benjamine commented 6 years ago

@wmonk

const jsonSchemaToFlowType = require("json-schema-to-flow-type");

const schema = {
    "type": "object",
    "properties": {
      "id": {
        "type": "string"
      },
      "reportType": {
        "type": "string",
        "example": "issues",
        "description": "a report type"
      },
      "params": {
        "type": "object",
        "description": "parameters for the report.\n        these can be specific to the report type",
        "properties": {}
      },
      "createdAt": {
        "$ref": "#/definitions/Date"
      }
    },
    "additionalProperties": false,
    "required": [
      "id",
      "reportType",
      "params",
      "createdAt"
    ],
    "id": "Report"
  };

 const imports = {
    "Report": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string"
        },
        "reportType": {
          "type": "string",
          "example": "issues",
          "description": "a report type"
        },
        "params": {
          "type": "object",
          "description": "parameters for the report.\n        these can be specific to the report type"
        },
        "createdAt": {
          "type": "string",
          "format": "date-time",
          "pattern": "^\\d{4}-\\d{2}-\\d{2}[T ]\\d{2}:\\d{2}:\\d{2}\\.{0,1}[0-9]*Z$",
          "description": "creation datetime"
        }
      },
      "additionalProperties": false,
      "required": [
        "id",
        "reportType",
        "params",
        "createdAt"
      ],
      "id": "Report"
    },
    "ReportList": {
      "type": "object",
      "properties": {
        "entries": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/Report"
          }
        }
      },
      "additionalProperties": false,
      "required": [
        "entries"
      ],
      "id": "ReportList"
    }
  };

jsonSchemaToFlowType.parseSchema(schema, imports);

on 0.4.0 throws:

TypeError: Property internalSlots expected type of array but got boolean
   at validate in @babel/types/lib/definitions/utils.js — line 161
   at Object.validate in @babel/types/lib/definitions/utils.js — line 172
   ....

(works fine with 0.2.6)

wmonk commented 6 years ago

@benjamine thanks for this, will investigate

zhulduz commented 6 years ago

@wmonk Any updates?

esturcke commented 5 years ago

Looks like the problem is the @babel/types signature for objectTypeAnnotation has a new 4th argument. There's an open pull request #28 to address it. I've tested this fix locally and it's working for me.

esturcke commented 5 years ago

As a stopgap, @marudor has published @marudor/json-schema-to-flow-type with the fix.

sakai-akinobu commented 5 years ago

This problem was solved in #28 and v1.0.0 was released. So I recommend using v1.0.0.