Skip to content

Arrays wrongly require items #314

@spencerwilson

Description

@spencerwilson

Given

{
  "title": "hello",
  "type": "array",
  "minItems": 1,
  "uniqueItems": true
}

cargo-typify 0.0.13 errors:

% cargo typify other.json
Error:
   0: Failed to convert JSON Schema to Rust code
   1: Schema conversion failed
   2: schema invalid: unhandled array validation ArrayValidation {
          items: None,
          additional_items: None,
          max_items: None,
          min_items: Some(
              1,
          ),
          unique_items: Some(
              true,
          ),
          contains: None,
      }
...

In the latest JSON Schema spec (2020-12 Core),

Omitting [items] has the same assertion behavior as an empty schema.

typify does do something reasonable when adding an "items": {} to the schema: it generates a struct like

pub struct Hello(pub Vec<serde_json::Value>);

(arguably the minimum reasonable data structure would be something like a Vec<serde_json::Value>, but not sure if typify should try to be that clever)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions