clojure-uk

A place for people in the UK, near the UK, visiting the UK, planning to visit the UK or just vaguely interested to randomly chat about things (often vi and emacs, occasionally clojure). More general the #ldnclj
dharrigan 2021-01-29T06:09:36.066Z

Buongiorno!

1
djm 2021-01-29T07:08:11.066300Z

๐Ÿ‘‹

2021-01-29T08:04:38.066500Z

Bunฤƒ dimineaลฃa!

thomas 2021-01-29T08:19:30.066800Z

moin moin

dharrigan 2021-01-29T08:52:14.067700Z

Yesterday, I spent a lot of my time in Kotlin, fighting with Jackson to ensure that the data I'm reading from an external API fits into the statically defined model...

dharrigan 2021-01-29T08:52:18.067900Z

Give me strength!

dharrigan 2021-01-29T08:52:35.068300Z

I did the same in Clojure, and it was trivially easy to map...

dharrigan 2021-01-29T08:53:24.068900Z

Got it working in the end, but I think I have mild trauma from it

djm 2021-01-29T08:54:12.069600Z

Raise a feature request with JetBrains for ctrl-alt-shift-k to do Clojure -> Kotlin, as well as Java -> Kotlin

djm 2021-01-29T08:54:22.069900Z

I'm sure they'll get right on it ๐Ÿ˜

dharrigan 2021-01-29T08:54:58.070500Z

