encoding/openapi: simplify based on user-defined format
For instance, don't use minimum and maximum for
int32 boundaries if the user indicated the field is an
int32.
Also move to apd instead of ints.
Issue #56
Change-Id: I472c3c2b1fd8622430595bd062cef3bbd53b62f1
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/2376
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
diff --git a/encoding/openapi/testdata/array.cue b/encoding/openapi/testdata/array.cue
new file mode 100644
index 0000000..3261f81
--- /dev/null
+++ b/encoding/openapi/testdata/array.cue
@@ -0,0 +1,19 @@
+Arrays: {
+ bar?: [...MyEnum]
+ foo?: [...MyStruct]
+}
+
+Arrays: {
+ bar?: [...MyEnum]
+ foo?: [...MyStruct]
+}
+
+// MyStruct
+MyStruct: {
+ a?: int
+ e?: [...MyEnum]
+ e?: [...MyEnum]
+}
+
+// MyEnum
+MyEnum: *"1" | "2" | "3"
diff --git a/encoding/openapi/testdata/array.json b/encoding/openapi/testdata/array.json
new file mode 100644
index 0000000..4b29400
--- /dev/null
+++ b/encoding/openapi/testdata/array.json
@@ -0,0 +1,74 @@
+{
+ "openapi": "3.0.0",
+ "components": {
+ "schema": {
+ "Arrays": {
+ "type": "object",
+ "properties": {
+ "bar": {
+ "type": "array",
+ "items": {
+ "enum": [
+ "1",
+ "2",
+ "3"
+ ],
+ "default": "1"
+ }
+ },
+ "foo": {
+ "type": "array",
+ "items": {
+ "type": "object",
+ "properties": {
+ "a": {
+ "type": "integer"
+ },
+ "e": {
+ "type": "array",
+ "items": {
+ "enum": [
+ "1",
+ "2",
+ "3"
+ ],
+ "default": "1"
+ }
+ }
+ }
+ }
+ }
+ }
+ },
+ "MyEnum": {
+ "description": "MyEnum",
+ "enum": [
+ "1",
+ "2",
+ "3"
+ ],
+ "default": "1"
+ },
+ "MyStruct": {
+ "description": "MyStruct",
+ "type": "object",
+ "properties": {
+ "a": {
+ "type": "integer"
+ },
+ "e": {
+ "type": "array",
+ "items": {
+ "enum": [
+ "1",
+ "2",
+ "3"
+ ],
+ "default": "1"
+ }
+ }
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/encoding/openapi/testdata/oneof.json b/encoding/openapi/testdata/oneof.json
index c526b28..ce39ad4 100644
--- a/encoding/openapi/testdata/oneof.json
+++ b/encoding/openapi/testdata/oneof.json
@@ -11,7 +11,8 @@
],
"properties": {
"exact": {
- "type": "string"
+ "type": "string",
+ "format": "string"
}
}
},
@@ -22,7 +23,8 @@
],
"properties": {
"regex": {
- "type": "string"
+ "type": "string",
+ "format": "string"
}
}
}
diff --git a/encoding/openapi/testdata/openapi-norefs.json b/encoding/openapi/testdata/openapi-norefs.json
index 0094bd8..00803cd 100644
--- a/encoding/openapi/testdata/openapi-norefs.json
+++ b/encoding/openapi/testdata/openapi-norefs.json
@@ -15,7 +15,8 @@
"bar": {
"type": "array",
"items": {
- "type": "string"
+ "type": "string",
+ "format": "string"
}
},
"foo": {
@@ -68,7 +69,8 @@
],
"properties": {
"b": {
- "type": "string"
+ "type": "string",
+ "format": "string"
}
}
}
@@ -96,8 +98,7 @@
},
"Int32": {
"type": "integer",
- "minimum": -2147483648,
- "maximum": 2147483647
+ "format": "int32"
},
"YourMessage": {
"oneOf": [
@@ -108,10 +109,12 @@
],
"properties": {
"a": {
- "type": "string"
+ "type": "string",
+ "format": "string"
},
"b": {
- "type": "string"
+ "type": "string",
+ "format": "string"
}
}
},
@@ -122,7 +125,8 @@
],
"properties": {
"a": {
- "type": "string"
+ "type": "string",
+ "format": "string"
},
"b": {
"type": "number"
@@ -233,7 +237,8 @@
],
"properties": {
"a": {
- "type": "string"
+ "type": "string",
+ "format": "string"
}
}
}
diff --git a/encoding/openapi/testdata/openapi.json b/encoding/openapi/testdata/openapi.json
index 7409a75..c0ef7db 100644
--- a/encoding/openapi/testdata/openapi.json
+++ b/encoding/openapi/testdata/openapi.json
@@ -15,7 +15,8 @@
"bar": {
"type": "array",
"items": {
- "type": "string"
+ "type": "string",
+ "format": "string"
}
},
"foo": {
@@ -61,7 +62,8 @@
],
"properties": {
"b": {
- "type": "string"
+ "type": "string",
+ "format": "string"
}
}
}
@@ -89,8 +91,7 @@
},
"Int32": {
"type": "integer",
- "minimum": -2147483648,
- "maximum": 2147483647
+ "format": "int32"
},
"YourMessage": {
"oneOf": [
@@ -101,10 +102,12 @@
],
"properties": {
"a": {
- "type": "string"
+ "type": "string",
+ "format": "string"
},
"b": {
- "type": "string"
+ "type": "string",
+ "format": "string"
}
}
},
@@ -115,7 +118,8 @@
],
"properties": {
"a": {
- "type": "string"
+ "type": "string",
+ "format": "string"
},
"b": {
"type": "number"
@@ -226,7 +230,8 @@
],
"properties": {
"a": {
- "type": "string"
+ "type": "string",
+ "format": "string"
}
}
}