This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-05-15
Channels
- # aws (4)
- # beginners (98)
- # boot (23)
- # cider (63)
- # cljsrn (3)
- # clojure (259)
- # clojure-boston (1)
- # clojure-dev (2)
- # clojure-italy (6)
- # clojure-nl (17)
- # clojure-russia (1)
- # clojure-serbia (1)
- # clojure-spec (36)
- # clojure-uk (74)
- # clojurescript (11)
- # cursive (2)
- # datascript (12)
- # datomic (36)
- # defnpodcast (1)
- # devops (1)
- # docs (1)
- # emacs (15)
- # euroclojure (3)
- # fulcro (13)
- # graphql (1)
- # juxt (2)
- # lumo (27)
- # off-topic (46)
- # onyx (23)
- # pedestal (6)
- # planck (2)
- # portkey (27)
- # re-frame (18)
- # reagent (12)
- # remote-jobs (2)
- # ring-swagger (11)
- # rum (4)
- # shadow-cljs (104)
- # spacemacs (4)
- # sql (3)
- # tools-deps (5)
- # vim (45)
so mostly just curious if there are ways to spec collections of things, but spec them in terms of the collection, not in terms of the individual items in the collection (so whether or not only certain fields for the items are unique, or that summing fields for all items is within a certain range, etc)
so I'm trying to do some work where I validate a JSON blob against a swagger spec. I'm thinking about trying to translate the swagger spec into clojure.spec and do it that way
however, it seems like there's an assumption that clojure.spec's are registered globally with a name and everything. I would be generating these specs dynamically, on the fly
so if you have a function that given a swagger spec and some data returns true or false, then you just partial that with the swagger spec and you have a spec
it isn't a very nice spec, it won't generate and you won't get vary granular error messages, but it is a spec
okay. I was thinking of trying to use clojure.spec to do some of the heavy lifting around e.g. checking whether a map conforms to a set of expected values
so like
x-allOf: [
{
type: "object",
properties: {
personId: {
type: "integer",
format: "int64"
},
familyMemberId: {
type: "integer",
format: "int64"
}
},
required: [
"personId",
"familyMemberId"
]
},
gets turned into (s/def ::personId integer?)
(s/def ::familyMemberId integer?)
(s/def ::my-obj (s/keys :req-un [::personId ::familyMemberId]))
but obvi this is made more difficult by the fact that this would need to be done for arbitrary number of swagger specs at runtime, so I would have to make sure I'm not clobbering things in the registry...
I’m probably using the wrong definition of dynamic, but i thought you would know what sort of data you would be getting? so you could potentially spec out the shape of the data?
I'm writing some code that you give it a URL to a swagger.json, a URL path, example request and an example response
and it validates that the URL path, request and response are valid based on the swagger.json
i guess you could test it by creating multiple unique specs and seeing how many you could create
@lilactown Would it be easier/better to have something that generated spec source code from a swagger URL? After all, you only want to generate the spec once per API end point, but you'll want to validate data against that spec repeatedly...
it seems like it would be a better idea to use some swagger validator to validate the swagger, for a swagger validation service
I think the direction you see in spec-utils (spec -> swagger) makes sense because the idea is, you can consolidate different ways of specifying data (database schemas, swagger, json schema, etc) as spec specs, and then generate (or using spec to make sure you data matches the contract) those other things from spec as needed. But it doesn't seem like turning swagger in to specs, if all you care about is validating arbitrary swagger specs against arbitrary data, makes a lot of sense
yeah I guess I'm looking for a swagger validator, and I decided to try and build my own using clojure.spec? and that sounds like it's not a good idea
I'm actually struggling to find such a thing that exists, which is why I'm trying to build one in the first place
ah well thats a different matter, if ur doing it for work, i might try and find a different solution
googling java swagger validator and jvm swagger validator both seem to turn up good leads
Here's one implementation: https://github.com/metosin/ring-swagger/blob/master/src/ring/swagger/validator.clj
@U055NJ5CC scjsv is exactly what i'm looking for! 😄 thanks!