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

Failing schema: unhandled array validation #269

Open
clbarnes opened this issue Apr 26, 2023 · 1 comment
Open

Failing schema: unhandled array validation #269

clbarnes opened this issue Apr 26, 2023 · 1 comment

Comments

@clbarnes
Copy link

The schema is here: https://github.com/jgm/djot.js/blob/baa4d3e62bccaebe0680adea1b185adbd211fd8a/djot-schema.json , and is AFAIK automatically generated using typescript-json-schema.

The output of cargo typify is

cargo typify --output src/types.rs djot.js/djot-schema.json
Error: 
   0: Failed to convert JSON Schema to Rust code
   1: Could not add ref types from the 'definitions' field in the JSON Schema
   2: schema invalid: unhandled array validation ArrayValidation {
          items: Some(
              Vec(
                  [
                      Object(
                          SchemaObject {
                              metadata: None,
                              instance_type: None,
                              format: None,
                              enum_values: None,
                              const_value: None,
                              subschemas: None,
                              number: None,
                              string: None,
                              array: None,
                              object: None,
                              reference: Some(
                                  "#/definitions/Caption",
                              ),
                              extensions: {},
                          },
                      ),
                  ],
              ),
          ),
          additional_items: Some(
              Object(
                  SchemaObject {
                      metadata: None,
                      instance_type: None,
                      format: None,
                      enum_values: None,
                      const_value: None,
                      subschemas: None,
                      number: None,
                      string: None,
                      array: None,
                      object: None,
                      reference: Some(
                          "#/definitions/Row",
                      ),
                      extensions: {},
                  },
              ),
          ),
          max_items: None,
          min_items: Some(
              1,
          ),
          unique_items: None,
          contains: None,
      }
@ahl
Copy link
Collaborator

ahl commented Apr 27, 2023

Here's the schema:

                  {
                    "additionalItems": {
                        "$ref": "#/definitions/Row"
                    },
                    "items": [
                        {
                            "$ref": "#/definitions/Caption"
                        }
                    ],
                    "minItems": 1,
                    "type": "array"
                }

I think we'd want to generate a type more or less like this?

(Caption, Vec<Row>)

This is a bit like #203 and a subset of #254. In particular the constraints relevant for this proposed type are

  • maxItems = None
  • items is an array
  • items.len() == minItems

If that type seems reasonable I think it wouldn't be that hard to implement; the only trick is to "flatten" or "inline" the second item in tuple for Serialize and Deserialize (which @dtolnay describes here serde-rs/serde#1337 (comment)).

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

No branches or pull requests

2 participants