Commit graph

18 commits

Author SHA1 Message Date
Lauri Ojansivu
a2911bc9c3 Fixed building OpenAPI docs.
Thanks to xet7 !

Fixes #5512
2025-03-15 19:32:16 +02:00
Benjamin Tissoires
73a170a388 openapi: fix breakage introduced with blank return
Introduced by commit f8ef2e33de ("cards.js Added a control to check
error if card is not updated"), a blank return was added at line 3914.

The generate_openapi script assumed a return statement always has an
argument, and this was crashing.

Fixes #5320
2024-02-22 16:31:11 +01:00
Benjamin Tissoires
d7243bba77 openapi: also ignores ThrowStatement
This gives an error in the resulting file, which makes it not OpenAPI
compatible (not yaml actually).

Fixes #4917

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2023-05-09 10:13:23 +02:00
Benjamin Tissoires
ebe39771a6 openapi: actually catch the error when esprima fails at parsing the file
39f8a138d7 added a try/except around esprima to catch any hard error
from the parsing, but the returned value was not checked.

We now have the file models/exportExcel.js which gives us an unexpected
symbol on line 3 (not sure why it is not happy), but that fails the
generation of the doc entirely.

Fixes #3884

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2021-07-01 10:23:29 +02:00
Benjamin Tissoires
ae30b1220a openapi: better handle nested schemas
there is a 2 levels schemas in profile.notifications.

The code previously assumed we could only have one level, and so was not
producing the correct UsersProfileNotifications.

Fix that by being more generic in the way we retrieve the nested
subschemas.
2021-04-27 10:44:27 +02:00
Benjamin Tissoires
39f8a138d7 openapi: rework the allowedValues to allow for imported variables
Previously I was assuming all variables were declared in the same file.
Turns out that imports exists too, and we need to recurse one more time
in those imports./

Also "clean" up a bit the function to do the parsing in 2 steps:
- first find out the actual matching node in js
- then convert it based on its type
rinse wash repeat.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2021-04-14 11:32:03 +02:00
Benjamin Tissoires
2c1f40357d Fix openapi docs generation
esprima-python is now safe to use
(https://github.com/Kronuz/esprima-python/pull/12)

And there was a new ArrowFunctionExpression used in db666eec65
that broke the python script
2021-03-26 18:41:34 +01:00
Lauri Ojansivu
0bb3b67075 Fixed generating API docs and Wekan Custom Fields REST API.
Thanks to xet7 !
2021-03-07 17:57:24 +02:00
Benjamin Tissoires
e1ffe943c8 openapi: also consider Object type as valid
Not sure if this will end up in a correct openapi file, but the docs
are correctly generated, so... meh.
2020-06-17 05:40:38 +02:00
Benjamin Tissoires
431d884e83 openapi: fix jsdoc/operation matching
The script was considering that the operation
associated to a jsdoc was declared on the line
just after the end of the jsdoc.

Turns out that adding new lines makes the code
clearer, but the python script was then ignoring
some jsdocs.

Change the behaviour to consider that the jsdoc
associated with an operation is the last one
declared after the end of the previous operation.

Fixes #3169
2020-06-17 05:15:39 +02:00
Benjamin Tissoires
3f059ec1e0 generate_openapi: fix enums when they are declared as const
Fixes: #2781
2019-11-05 12:58:06 +01:00
Benjamin Tissoires
8cb3974eff generate_openapi: print a more useful error
...when we can not parse a SchemaProperty
2019-11-05 12:54:58 +01:00
Benjamin Tissoires
7d62d0920c generate_openapi: add a little bit more verbosity when we get an Error 2019-11-05 12:01:04 +01:00
Benjamin Tissoires
b787854289 generate_openapi.py: use the logging module
Instead of dealing with custom writes to stderr, it's always better
to rely on standard libraries.
2019-11-05 11:06:40 +01:00
Benjamin Tissoires
1eea102f26 openAPI: also handle export statement in the scripts
The files are actually modules, not plain scripts, and thus we are allowed
to use `export`. Without `parseModule`, the script would silently fail
when parsing `export.js` and the export function will not be present.
2019-05-14 10:10:21 +02:00
Lauri Ojansivu
2969161afb - More whitelabeling.
Thanks to xet7 !
2019-03-21 20:27:21 +02:00
Benjamin Tissoires
8be7eec2ca openapi: make the code python 3.5 compatible
It is common to use Ubuntu 16.04 to build snaps. For example,
the official docker container to build snaps is using this old
distribution.

However, Ubuntu 16.04 ships Python 3.5.X which is not compatible
with the f-strings in generate_openapi.py. This is sad, because
we need to use the `.format()` syntax to make it compatible.
2019-01-18 17:03:12 +01:00
Benjamin Tissoires
49d3eb5a3f Add OpenAPI description of the REST API
The API is generated by a custom script that parses the models directory.
Once the API is generated, tools like https://editor.swagger.io/ or
Python bravado can parse the file and generate a language friendly API.

Note that the tool generate an OpenAPI 2.0 version because bravado
doesn't handle OpenAPI 3.0.

The script also parses the JSDoc with a custom parser to allow
customization of the description of the fields.
2019-01-18 17:01:11 +01:00