Replies: 3 comments 1 reply
-
There has been interest in building a JSON schema to Nickel contract converter, see also #418. There is a bit of a conceptual issue with |
Beta Was this translation helpful? Give feedback.
-
Thanks! That was a really interesting tour of the state of the art right now. I still wonder if there's work (or an avenue...) the other direction: can Nickel contracts be represented as OpenAPI schemata? The lack of unions makes it clear that OpenAPI is in some way more expressive that contracts are - is the reverse also true, or is OpenAPI a superset of contracts? Likewise, the conversion to predicate contracts seems like it wouldn't be onerous in this context, since the Kubernetes resources are going to have to be completely serialized to be useful anyway. Restricted (future) combinators for contracts would be really useful but they don't seem like a hard requirement for this application. Related, I'm thinking along these lines: what I'm looking for is for data to be able to flow between a tool that embeds Nickel and Kubernetes. In general that will mean that a document (a K8s Resource, usually) will need to be checked against both validations. Part of the problem space looks like this:
That would be the ideal - anything Nickel accepts, I can assume Kubernetes will likewise accept and vice versa. But depending on the use case, I might be willing to relax one of the ❌es - For instance, I might be happy to accept that most validation would fail in Nickel, but there's some cases that Nickel would accept but wouldn't One application I imagine is defining a custom resource in Nickel, and then emitting the corresponding CRD, in which case (and granted that Nickel->OpenAPI is possible) the above chart would be satisfied, right? The subset of OpenAPI used to represent the contracts would be all that would be used in such a process. |
Beta Was this translation helpful? Give feedback.
-
One wrinkle with Nickel->OpenAPI that strikes me is predicate contracts - does If so, is that even possible? Perhaps CEL is expressive enough to allow for general purpose Nickel contracts, but I wouldn't be surprised if it was a challenge. I'm not sure exactly how to express the idea, but are there, perhaps, subsets of each language as-expressible-in the other? I'm thinking of something like canonical JSON. Maybe a nickel2openapi tool enforces/parses not just Nickel but a well-defined Nickel-as-expressible-in-OpenAPI. (Likewise, an openapi2nickel tool with suitable replacements). The related issue would be: can any of the above be accomplished idiomatically? Contemplating any of this, I imagine one naive solution being to lean hard on CEL rather than trying to use more conventional features of JSONSchema, and while that would fit the bill, I can imagine Kubernetes operators rolling their eyes at "another Nickel-generated CRD." |
Beta Was this translation helpful? Give feedback.
-
A cursory review makes it seem that there's a reasonable overlap between the OpenAPI v3 Validation and CEL languages that Kubernetes uses to validate CRDs and Nickel contracts and types.
I wonder if it would be possible to write Nickel contracts and convert them into (parts of) a CRD or vice versa. In part, I'm coming from CUE's ability to import Go and JSONSchema files, and wondering if there's a sensible parallel in Nickel.
In order of decreasing preference and increasing expectation:
nickel-nix
.The last two bullets amount to "would it be worth the time to try to build such a tool?" An important consideration in that vein would be this: would anyone else have use for such a thing, and if so why doesn't it exist already?
Beta Was this translation helpful? Give feedback.
All reactions