From d2b74951a73462291ebaa7f5d289d56ec008ff7f Mon Sep 17 00:00:00 2001 From: Zoheb Shaikh Date: Tue, 6 Aug 2024 13:13:59 +0000 Subject: [PATCH] Ensure order of generated Schema --- pyproject.toml | 1 - schema.json | 578 ++++++++++++++++++++-------------------- src/scanspec/core.py | 20 +- src/scanspec/regions.py | 4 +- src/scanspec/service.py | 2 +- src/scanspec/specs.py | 6 +- 6 files changed, 306 insertions(+), 305 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 7f762b33..a76f223a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -80,7 +80,6 @@ ignore_missing_imports = true # Ignore missing stubs in imported modules # Run pytest with all our checkers, and don't spam us with massive tracebacks on error addopts = """ --tb=native -vv --doctest-modules --doctest-glob="*.rst" - -W ignore::DeprecationWarning """ # https://iscinumpy.gitlab.io/post/bound-version-constraints/#watch-for-warnings filterwarnings = "error" diff --git a/schema.json b/schema.json index d8aa5f62..182d729c 100644 --- a/schema.json +++ b/schema.json @@ -16,17 +16,23 @@ "schema": { "oneOf": [ { - "$ref": "#/components/schemas/Static" + "$ref": "#/components/schemas/Concat-Input" }, { "$ref": "#/components/schemas/Line" }, { - "$ref": "#/components/schemas/Concat-Input" + "$ref": "#/components/schemas/Static" + }, + { + "$ref": "#/components/schemas/Spiral" }, { "$ref": "#/components/schemas/Product-Input" }, + { + "$ref": "#/components/schemas/Repeat" + }, { "$ref": "#/components/schemas/Zip-Input" }, @@ -38,12 +44,6 @@ }, { "$ref": "#/components/schemas/Squash-Input" - }, - { - "$ref": "#/components/schemas/Repeat" - }, - { - "$ref": "#/components/schemas/Spiral" } ], "title": "Spec", @@ -69,16 +69,16 @@ "discriminator": { "propertyName": "type", "mapping": { - "Static": "#/components/schemas/Static", - "Line": "#/components/schemas/Line", "Concat": "#/components/schemas/Concat-Input", + "Line": "#/components/schemas/Line", + "Static": "#/components/schemas/Static", + "Spiral": "#/components/schemas/Spiral", "Product": "#/components/schemas/Product-Input", + "Repeat": "#/components/schemas/Repeat", "Zip": "#/components/schemas/Zip-Input", "Mask": "#/components/schemas/Mask-Input", "Snake": "#/components/schemas/Snake-Input", - "Squash": "#/components/schemas/Squash-Input", - "Repeat": "#/components/schemas/Repeat", - "Spiral": "#/components/schemas/Spiral" + "Squash": "#/components/schemas/Squash-Input" } } } @@ -255,17 +255,23 @@ "schema": { "anyOf": [ { - "$ref": "#/components/schemas/Static" + "$ref": "#/components/schemas/Concat-Input" }, { "$ref": "#/components/schemas/Line" }, { - "$ref": "#/components/schemas/Concat-Input" + "$ref": "#/components/schemas/Static" + }, + { + "$ref": "#/components/schemas/Spiral" }, { "$ref": "#/components/schemas/Product-Input" }, + { + "$ref": "#/components/schemas/Repeat" + }, { "$ref": "#/components/schemas/Zip-Input" }, @@ -277,12 +283,6 @@ }, { "$ref": "#/components/schemas/Squash-Input" - }, - { - "$ref": "#/components/schemas/Repeat" - }, - { - "$ref": "#/components/schemas/Spiral" } ], "title": "Spec", @@ -345,17 +345,23 @@ "schema": { "anyOf": [ { - "$ref": "#/components/schemas/Static" + "$ref": "#/components/schemas/Concat-Input" }, { "$ref": "#/components/schemas/Line" }, { - "$ref": "#/components/schemas/Concat-Input" + "$ref": "#/components/schemas/Static" + }, + { + "$ref": "#/components/schemas/Spiral" }, { "$ref": "#/components/schemas/Product-Input" }, + { + "$ref": "#/components/schemas/Repeat" + }, { "$ref": "#/components/schemas/Zip-Input" }, @@ -367,12 +373,6 @@ }, { "$ref": "#/components/schemas/Squash-Input" - }, - { - "$ref": "#/components/schemas/Repeat" - }, - { - "$ref": "#/components/schemas/Spiral" } ], "title": "Spec", @@ -548,34 +548,34 @@ "left": { "oneOf": [ { - "$ref": "#/components/schemas/CombinationOf-Input" + "$ref": "#/components/schemas/Range" }, { - "$ref": "#/components/schemas/Polygon" + "$ref": "#/components/schemas/Rectangle" }, { - "$ref": "#/components/schemas/DifferenceOf" + "$ref": "#/components/schemas/Polygon" }, { - "$ref": "#/components/schemas/Range" + "$ref": "#/components/schemas/Circle" }, { - "$ref": "#/components/schemas/Rectangle" + "$ref": "#/components/schemas/Ellipse" }, { - "$ref": "#/components/schemas/UnionOf" + "$ref": "#/components/schemas/CombinationOf-Input" }, { - "$ref": "#/components/schemas/SymmetricDifferenceOf" + "$ref": "#/components/schemas/UnionOf" }, { - "$ref": "#/components/schemas/Ellipse" + "$ref": "#/components/schemas/IntersectionOf" }, { - "$ref": "#/components/schemas/Circle" + "$ref": "#/components/schemas/DifferenceOf" }, { - "$ref": "#/components/schemas/IntersectionOf" + "$ref": "#/components/schemas/SymmetricDifferenceOf" } ], "title": "Left", @@ -599,34 +599,34 @@ "right": { "oneOf": [ { - "$ref": "#/components/schemas/CombinationOf-Input" + "$ref": "#/components/schemas/Range" }, { - "$ref": "#/components/schemas/Polygon" + "$ref": "#/components/schemas/Rectangle" }, { - "$ref": "#/components/schemas/DifferenceOf" + "$ref": "#/components/schemas/Polygon" }, { - "$ref": "#/components/schemas/Range" + "$ref": "#/components/schemas/Circle" }, { - "$ref": "#/components/schemas/Rectangle" + "$ref": "#/components/schemas/Ellipse" }, { - "$ref": "#/components/schemas/UnionOf" + "$ref": "#/components/schemas/CombinationOf-Input" }, { - "$ref": "#/components/schemas/SymmetricDifferenceOf" + "$ref": "#/components/schemas/UnionOf" }, { - "$ref": "#/components/schemas/Ellipse" + "$ref": "#/components/schemas/IntersectionOf" }, { - "$ref": "#/components/schemas/Circle" + "$ref": "#/components/schemas/DifferenceOf" }, { - "$ref": "#/components/schemas/IntersectionOf" + "$ref": "#/components/schemas/SymmetricDifferenceOf" } ], "title": "Right", @@ -671,34 +671,34 @@ "left": { "oneOf": [ { - "$ref": "#/components/schemas/CombinationOf-Output" + "$ref": "#/components/schemas/Range" }, { - "$ref": "#/components/schemas/Polygon" + "$ref": "#/components/schemas/Rectangle" }, { - "$ref": "#/components/schemas/DifferenceOf" + "$ref": "#/components/schemas/Polygon" }, { - "$ref": "#/components/schemas/Range" + "$ref": "#/components/schemas/Circle" }, { - "$ref": "#/components/schemas/Rectangle" + "$ref": "#/components/schemas/Ellipse" }, { - "$ref": "#/components/schemas/UnionOf" + "$ref": "#/components/schemas/CombinationOf-Output" }, { - "$ref": "#/components/schemas/SymmetricDifferenceOf" + "$ref": "#/components/schemas/UnionOf" }, { - "$ref": "#/components/schemas/Ellipse" + "$ref": "#/components/schemas/IntersectionOf" }, { - "$ref": "#/components/schemas/Circle" + "$ref": "#/components/schemas/DifferenceOf" }, { - "$ref": "#/components/schemas/IntersectionOf" + "$ref": "#/components/schemas/SymmetricDifferenceOf" } ], "title": "Left", @@ -722,34 +722,34 @@ "right": { "oneOf": [ { - "$ref": "#/components/schemas/CombinationOf-Output" + "$ref": "#/components/schemas/Range" }, { - "$ref": "#/components/schemas/Polygon" + "$ref": "#/components/schemas/Rectangle" }, { - "$ref": "#/components/schemas/DifferenceOf" + "$ref": "#/components/schemas/Polygon" }, { - "$ref": "#/components/schemas/Range" + "$ref": "#/components/schemas/Circle" }, { - "$ref": "#/components/schemas/Rectangle" + "$ref": "#/components/schemas/Ellipse" }, { - "$ref": "#/components/schemas/UnionOf" + "$ref": "#/components/schemas/CombinationOf-Output" }, { - "$ref": "#/components/schemas/SymmetricDifferenceOf" + "$ref": "#/components/schemas/UnionOf" }, { - "$ref": "#/components/schemas/Ellipse" + "$ref": "#/components/schemas/IntersectionOf" }, { - "$ref": "#/components/schemas/Circle" + "$ref": "#/components/schemas/DifferenceOf" }, { - "$ref": "#/components/schemas/IntersectionOf" + "$ref": "#/components/schemas/SymmetricDifferenceOf" } ], "title": "Right", @@ -794,17 +794,23 @@ "left": { "oneOf": [ { - "$ref": "#/components/schemas/Static" + "$ref": "#/components/schemas/Concat-Input" }, { "$ref": "#/components/schemas/Line" }, { - "$ref": "#/components/schemas/Concat-Input" + "$ref": "#/components/schemas/Static" + }, + { + "$ref": "#/components/schemas/Spiral" }, { "$ref": "#/components/schemas/Product-Input" }, + { + "$ref": "#/components/schemas/Repeat" + }, { "$ref": "#/components/schemas/Zip-Input" }, @@ -816,12 +822,6 @@ }, { "$ref": "#/components/schemas/Squash-Input" - }, - { - "$ref": "#/components/schemas/Repeat" - }, - { - "$ref": "#/components/schemas/Spiral" } ], "title": "Left", @@ -845,17 +845,23 @@ "right": { "oneOf": [ { - "$ref": "#/components/schemas/Static" + "$ref": "#/components/schemas/Concat-Input" }, { "$ref": "#/components/schemas/Line" }, { - "$ref": "#/components/schemas/Concat-Input" + "$ref": "#/components/schemas/Static" + }, + { + "$ref": "#/components/schemas/Spiral" }, { "$ref": "#/components/schemas/Product-Input" }, + { + "$ref": "#/components/schemas/Repeat" + }, { "$ref": "#/components/schemas/Zip-Input" }, @@ -867,12 +873,6 @@ }, { "$ref": "#/components/schemas/Squash-Input" - }, - { - "$ref": "#/components/schemas/Repeat" - }, - { - "$ref": "#/components/schemas/Spiral" } ], "title": "Right", @@ -929,17 +929,23 @@ "left": { "oneOf": [ { - "$ref": "#/components/schemas/Static" + "$ref": "#/components/schemas/Concat-Output" }, { "$ref": "#/components/schemas/Line" }, { - "$ref": "#/components/schemas/Concat-Output" + "$ref": "#/components/schemas/Static" + }, + { + "$ref": "#/components/schemas/Spiral" }, { "$ref": "#/components/schemas/Product-Output" }, + { + "$ref": "#/components/schemas/Repeat" + }, { "$ref": "#/components/schemas/Zip-Output" }, @@ -951,12 +957,6 @@ }, { "$ref": "#/components/schemas/Squash-Output" - }, - { - "$ref": "#/components/schemas/Repeat" - }, - { - "$ref": "#/components/schemas/Spiral" } ], "title": "Left", @@ -980,17 +980,23 @@ "right": { "oneOf": [ { - "$ref": "#/components/schemas/Static" + "$ref": "#/components/schemas/Concat-Output" }, { "$ref": "#/components/schemas/Line" }, { - "$ref": "#/components/schemas/Concat-Output" + "$ref": "#/components/schemas/Static" + }, + { + "$ref": "#/components/schemas/Spiral" }, { "$ref": "#/components/schemas/Product-Output" }, + { + "$ref": "#/components/schemas/Repeat" + }, { "$ref": "#/components/schemas/Zip-Output" }, @@ -1002,12 +1008,6 @@ }, { "$ref": "#/components/schemas/Squash-Output" - }, - { - "$ref": "#/components/schemas/Repeat" - }, - { - "$ref": "#/components/schemas/Spiral" } ], "title": "Right", @@ -1063,9 +1063,6 @@ "properties": { "left": { "oneOf": [ - { - "$ref": "#/components/schemas/Polygon" - }, { "$ref": "#/components/schemas/Range" }, @@ -1073,10 +1070,13 @@ "$ref": "#/components/schemas/Rectangle" }, { - "$ref": "#/components/schemas/Ellipse" + "$ref": "#/components/schemas/Polygon" }, { "$ref": "#/components/schemas/Circle" + }, + { + "$ref": "#/components/schemas/Ellipse" } ], "title": "Left", @@ -1094,9 +1094,6 @@ }, "right": { "oneOf": [ - { - "$ref": "#/components/schemas/Polygon" - }, { "$ref": "#/components/schemas/Range" }, @@ -1104,10 +1101,13 @@ "$ref": "#/components/schemas/Rectangle" }, { - "$ref": "#/components/schemas/Ellipse" + "$ref": "#/components/schemas/Polygon" }, { "$ref": "#/components/schemas/Circle" + }, + { + "$ref": "#/components/schemas/Ellipse" } ], "title": "Right", @@ -1238,9 +1238,6 @@ "properties": { "left": { "oneOf": [ - { - "$ref": "#/components/schemas/Polygon" - }, { "$ref": "#/components/schemas/Range" }, @@ -1248,10 +1245,13 @@ "$ref": "#/components/schemas/Rectangle" }, { - "$ref": "#/components/schemas/Ellipse" + "$ref": "#/components/schemas/Polygon" }, { "$ref": "#/components/schemas/Circle" + }, + { + "$ref": "#/components/schemas/Ellipse" } ], "title": "Left", @@ -1269,9 +1269,6 @@ }, "right": { "oneOf": [ - { - "$ref": "#/components/schemas/Polygon" - }, { "$ref": "#/components/schemas/Range" }, @@ -1279,10 +1276,13 @@ "$ref": "#/components/schemas/Rectangle" }, { - "$ref": "#/components/schemas/Ellipse" + "$ref": "#/components/schemas/Polygon" }, { "$ref": "#/components/schemas/Circle" + }, + { + "$ref": "#/components/schemas/Ellipse" } ], "title": "Right", @@ -1365,17 +1365,23 @@ "spec": { "oneOf": [ { - "$ref": "#/components/schemas/Static" + "$ref": "#/components/schemas/Concat-Input" }, { "$ref": "#/components/schemas/Line" }, { - "$ref": "#/components/schemas/Concat-Input" + "$ref": "#/components/schemas/Static" + }, + { + "$ref": "#/components/schemas/Spiral" }, { "$ref": "#/components/schemas/Product-Input" }, + { + "$ref": "#/components/schemas/Repeat" + }, { "$ref": "#/components/schemas/Zip-Input" }, @@ -1387,12 +1393,6 @@ }, { "$ref": "#/components/schemas/Squash-Input" - }, - { - "$ref": "#/components/schemas/Repeat" - }, - { - "$ref": "#/components/schemas/Spiral" } ], "title": "Spec", @@ -1416,34 +1416,34 @@ "region": { "oneOf": [ { - "$ref": "#/components/schemas/CombinationOf-Input" + "$ref": "#/components/schemas/Range" }, { - "$ref": "#/components/schemas/Polygon" + "$ref": "#/components/schemas/Rectangle" }, { - "$ref": "#/components/schemas/DifferenceOf" + "$ref": "#/components/schemas/Polygon" }, { - "$ref": "#/components/schemas/Range" + "$ref": "#/components/schemas/Circle" }, { - "$ref": "#/components/schemas/Rectangle" + "$ref": "#/components/schemas/Ellipse" }, { - "$ref": "#/components/schemas/UnionOf" + "$ref": "#/components/schemas/CombinationOf-Input" }, { - "$ref": "#/components/schemas/SymmetricDifferenceOf" + "$ref": "#/components/schemas/UnionOf" }, { - "$ref": "#/components/schemas/Ellipse" + "$ref": "#/components/schemas/IntersectionOf" }, { - "$ref": "#/components/schemas/Circle" + "$ref": "#/components/schemas/DifferenceOf" }, { - "$ref": "#/components/schemas/IntersectionOf" + "$ref": "#/components/schemas/SymmetricDifferenceOf" } ], "title": "Region", @@ -1494,17 +1494,23 @@ "spec": { "oneOf": [ { - "$ref": "#/components/schemas/Static" + "$ref": "#/components/schemas/Concat-Output" }, { "$ref": "#/components/schemas/Line" }, { - "$ref": "#/components/schemas/Concat-Output" + "$ref": "#/components/schemas/Static" + }, + { + "$ref": "#/components/schemas/Spiral" }, { "$ref": "#/components/schemas/Product-Output" }, + { + "$ref": "#/components/schemas/Repeat" + }, { "$ref": "#/components/schemas/Zip-Output" }, @@ -1516,12 +1522,6 @@ }, { "$ref": "#/components/schemas/Squash-Output" - }, - { - "$ref": "#/components/schemas/Repeat" - }, - { - "$ref": "#/components/schemas/Spiral" } ], "title": "Spec", @@ -1545,34 +1545,34 @@ "region": { "oneOf": [ { - "$ref": "#/components/schemas/CombinationOf-Output" + "$ref": "#/components/schemas/Range" }, { - "$ref": "#/components/schemas/Polygon" + "$ref": "#/components/schemas/Rectangle" }, { - "$ref": "#/components/schemas/DifferenceOf" + "$ref": "#/components/schemas/Polygon" }, { - "$ref": "#/components/schemas/Range" + "$ref": "#/components/schemas/Circle" }, { - "$ref": "#/components/schemas/Rectangle" + "$ref": "#/components/schemas/Ellipse" }, { - "$ref": "#/components/schemas/UnionOf" + "$ref": "#/components/schemas/CombinationOf-Output" }, { - "$ref": "#/components/schemas/SymmetricDifferenceOf" + "$ref": "#/components/schemas/UnionOf" }, { - "$ref": "#/components/schemas/Ellipse" + "$ref": "#/components/schemas/IntersectionOf" }, { - "$ref": "#/components/schemas/Circle" + "$ref": "#/components/schemas/DifferenceOf" }, { - "$ref": "#/components/schemas/IntersectionOf" + "$ref": "#/components/schemas/SymmetricDifferenceOf" } ], "title": "Region", @@ -1682,17 +1682,23 @@ "spec": { "oneOf": [ { - "$ref": "#/components/schemas/Static" + "$ref": "#/components/schemas/Concat-Input" }, { "$ref": "#/components/schemas/Line" }, { - "$ref": "#/components/schemas/Concat-Input" + "$ref": "#/components/schemas/Static" + }, + { + "$ref": "#/components/schemas/Spiral" }, { "$ref": "#/components/schemas/Product-Input" }, + { + "$ref": "#/components/schemas/Repeat" + }, { "$ref": "#/components/schemas/Zip-Input" }, @@ -1704,12 +1710,6 @@ }, { "$ref": "#/components/schemas/Squash-Input" - }, - { - "$ref": "#/components/schemas/Repeat" - }, - { - "$ref": "#/components/schemas/Spiral" } ], "title": "Spec", @@ -1814,17 +1814,23 @@ "outer": { "oneOf": [ { - "$ref": "#/components/schemas/Static" + "$ref": "#/components/schemas/Concat-Input" }, { "$ref": "#/components/schemas/Line" }, { - "$ref": "#/components/schemas/Concat-Input" + "$ref": "#/components/schemas/Static" + }, + { + "$ref": "#/components/schemas/Spiral" }, { "$ref": "#/components/schemas/Product-Input" }, + { + "$ref": "#/components/schemas/Repeat" + }, { "$ref": "#/components/schemas/Zip-Input" }, @@ -1836,12 +1842,6 @@ }, { "$ref": "#/components/schemas/Squash-Input" - }, - { - "$ref": "#/components/schemas/Repeat" - }, - { - "$ref": "#/components/schemas/Spiral" } ], "title": "Outer", @@ -1865,17 +1865,23 @@ "inner": { "oneOf": [ { - "$ref": "#/components/schemas/Static" + "$ref": "#/components/schemas/Concat-Input" }, { "$ref": "#/components/schemas/Line" }, { - "$ref": "#/components/schemas/Concat-Input" + "$ref": "#/components/schemas/Static" + }, + { + "$ref": "#/components/schemas/Spiral" }, { "$ref": "#/components/schemas/Product-Input" }, + { + "$ref": "#/components/schemas/Repeat" + }, { "$ref": "#/components/schemas/Zip-Input" }, @@ -1887,12 +1893,6 @@ }, { "$ref": "#/components/schemas/Squash-Input" - }, - { - "$ref": "#/components/schemas/Repeat" - }, - { - "$ref": "#/components/schemas/Spiral" } ], "title": "Inner", @@ -1937,17 +1937,23 @@ "outer": { "oneOf": [ { - "$ref": "#/components/schemas/Static" + "$ref": "#/components/schemas/Concat-Output" }, { "$ref": "#/components/schemas/Line" }, { - "$ref": "#/components/schemas/Concat-Output" + "$ref": "#/components/schemas/Static" + }, + { + "$ref": "#/components/schemas/Spiral" }, { "$ref": "#/components/schemas/Product-Output" }, + { + "$ref": "#/components/schemas/Repeat" + }, { "$ref": "#/components/schemas/Zip-Output" }, @@ -1959,12 +1965,6 @@ }, { "$ref": "#/components/schemas/Squash-Output" - }, - { - "$ref": "#/components/schemas/Repeat" - }, - { - "$ref": "#/components/schemas/Spiral" } ], "title": "Outer", @@ -1988,17 +1988,23 @@ "inner": { "oneOf": [ { - "$ref": "#/components/schemas/Static" + "$ref": "#/components/schemas/Concat-Output" }, { "$ref": "#/components/schemas/Line" }, { - "$ref": "#/components/schemas/Concat-Output" + "$ref": "#/components/schemas/Static" + }, + { + "$ref": "#/components/schemas/Spiral" }, { "$ref": "#/components/schemas/Product-Output" }, + { + "$ref": "#/components/schemas/Repeat" + }, { "$ref": "#/components/schemas/Zip-Output" }, @@ -2010,12 +2016,6 @@ }, { "$ref": "#/components/schemas/Squash-Output" - }, - { - "$ref": "#/components/schemas/Repeat" - }, - { - "$ref": "#/components/schemas/Spiral" } ], "title": "Inner", @@ -2211,17 +2211,23 @@ "spec": { "oneOf": [ { - "$ref": "#/components/schemas/Static" + "$ref": "#/components/schemas/Concat-Input" }, { "$ref": "#/components/schemas/Line" }, { - "$ref": "#/components/schemas/Concat-Input" + "$ref": "#/components/schemas/Static" + }, + { + "$ref": "#/components/schemas/Spiral" }, { "$ref": "#/components/schemas/Product-Input" }, + { + "$ref": "#/components/schemas/Repeat" + }, { "$ref": "#/components/schemas/Zip-Input" }, @@ -2233,12 +2239,6 @@ }, { "$ref": "#/components/schemas/Squash-Input" - }, - { - "$ref": "#/components/schemas/Repeat" - }, - { - "$ref": "#/components/schemas/Spiral" } ], "title": "Spec", @@ -2282,17 +2282,23 @@ "spec": { "oneOf": [ { - "$ref": "#/components/schemas/Static" + "$ref": "#/components/schemas/Concat-Output" }, { "$ref": "#/components/schemas/Line" }, { - "$ref": "#/components/schemas/Concat-Output" + "$ref": "#/components/schemas/Static" + }, + { + "$ref": "#/components/schemas/Spiral" }, { "$ref": "#/components/schemas/Product-Output" }, + { + "$ref": "#/components/schemas/Repeat" + }, { "$ref": "#/components/schemas/Zip-Output" }, @@ -2304,12 +2310,6 @@ }, { "$ref": "#/components/schemas/Squash-Output" - }, - { - "$ref": "#/components/schemas/Repeat" - }, - { - "$ref": "#/components/schemas/Spiral" } ], "title": "Spec", @@ -2419,17 +2419,23 @@ "spec": { "oneOf": [ { - "$ref": "#/components/schemas/Static" + "$ref": "#/components/schemas/Concat-Input" }, { "$ref": "#/components/schemas/Line" }, { - "$ref": "#/components/schemas/Concat-Input" + "$ref": "#/components/schemas/Static" + }, + { + "$ref": "#/components/schemas/Spiral" }, { "$ref": "#/components/schemas/Product-Input" }, + { + "$ref": "#/components/schemas/Repeat" + }, { "$ref": "#/components/schemas/Zip-Input" }, @@ -2441,12 +2447,6 @@ }, { "$ref": "#/components/schemas/Squash-Input" - }, - { - "$ref": "#/components/schemas/Repeat" - }, - { - "$ref": "#/components/schemas/Spiral" } ], "title": "Spec", @@ -2496,17 +2496,23 @@ "spec": { "oneOf": [ { - "$ref": "#/components/schemas/Static" + "$ref": "#/components/schemas/Concat-Output" }, { "$ref": "#/components/schemas/Line" }, { - "$ref": "#/components/schemas/Concat-Output" + "$ref": "#/components/schemas/Static" + }, + { + "$ref": "#/components/schemas/Spiral" }, { "$ref": "#/components/schemas/Product-Output" }, + { + "$ref": "#/components/schemas/Repeat" + }, { "$ref": "#/components/schemas/Zip-Output" }, @@ -2518,12 +2524,6 @@ }, { "$ref": "#/components/schemas/Squash-Output" - }, - { - "$ref": "#/components/schemas/Repeat" - }, - { - "$ref": "#/components/schemas/Spiral" } ], "title": "Spec", @@ -2609,9 +2609,6 @@ "properties": { "left": { "oneOf": [ - { - "$ref": "#/components/schemas/Polygon" - }, { "$ref": "#/components/schemas/Range" }, @@ -2619,10 +2616,13 @@ "$ref": "#/components/schemas/Rectangle" }, { - "$ref": "#/components/schemas/Ellipse" + "$ref": "#/components/schemas/Polygon" }, { "$ref": "#/components/schemas/Circle" + }, + { + "$ref": "#/components/schemas/Ellipse" } ], "title": "Left", @@ -2640,9 +2640,6 @@ }, "right": { "oneOf": [ - { - "$ref": "#/components/schemas/Polygon" - }, { "$ref": "#/components/schemas/Range" }, @@ -2650,10 +2647,13 @@ "$ref": "#/components/schemas/Rectangle" }, { - "$ref": "#/components/schemas/Ellipse" + "$ref": "#/components/schemas/Polygon" }, { "$ref": "#/components/schemas/Circle" + }, + { + "$ref": "#/components/schemas/Ellipse" } ], "title": "Right", @@ -2692,9 +2692,6 @@ "properties": { "left": { "oneOf": [ - { - "$ref": "#/components/schemas/Polygon" - }, { "$ref": "#/components/schemas/Range" }, @@ -2702,10 +2699,13 @@ "$ref": "#/components/schemas/Rectangle" }, { - "$ref": "#/components/schemas/Ellipse" + "$ref": "#/components/schemas/Polygon" }, { "$ref": "#/components/schemas/Circle" + }, + { + "$ref": "#/components/schemas/Ellipse" } ], "title": "Left", @@ -2723,9 +2723,6 @@ }, "right": { "oneOf": [ - { - "$ref": "#/components/schemas/Polygon" - }, { "$ref": "#/components/schemas/Range" }, @@ -2733,10 +2730,13 @@ "$ref": "#/components/schemas/Rectangle" }, { - "$ref": "#/components/schemas/Ellipse" + "$ref": "#/components/schemas/Polygon" }, { "$ref": "#/components/schemas/Circle" + }, + { + "$ref": "#/components/schemas/Ellipse" } ], "title": "Right", @@ -2776,17 +2776,23 @@ "input_spec": { "oneOf": [ { - "$ref": "#/components/schemas/Static" + "$ref": "#/components/schemas/Concat-Output" }, { "$ref": "#/components/schemas/Line" }, { - "$ref": "#/components/schemas/Concat-Output" + "$ref": "#/components/schemas/Static" + }, + { + "$ref": "#/components/schemas/Spiral" }, { "$ref": "#/components/schemas/Product-Output" }, + { + "$ref": "#/components/schemas/Repeat" + }, { "$ref": "#/components/schemas/Zip-Output" }, @@ -2798,12 +2804,6 @@ }, { "$ref": "#/components/schemas/Squash-Output" - }, - { - "$ref": "#/components/schemas/Repeat" - }, - { - "$ref": "#/components/schemas/Spiral" } ], "title": "Input Spec", @@ -2827,17 +2827,23 @@ "valid_spec": { "oneOf": [ { - "$ref": "#/components/schemas/Static" + "$ref": "#/components/schemas/Concat-Output" }, { "$ref": "#/components/schemas/Line" }, { - "$ref": "#/components/schemas/Concat-Output" + "$ref": "#/components/schemas/Static" + }, + { + "$ref": "#/components/schemas/Spiral" }, { "$ref": "#/components/schemas/Product-Output" }, + { + "$ref": "#/components/schemas/Repeat" + }, { "$ref": "#/components/schemas/Zip-Output" }, @@ -2849,12 +2855,6 @@ }, { "$ref": "#/components/schemas/Squash-Output" - }, - { - "$ref": "#/components/schemas/Repeat" - }, - { - "$ref": "#/components/schemas/Spiral" } ], "title": "Valid Spec", @@ -2922,17 +2922,23 @@ "left": { "oneOf": [ { - "$ref": "#/components/schemas/Static" + "$ref": "#/components/schemas/Concat-Input" }, { "$ref": "#/components/schemas/Line" }, { - "$ref": "#/components/schemas/Concat-Input" + "$ref": "#/components/schemas/Static" + }, + { + "$ref": "#/components/schemas/Spiral" }, { "$ref": "#/components/schemas/Product-Input" }, + { + "$ref": "#/components/schemas/Repeat" + }, { "$ref": "#/components/schemas/Zip-Input" }, @@ -2944,12 +2950,6 @@ }, { "$ref": "#/components/schemas/Squash-Input" - }, - { - "$ref": "#/components/schemas/Repeat" - }, - { - "$ref": "#/components/schemas/Spiral" } ], "title": "Left", @@ -2973,17 +2973,23 @@ "right": { "oneOf": [ { - "$ref": "#/components/schemas/Static" + "$ref": "#/components/schemas/Concat-Input" }, { "$ref": "#/components/schemas/Line" }, { - "$ref": "#/components/schemas/Concat-Input" + "$ref": "#/components/schemas/Static" + }, + { + "$ref": "#/components/schemas/Spiral" }, { "$ref": "#/components/schemas/Product-Input" }, + { + "$ref": "#/components/schemas/Repeat" + }, { "$ref": "#/components/schemas/Zip-Input" }, @@ -2995,12 +3001,6 @@ }, { "$ref": "#/components/schemas/Squash-Input" - }, - { - "$ref": "#/components/schemas/Repeat" - }, - { - "$ref": "#/components/schemas/Spiral" } ], "title": "Right", @@ -3045,17 +3045,23 @@ "left": { "oneOf": [ { - "$ref": "#/components/schemas/Static" + "$ref": "#/components/schemas/Concat-Output" }, { "$ref": "#/components/schemas/Line" }, { - "$ref": "#/components/schemas/Concat-Output" + "$ref": "#/components/schemas/Static" + }, + { + "$ref": "#/components/schemas/Spiral" }, { "$ref": "#/components/schemas/Product-Output" }, + { + "$ref": "#/components/schemas/Repeat" + }, { "$ref": "#/components/schemas/Zip-Output" }, @@ -3067,12 +3073,6 @@ }, { "$ref": "#/components/schemas/Squash-Output" - }, - { - "$ref": "#/components/schemas/Repeat" - }, - { - "$ref": "#/components/schemas/Spiral" } ], "title": "Left", @@ -3096,17 +3096,23 @@ "right": { "oneOf": [ { - "$ref": "#/components/schemas/Static" + "$ref": "#/components/schemas/Concat-Output" }, { "$ref": "#/components/schemas/Line" }, { - "$ref": "#/components/schemas/Concat-Output" + "$ref": "#/components/schemas/Static" + }, + { + "$ref": "#/components/schemas/Spiral" }, { "$ref": "#/components/schemas/Product-Output" }, + { + "$ref": "#/components/schemas/Repeat" + }, { "$ref": "#/components/schemas/Zip-Output" }, @@ -3118,12 +3124,6 @@ }, { "$ref": "#/components/schemas/Squash-Output" - }, - { - "$ref": "#/components/schemas/Repeat" - }, - { - "$ref": "#/components/schemas/Spiral" } ], "title": "Right", diff --git a/src/scanspec/core.py b/src/scanspec/core.py index 487ab9de..60302e74 100644 --- a/src/scanspec/core.py +++ b/src/scanspec/core.py @@ -49,7 +49,10 @@ StrictConfig: ConfigDict = {"extra": "forbid"} -def discriminated_union_of_subclasses(cls): +def discriminated_union_of_subclasses( + cls, + discriminator: str = "type", +): """Add all subclasses of super_cls to a discriminated union. For all subclasses of super_cls, add a discriminator field to identify @@ -118,7 +121,7 @@ def calculate(self) -> int: Union[Type, Callable[[Type], Type]]: A decorator that adds the necessary functionality to a class. """ - tagged_union = _TaggedUnion(cls) + tagged_union = _TaggedUnion(cls, discriminator) _tagged_unions[cls] = tagged_union cls.__init_subclass__ = classmethod(__init_subclass__) cls.__get_pydantic_core_schema__ = classmethod( @@ -143,13 +146,14 @@ def uses_tagged_union(cls_or_func: T) -> T: class _TaggedUnion: - def __init__(self, base_class: type): + def __init__(self, base_class: type, discriminator: str): self._base_class = base_class # The members of the tagged union, i.e. subclasses of the baseclasses - self._members: set[type] = set() + self._members: list[type] = [] # Classes and their field names that refer to this tagged union self._referrers: dict[type | Callable, set[str]] = {} - self.type_adapter = TypeAdapter(None) + self.type_adapter: TypeAdapter = TypeAdapter(None) + self._discriminator = discriminator def _make_union(self): # Make a union of members @@ -165,7 +169,7 @@ def _set_discriminator(self, cls: type | Callable, field_name: str, field: Any): assert isinstance( field, FieldInfo ), f"Expected {cls.__name__}.{field_name} to be a Pydantic field, not {field!r}" # noqa: E501 - field.discriminator = "type" + field.discriminator = self._discriminator def add_member(self, cls: type): if cls in self._members: @@ -175,7 +179,7 @@ def add_member(self, cls: type): return if cls is self._base_class: return - self._members.add(cls) + self._members.append(cls) union = self._make_union() if union: # There are more than 1 subclasses in the union, so set all the referrers @@ -199,8 +203,6 @@ def add_referrer(self, cls: type | Callable, attr_name: str): # note that we use annotations as the class has not been turned into # a dataclass yet cls.__annotations__[attr_name] = union - if not isclass(cls): - print(dir(cls.__defaults__)) self._set_discriminator(cls, attr_name, getattr(cls, attr_name, None)) diff --git a/src/scanspec/regions.py b/src/scanspec/regions.py index 23723100..f291b45a 100644 --- a/src/scanspec/regions.py +++ b/src/scanspec/regions.py @@ -174,10 +174,10 @@ class Polygon(Region[Axis]): x_axis: Axis = Field(description="The name matching the x axis of the spec") y_axis: Axis = Field(description="The name matching the y axis of the spec") x_verts: List[float] = Field( - description="The Nx1 x coordinates of the polygons vertices", min_len=3 + description="The Nx1 x coordinates of the polygons vertices", min_length=3 ) y_verts: List[float] = Field( - description="The Nx1 y coordinates of the polygons vertices", min_len=3 + description="The Nx1 y coordinates of the polygons vertices", min_length=3 ) def axis_sets(self) -> List[Set[Axis]]: diff --git a/src/scanspec/service.py b/src/scanspec/service.py index 9f6df261..4ef53e31 100644 --- a/src/scanspec/service.py +++ b/src/scanspec/service.py @@ -129,7 +129,7 @@ class SmallestStepResponse: @app.post("/valid", response_model=ValidResponse) @uses_tagged_union def valid( - spec: Spec = Body(..., examples=[_EXAMPLE_SPEC], discriminator="type"), + spec: Spec = Body(..., examples=[_EXAMPLE_SPEC]), ) -> Union[ValidResponse, JSONResponse]: """Validate wether a ScanSpec can produce a viable scan. diff --git a/src/scanspec/specs.py b/src/scanspec/specs.py index 61aa9a66..00aa34ac 100644 --- a/src/scanspec/specs.py +++ b/src/scanspec/specs.py @@ -233,7 +233,7 @@ def bounded( return cls(axis, start, stop, num) -Line.bounded = validate_call(Line.bounded) +Line.bounded = validate_call(Line.bounded) # type:ignore @dataclass(config=StrictConfig) @@ -281,7 +281,7 @@ def calculate(self, bounds=True, nested=False) -> List[Frames[Axis]]: ) -Static.duration = validate_call(Static.duration) +Static.duration = validate_call(Static.duration) # type:ignore @dataclass(config=StrictConfig) @@ -369,7 +369,7 @@ def spaced( ) -Spiral.spaced = validate_call(Spiral.spaced) +Spiral.spaced = validate_call(Spiral.spaced) # type:ignore @dataclass(config=StrictConfig)