Repository: s-knibbs/dataclasses-jsonschema (python)

Issue:
Schema for tuple types incompatible with OpenAPI Spec 3.0
The following schema is valid for jsonschema but not for openapi 3.0:

```json
{
  "type": "array",
  "minItems": 2,
  "maxItems": 2,
  "items": [{"type": "number"}, {"type": "number"}]
}
```

For the above case, since both tuple items have the same type, we can replace the above with this:

```json
{
  "type": "array",
  "minItems": 2,
  "maxItems": 2,
  "items": {"type": "number"}
}
```

Pull request description:
Generated tuple schema is now compliant with openapi 3.0
Closes #182 

Patch:
diff --git a/dataclasses_jsonschema/__init__.py b/dataclasses_jsonschema/__init__.py
index c89fb5b..f6d0aaa 100644
--- a/dataclasses_jsonschema/__init__.py
+++ b/dataclasses_jsonschema/__init__.py
@@ -708,6 +708,7 @@ class JsonSchemaMixin:
                 if field_args[1] is not Any:
                     field_schema['additionalProperties'] = cls._get_field_schema(field_args[1], schema_options)[0]
             elif field_type_name in SEQUENCE_TYPES or (field_type_name in TUPLE_TYPES and ... in field_args):
+                # TODO: How do we handle Optional type within lists / tuples
                 field_schema = {'type': 'array'}
                 if field_args[0] is not Any:
                     field_schema['items'] = cls._get_field_schema(field_args[0], schema_options)[0]
@@ -715,10 +716,11 @@ class JsonSchemaMixin:
                     field_schema['uniqueItems'] = True
             elif field_type_name in TUPLE_TYPES:
                 tuple_len = len(field_args)
-                # TODO: How do we handle Optional type within lists / tuples
+                # TODO: If there are multiple distinct item_schemas, this is not compliant with OpenAPI 3.0
+                item_schemas = [cls._get_field_schema(type_arg, schema_options)[0] for type_arg in field_args]
                 field_schema = {
                     'type': 'array', 'minItems': tuple_len, 'maxItems': tuple_len,
-                    'items': [cls._get_field_schema(type_arg, schema_options)[0] for type_arg in field_args]
+                    'items': item_schemas[0] if len(set(field_args)) == 1 else item_schemas
                 }
             elif field_type in JSON_ENCODABLE_TYPES:
                 field_schema.update(JSON_ENCODABLE_TYPES[field_type])


Test patch:
diff --git a/tests/test_core.py b/tests/test_core.py
index 9f390d7..ad4f2b7 100644
--- a/tests/test_core.py
+++ b/tests/test_core.py
@@ -5,7 +5,7 @@ from enum import Enum
 
 from dataclasses import dataclass, field
 from ipaddress import IPv4Address, IPv6Address
-from typing import List, NewType, Optional, Union, Set, Any, cast, Dict
+from typing import List, NewType, Optional, Union, Set, Any, cast, Dict, Tuple
 from typing_extensions import Final, Literal
 from uuid import UUID
 
@@ -1052,3 +1052,13 @@ def test_union_with_discriminator():
     data = Person(name="Joe", pet=Dog(breed="Pug")).to_dict()
     p = Person.from_dict(data)
     assert p.pet == Dog(breed="Pug")
+
+
+def test_tuple_item_schema():
+    @dataclass
+    class MapNote(JsonSchemaMixin):
+        text: str
+        point: Tuple[float, float]
+
+    expected_tuple_schema = {"type": "array", "minItems": 2, "maxItems": 2, "items": {"type": "number"}}
+    assert MapNote.json_schema()['properties']['point'] == expected_tuple_schema