Open vigoo opened 2 years ago
:+1: this was a conscious decision at the time to not support arbitrary types for additionalProperties
(see additionalProperties: true
), but you're bringing up a very valid use case, where the schema is actually well defined.
I think this could be fairly straightforward to add, at least in the case of a $ref
(but probably for literals as well) by adding a parameter additionalProperties: Map[String, A]
and doing some custom parsing in the encoders and decoders.
Is this something you'd be interested and available to add? I can help with guidance in the Matrix channel if you'd like, and I can cut a release as soon as the tests pass. The nice thing is we don't have to worry about backwards compatibility here, since this is entirely new.
Actually, I just saw that you're already doing some heavy lifting over there.
I'm curious about the level of customization that they needed that wasn't already available via the sbt plugin, but that's I guess out of the scope for this ticket. The module system in recent releases should give them full control to override absolutely every part of code generation with relatively little headache, so if there's some need there then I can help as well
I can look at adding support for this within the next two weeks, if that fits your timeline
It's very likely that zio-k8s-crd
s customization can be written in a better way. I wrote it about 1.5 years ago based on guardrail 0.64 (or older) and what I basically did is I copied the circe implementation and modified that. I'm currently not actively working on zio-k8s just looked into this bug report. So whenever you have time to implement the guardrail part I will try to update it there but don't really have time to do this as well :)
Also, I think in CRDs there are no $ref
s ever everything is "inlined" (not sure what the proper term is in OpenAPI context). There is always a single openAPIV3Schema
node in the definition which is an object
and there is no place to have additional top level named definitions.
The zio-k8s-crd
plugin extracts this node from the CRD yaml and uses guardrail to generate the model classes for it, and generates other K8s specific code outside of guardrail as well. The customizations in the copied circe-support files are roughly the following:
Option
it uses our own Optional
type (which is now in zio-prelude
)object
s contains a metadata
field which is sometimes optional sometimes not (...), and it generates an implicit K8sObject[T]
and K8sObjectOps
for these types which helps the K8s library work with them.object
s contain a top level status
field as well which is special and we need to generate some other implicits to work with themResourceMetadata
with information coming outside guardrails's scope (names from the CRD yaml)(This page describes how to do it by hand: https://coralogix.github.io/zio-k8s/docs/crd/crd_custom)
That makes a lot of sense, thanks for the explanation!
I wish there were a more pleasant workflow than copy paste, as I think you'll find there have been some significant changes (presence
and package structure being two, the SPI stuff being a third though you may not run into that if you depend on the Scala modules directly).
Once I've got a spare moment I'll see if I can get that additional properties stuff working.
From your perspective, is my proposal of an additional parameter with Map[String, A]
is sufficient? Also, the specification is correct that every extra parameter must match that schema otherwise the whole decode will fail?
Sorry for the delay on getting back to this, hopefully it hasn't caused too much trouble.
I've just opened a PR that at least satisfies the example spec from this issue, though with one caveat -- properties
cannot live alongside additionalProperties
at this time.
If that's required I can prioritize another pass, but if not then I've at least left enough context that it should be possible to make moves in that direction when things calm down a bit more for me, or if somebody is feeling this pain particularly significantly.
Is there any update about this or any chance to merge?
Unfortunately no, I've got a partial branch but I haven't had the time to finish it, I'm sorry to block the zio work.
The following example (taken from the schema of the CRD https://github.com/argoproj/argo-cd/blob/41f54aa556f3ffb3fa4cf93d784fb7d30c15041c/manifests/crds/appproject-crd.yaml):
generates this code:
in which
Status.JwtTokensByRole
is missing.