question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Validation keywords for primitives in arrays

See original GitHub issue

Would be nice if we could specify validation keywords for primitive array items. Example:

export interface Test {
  /**
   * @multipleOf 10
   */
  numbersArray?: number[];
}

now converts to

"Test": {
  "additionalProperties": false,
  "properties": {
    "numbersArray": {
      "items": {
        "type": "number"
      },
      "multipleOf": 10,
      "type": "array"
    },
  },
  "type": "object"
}

but should instead be converted to

"Test": {
  "additionalProperties": false,
  "properties": {
    "numbersArray": {
      "items": {
        "type": "number",
        "multipleOf": 10
      },
      "type": "array"
    },
  },
  "type": "object"
}

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
grigaspcommented, Aug 2, 2018

It doesn’t look like TJS picks up type annotations for properties:

/**
 * Some type description
 * @multipleOf 10
 * @type integer
 */
export type SomeNumber = number;

export interface Test {
  /** 
   * Some property description
   */
  numbersArray?: SomeNumber[];
}

gets converted to

"Test": {
  "additionalProperties": false,
  "properties": {
    "numbersArray": {
      "description": "Some property description",
      "items": {
        "type": "number"
      },
      "type": "array"
    }
  },
  "type": "object"
}
0reactions
dobesvcommented, Dec 4, 2019

The original issue was about specifying information about the elements of an array. I am trying to do this as well.

I tried an approach like this:

/**
 * @items {"type":"integer"}
 */
 grades: number[];

but it doesn’t seem to set items for some reason.

Read more comments on GitHub >

github_iconTop Results From Across the Web

A Vocabulary for Structural Validation of JSON - JSON Schema
Validation Keywords for Arrays ... String values MUST be one of the six primitive types ("null", "boolean", "object", "array", "number", ...
Read more >
JSON Schema Validation: A Vocabulary for Structural ... - IETF
For arrays, primitive type validation consists of validating restrictions on ... Each JSON Schema validation keyword adds constraints that an instance must ...
Read more >
ajv-keywords - Ajv JSON schema validator
The keyword allows to check that some properties in array items are unique. This keyword applies only to arrays. If the data is...
Read more >
JSON Schema: How to check that an array contains at least ...
The value of this keyword MUST be a valid JSON Schema. An array instance is valid against "contains" if at least one of...
Read more >
Validate.io-string-primitive-array NPM | npm.io
Validates if a value is an array of string primitives. Installation. $ npm install validate.io-string-primitive-array. For use in the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found