My data model in Kotlin (this isn't a fault of Kotlin per-se!) is littered with`@Json*` annotations...

dharrigan 2021-01-29T08:55:51.071200Z

It doesn't help that the external party's API, obviously done using C# is PascalCase for the field names

dharrigan 2021-01-29T08:56:12.071400Z

rant rant rant

alexlynham 2021-01-29T09:15:30.071500Z

morning

2021-01-29T09:25:32.071700Z

Morn'

jonpither 2021-01-29T09:32:11.073400Z

morning

2021-01-29T10:37:27.074900Z

PascalCase :face_vomiting: โ€ฆ I feel your pain. Forcing crappy JSON to map onto classes correctly in a statically typed language is the hardest problem in computer scient.

๐Ÿ’ฏ 1
alexlynham 2021-01-29T10:38:38.075100Z

also if you work in a microservice style and a different team has a json api with streetAddress but your team is using street_address lolol

alexlynham 2021-02-01T14:25:18.108Z

Yep sadly

2021-01-29T10:38:48.075300Z

I up you with Proto/Flat Buffers

dharrigan 2021-01-29T10:39:23.075600Z

Man

dharrigan 2021-01-29T10:39:32.075800Z

Don't talk to me about Protobuffers

Conor 2021-01-29T10:42:09.075900Z

It's like a normal buffer but more protozoan

dharrigan 2021-01-29T10:46:07.076300Z

We use protobuffers at work and are in the loooong process of ripping them out

dharrigan 2021-01-29T10:46:21.076500Z

Vital systems, so has to be done carefully

danielneal 2021-01-29T10:47:11.076800Z

Does anyone have an opinion on malli vs spec?

2021-01-29T10:47:29.077400Z

isn't there a library for this, camel_Snake-kebab or something?

danielneal 2021-01-29T10:47:30.077600Z

I've joined a new codebase and there's spec, plumatic schema and malli

danielneal 2021-01-29T10:47:37.077900Z

so I think we should settle on one

alexlynham 2021-01-29T10:47:46.078300Z

in clj yes

dharrigan 2021-01-29T10:47:55.078700Z

I use malli a lot. I use reitit to service a RESTful API and malli is soooooooo good.

2021-01-29T10:47:58.078900Z

I imagine the plan is to settle on spec once it's out of alpha...

alexlynham 2021-01-29T10:48:00.079Z

not sure about other langs

alexlynham 2021-01-29T10:48:09.079400Z

does rely on consistency though >_>

dharrigan 2021-01-29T10:48:19.079800Z

There's a lot of work going on in #malli right now, lots of exciting stuff.

2021-01-29T10:48:25.079900Z

ah, so no use in the real world then!

alexlynham 2021-01-29T10:48:44.080500Z

somebody sell me malli, i've had a lot of success with plumatic/schema in the past

dharrigan 2021-01-29T10:48:56.080900Z

I have used spec as well, but <shrug> malli feels a lot easier to me.

dharrigan 2021-01-29T10:49:25.081200Z

I think the github page lists it's benefits: <https://github.com/metosin/malli>,

dharrigan 2021-01-29T10:49:43.081700Z

for example, with malli and reitit I was able, without hardly any work, to expose a Swagger endpoint.

2021-01-29T10:50:04.081900Z

is swagger useful?

dharrigan 2021-01-29T10:50:20.082300Z

Meh, there's a push for it at work.

dharrigan 2021-01-29T10:50:27.082600Z

I'm so-so about it.

2021-01-29T10:50:39.083100Z

it seems clever but I've never seen the benefit (I can well believe that there is one though)

dharrigan 2021-01-29T10:50:52.083400Z

But, having it done for me is nice, I don't have to spend a lot of cycles working with it,

๐Ÿ‘ 1
danielneal 2021-01-29T10:51:44.084700Z

I'm being pushed to make swagger work too, but it makes more sense for us because we have outsourced the UI and mobile app

2021-01-29T10:51:46.085Z

At one point I was going to add it because yada apparently made it easy - but there never seemed enough reason to actually do it.

danielneal 2021-01-29T10:51:58.085300Z

so we need something to document our api

๐Ÿ‘ 1
danielneal 2021-01-29T10:52:15.086Z

but having tried to read through the 15,000 word openapi3 spec yesterday my brain is mush

dharrigan 2021-01-29T10:52:22.086300Z

I would like to see something borrowed from the Spring world, aka Spring RestDocs

dharrigan 2021-01-29T10:52:35.086600Z

by running tests against your exposed APIs, it autogenerates documentation

danielneal 2021-01-29T10:52:43.086800Z

wow that's clever

dharrigan 2021-01-29T10:53:02.087Z

Here's an example <https://toyota.test.txconnected.com/>

dharrigan 2021-01-29T10:53:20.087400Z

that I did, all generated by running unit tests against the exposed API endpoints

dharrigan 2021-01-29T10:53:41.087800Z

those snippets of code are real actual test results

danielneal 2021-01-29T10:54:15.088100Z

how is the rest of the document constructed?

danielneal 2021-01-29T10:54:33.088700Z

it looks really good

dharrigan 2021-01-29T10:54:36.088800Z

you have a base template and hooks that the unit tests spit their snippets out into

dharrigan 2021-01-29T10:54:48.089300Z

then asciidoc runs over it and spits out html (or a pdf of whatever)

danielneal 2021-01-29T10:55:23.090500Z

yeah I was hoping we could somehow kill two birds with one stone with tests and documentation

dharrigan 2021-01-29T10:55:23.090700Z

i.e.,

dharrigan 2021-01-29T10:55:26.090900Z

===== Example 1 (Successful BASIC Authentication)

====== Request Headers

include::{snippets}/authentication-basic/request-headers.adoc[]

====== Example HTTPie Request

include::{snippets}/authentication-basic/httpie-request.adoc[]

2021-01-29T10:55:32.091300Z

something like swagger makes sense when you generate code/validators/types from the spec, as well as documentation. I've used it a couple of times as just the docs part, and it makes no sense to me

dharrigan 2021-01-29T10:55:49.091800Z

Spring RestDocs generates the request-headers.adoc, httpie-request.adoc etc...

dharrigan 2021-01-29T10:56:52.092400Z

I would lurve to see something like that in Clojure Land ๐Ÿ™‚

alexlynham 2021-01-29T10:57:40.092500Z

swagger is good

alexlynham 2021-01-29T10:57:47.092600Z

i see it as docs for free

danielneal 2021-01-29T10:58:08.093100Z

this looks really great, how do these annotations work @dharrigan ? Is that an asciidoc thing?

alexlynham 2021-01-29T10:58:15.093500Z

and right now in a project where we have to field a bunch of questions about what is what and where and why, i'm just like 'ugh, this should be automated'

dharrigan 2021-01-29T10:58:15.093600Z

yes

alexlynham 2021-01-29T10:58:25.093700Z

that said if i had to write swagger by hand, i'd nope out

dharrigan 2021-01-29T10:58:55.093900Z

.JSON Error Response Format
{
    "code": "errorCode", &lt;1&gt;
    "errors": {
      "request": [ &lt;2&gt;
          "Sorry, incorrect data [foo] supplied for [field]. Reason [bar]." &lt;3&gt;
      ]
    }
    "message": "Sorry, there has been a validation problem with the supplied data. Please report the reference code to Support.",
    "reference": "referenceCode" &lt;4&gt;
}
&lt;1&gt; For example `E13000`.
&lt;2&gt; For example `eligibilityCheckRequest`.
&lt;3&gt; For example `Sorry, incorrect data [123456789012345678] supplied for field [vin]. Reason [size must be between 0 and 17]."`
&lt;4&gt; For example `4f35fc4f
`

dharrigan 2021-01-29T10:59:16.094200Z

the <1> etc...

danielneal 2021-01-29T10:59:36.094600Z

I see nice. And ascii doc does the structure / index too? (I've not used it before)

dharrigan 2021-01-29T10:59:40.094800Z

Yup

dharrigan 2021-01-29T10:59:42.095Z

does all that

danielneal 2021-01-29T10:59:50.095200Z

Very cool

dharrigan 2021-01-29T11:00:06.095400Z

<https://asciidoc.org/userguide.html#X105>

dharrigan 2021-01-29T11:00:24.095700Z

and this <https://asciidoc.org/userguide.html#X28> for admonitions

dharrigan 2021-01-29T11:00:27.095900Z

I do like me Asciidoc

dharrigan 2021-01-29T11:01:05.096200Z

This one is a bit prettier <https://asciidoctor.org/docs/asciidoc-writers-guide/>

danielneal 2021-01-29T11:01:59.096900Z

So you write the overall template by hand and include references to files that are spit out by the unit tests. So each time you add a new unit test, you add a bit on to your main template, too?

dharrigan 2021-01-29T11:02:38.097200Z

yes

danielneal 2021-01-29T11:05:49.097700Z

I really really like the idea of combining tests and documentation

โž• 1
dharrigan 2021-01-29T11:06:21.098Z

:yes:

danielneal 2021-01-29T11:06:48.098600Z

I used hydrox before, http://helpshift.github.io/hydrox/ but I think zcaudate left the clojure community in storm and fire

2021-01-29T11:08:10.098800Z

unless everyone on the project retires before it happens

danielneal 2021-01-29T11:10:14.099100Z

but that's for clojure tests

danielneal 2021-01-29T11:10:26.099400Z

I wonder how much work it would be to do something like spring restdocs

mccraigmccraig 2021-01-29T11:33:48.099700Z

apart from the other problem of cache invalidation and off-by-one errors

mccraigmccraig 2021-01-29T11:37:08.101100Z

malli gives you jsonschema in your swagger doesn't it @dharrigan? or am i having a false memory? lack of jsonschema (for complex content) was always a shortcoming with the swagger autogenerated from yada schema annotations

dharrigan 2021-01-29T11:51:34.101600Z

You can generate json schema from malli, aka <https://github.com/metosin/malli#json-schema>

dharrigan 2021-01-29T11:51:48.101900Z

but I don't see it on the swagger ui when I've fired up my service

danielneal 2021-01-29T12:49:34.102300Z

openapi3 is both a superset and a subset of json schema (apparently)

Conor 2021-01-29T12:52:42.102500Z

If x is a superset and subset of y, doesn't that mean x = y :thinking_face:

๐Ÿ˜„ 1
danielneal 2021-01-29T12:54:43.102800Z

haha maybe I don't mean superset and subset

danielneal 2021-01-29T12:55:08.103300Z

how do you call it when there are properties in openapi3 that are not in json schema, and properties in json schema that are not in openapi3

Conor 2021-01-29T12:56:12.103500Z

I guess they intersect to some degree!

2021-01-29T16:38:20.103600Z

I guess you could do that pretty easily with martian and an interceptor: https://github.com/oliyh/martian cc @danieleneal

2021-01-29T16:44:42.103900Z

Whatโ€™s the advantage of using tests over swagger? Keeping you honest?

danielneal 2021-01-29T16:57:56.104100Z

haha, something like that