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

Array of array loses its constraints #297

Open
Aedial opened this issue Nov 23, 2022 · 0 comments
Open

Array of array loses its constraints #297

Aedial opened this issue Nov 23, 2022 · 0 comments

Comments

@Aedial
Copy link

Aedial commented Nov 23, 2022

An array of arrays gets translated into List[List[T]], even when the second array has contraints, losing these constraints. Minimal working example :

{
  "components": {
    "schemas": {
      "Mod": {
        "type": "object",
        "properties": {
          "prop": {
            "type": "array",
            "items": {
              "type": "array",
              "items": {
                "type": "number",
              },
              "minItems": 3,
              "maxItems": 6
            }
          }
        },
      }
    }
  }
}

I see 2 solutions to that :
1 - Use a conlist to keep the contraints. Albeit compact and easy (only a few lines to add around datamodel-code-generator/types.py L87,L254 and datamodel-code-generator/parser/jsonschema.py L772), it would stand out quite a bit, compared to the rest (the conX objects being alone in their own Item model).
2 - Handle constrained array the same way object is handled: by giving it its own Model, which would allow to store the constraints in Field, as it is done for a single array.

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

1 participant