Hello,
I tried to use clojure.spec for validation and test data generation of
requests for API described according OpenAPI (https://www.openapis.org/).
My code reads an OpenAPI specification, then constructs description that
can be used with clojure.spec.
The idea was to validate a request map according to spec or generate
request structure that conform this spec.
I tried to generate regexp-like clojure.spec expressions that use tuples
where first item selects specification sub-tree.
For example:
(alt
path-1-key (tuple path-1 (alt method-1-1-key (tuple method-1-1 (cat
..params..))
method-1-2-key (tuple method-1-2 (cat
..params..))))
path-2-key (tuple path-2 (alt method-2-1-key (tuple method-2-1 (cat
..params..))
method-2-2-key (tuple method-2-2 (cat
..params..)))))
(cat is used for parameters so I can describe optional ones with `?`)
My experiment code is here
https://github.com/PetrGlad/oasiege/blob/master/src/oasiege/core.clj
The approach turned out to be cumbersome, since generated structure has
different structure than result I want.
It looks like clojure.spec's requirement for fully qualified spec names is
made in assumption that all specs will be hand-crafted.
My first idea was to generate top level spec for paths, then for methods
and so on. That would require qualified spec names that describe map keys.
But names from OpenAPI description are unqualified. So to generate map of
request parameters {:param-a val-a} I should somehow to work
around the need to have specs like :api-specs.generated.spec1.param-a that
should eventually produce [:param-a val-a] key-value pair
("spec1" name part would be generated for each loaded OpenAPI
specification). Also it is not clear what to do if I want non keyword map
keys.
So the question: is there a more straightforward way to work with
specifications that are known only at run time or this is out of intended
clojure.spec usage?
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.