bcherny/json-schema-to-typescript

wrongly transformed array of string

Closed this issue · 6 comments

hello ...
i found an issue eslint-types/eslint-define-config that i think comes from the transformation of the jsonschema to typescript

this schema:

https://github.com/eslint/eslint/blob/b91f9dc072f17f5ea79803deb86cf002d031b4cf/lib/rules/camelcase.js#L30

is transformed

to

{
  ignoreDestructuring?: boolean
  ignoreImports?: boolean
  ignoreGlobals?: boolean
  properties?: "always" | "never"
  allow?: [] | [string]
}

the issue is allow should be string[] instead of [string]

The generated code makes sense to me since you have provided items as an array: [{ type: "string" }] and not as an object { type: "string" }. It literally assumes that your first element should be of type string.

as i understand it should be an array of string , not super familiair with json schema, but how is it supposed to be ?

as i understand it should be an array of string , not super familiair with json schema, but how is it supposed to be ?

I think they want to tell you that the issue is in eslint, not in json-schema

hehe, i got the hint @Shinigami92 :) ...

but if i look https://json-schema.org/understanding-json-schema/reference/array

What i understand (again, i'm a noob in jsonschema)

In the following example, we define that each item in an array is a number:

  "type": "array",
  "items": {
    "type": "number"
  }
}
[1, 2, 3, 4, 5]

This let me think that

  "type": "array",
  "items": {
    "type": "string"
  }
}

should allow

["one", "two", "three"]

No ?
if no (which is possible), can you help me find how is it supposed to look ?

items: [{type:'string'}] != items: {type:'string'}

oook :) thanks... let's go open a Pr there :)