Open mrclean-oa opened 2 years ago
This JSDoc issue resolves 2D arrays, yet it is still seems present, since CoordinateArray[][]
does not even render the coordinates
key when I use bracket notation.
If it helps for debugging I manually ran doctrine (using the one installed by express-jsdoc-swagger):
const doctrine = require('doctrine');
var ast = doctrine.parse(
`/**
* Index 0 is Longitude - The valid numbers for Longitude are between -180 and 180.
* Index 1 is Latitude - The valid numbers for Latitude are between -90 and 90.
* Index 2 is Altitude - The valid numbers for Altitude is a number greater than or equal to 0.
* @typedef {[integer, integer, integer]} CoordinateArray
*/
/**
* GeoJSON is a format for encoding a variety of geographic data structures using JavaScript Object Notation (JSON).
* @typedef {object} GeoJSON
* @property {string} type - enum:MultiLineString,Point,Position,MultiPoint,LineString,Polygon,MultiPolygon,GeometryCollection - the GeoJSON type
* @property {array<array<CoordinatesArray>>} coordinates - the coordinates to the location
*/`,
{ unwrap: true }
);
console.log(JSON.stringify(ast, null, 2));
And got this result:
{
"description": "Index 0 is Longitude - The valid numbers for Longitude are between -180 and 180.\nIndex 1 is Latitude - The valid numbers for Latitude are between -90 and 90.\nIndex 2 is Altitude - The valid numbers for Altitude is a number greater than or equal to 0.",
"tags": [
{
"title": "typedef",
"description": null,
"type": {
"type": "ArrayType",
"elements": [
{
"type": "NameExpression",
"name": "integer"
},
{
"type": "NameExpression",
"name": "integer"
},
{
"type": "NameExpression",
"name": "integer"
}
]
},
"name": "CoordinateArray"
},
{
"title": "typedef",
"description": null,
"type": {
"type": "NameExpression",
"name": "object"
},
"name": "GeoJSON"
},
{
"title": "property",
"description": "enum:MultiLineString,Point,Position,MultiPoint,LineString,Polygon,MultiPolygon,GeometryCollection - the GeoJSON type",
"type": {
"type": "NameExpression",
"name": "string"
},
"name": "type"
},
{
"title": "property",
"description": "the coordinates to the location",
"type": {
"type": "TypeApplication",
"expression": {
"type": "NameExpression",
"name": "array"
},
"applications": [
{
"type": "TypeApplication",
"expression": {
"type": "NameExpression",
"name": "array"
},
"applications": [
{
"type": "NameExpression",
"name": "CoordinatesArray"
}
]
}
]
},
"name": "coordinates"
}
]
}
I don't know how to judge the result, but would be happy to close this if it appears to be a doctrine
problem.
Describe the bug I am working with GeoJSON data and the data is represented as the following:
So I would like to type the endpoint accordingly using a
@typedef
, I'm especially excited about using express-oas-validator, so I'd really like to get this to work:When the
coordinates
property is{array<array<CoordinateArray>>}
it works great, but you'll notice I'm missing a dimension. I have two arrays for property, and the tuple for the three numbers, yet it drops one of the arrays, see the image:When I add one more dimension (required for GeoJSON), it breaks in a confusing way, see "broken" image:
It thinks it's an array of
string
s.I thought I might be defining the tuple incorrectly, because of the dropped array mentioned earlier, so I tried a work around:
But then it comes out as an object instead of an array... that's no good.
So I tried doing this:
Adding brackets to the
typedef
forCoordinateArray
, but it yields the same result as the "broken" screenshot.At this point, I believe this is a bug with express-jsdoc-swagger, or maybe I'm doing something wrong?
To Reproduce
Expected behavior I would expect to see this in Swagger UI:
Which would be equivalent to
[number, number, number][][]
. I'd love to definemin
andmax
values on the tuple but I'll settle for anything that unblocks me and would enable me to use the validation package y'all wrote.Screenshots When the
coordinates
property is{array<array<CoordinateArray>>}
it works great, see the image:When I add one more dimension (required for GeoJSON), it breaks in a confusing way:
Desktop (please complete the following information):
Additional context Nope, nothing that I can think of