-
Notifications
You must be signed in to change notification settings - Fork 169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
API documentation for Jsonnet libraries #223
Comments
Hi, FYI our fork of ksonnet-lib is available at https://github.com/kube-jsonnet/k. Keep in mind it's still alpha, some things might now work. Happy to receive feedback! Regarding docs, we have no proper solution at the moment. We ourselves have to frequently view the source code of libraries to figure out what's available, so it's one of our biggest priorities to get an adequate solution here. |
Do you have any thoughts on how you would want this to work? For example what structure such docs should have? Or how to describe objects in the documentation? It's interesting to us, because we hope to provide an upstream solution one day. FYI @sparkprime has a work-in-progress effort to extract information from the source code comments. I started investigating the other side of this - generating the HTML documentation using Jsonnet based on structured JSON input (I think the first target will be the stdlib documentation). |
I do have a very very ugly prototype (https://github.com/sh0rez/tkdoc), which is highly opinionated:
The overall idea is the following:
With such a clear entrypoint, it is in theory easy to generate the docs. BUT: The result of So I think we need to somehow get a representation of the evaluation result right before rendering to json. IE all object merges already done, references resolved. Is that possible @sbarzowski? |
That of course would be heavily opinionated for the use-case of Kubernetes but could get us to a starting point which we can build on later |
Yes, but it wouldn't necessarily be what you want. The result would be values (object, number, function), not AST nodes (object literal, function definition). So in particular it is stripped of any comments at this point. |
@sbarzowski that's a bummer, it won't help us then. As you know the language internals far better than me, what's your recommendation? Consider the following example: // foo.libsonnet
{
new():: { apiVersion: "v1", kind: "Service" },
spec:: {
// `withPorts` returns a patch to set `spec.ports` to `ports`
withPorts(ports):: { spec+: { ports: ports }}
}
}
// main.libsonnet
(import "foo.libsonnet") + {
// `new` returns a new instance of `Service`
new(name):: super.new() + { metadata+: { name: name }}
} I'd like to generate the following docs from it:
|
Well, to support something like that, we'll need static analysis which performs something like limited evaluation, but also keeps track of the comments and original source code locations. It will have a very limited set of operations (mostly + and locals I think). The most tricky part which may be needed is some support for It is not entirely out of question to extend the normal evaluation to carry more source information around, but this may be pretty complicated (unclear how to handle list comprehensions, function calls etc.) and may have negative performance implications. And it's way more invasive. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
I don't know how this documentation is generated, but it seems like it would make sense to generate docs similar to the jsonnet stdlib: https://jsonnet.org/ref/stdlib.html But maybe the better option is to move forward with using https://jsonnet-libs.github.io/k8s-alpha/1.18/ ? |
https://github.com/jsonnet-libs/docsonnet is now a thing and powers the docs of https://jsonnet-libs.github.io/k8s-alpha/. Closing this issue as the general problem is resolved. Improvements welcome :) |
This may be a bit premature but are there plans to come up with some sort of API documentation for the Jsonnet libraries, in particular the Kubernetes (ksonnet) library?
I find it really difficult to use without lots of string searching. IDE support would help but most plugins are limited. I just found http://g.bryan.dev.hepti.center/ which looks pretty cool. How do others manage to use it?
BTW thank you for planning to take over ksonnet-lib, this is awesome news.
The text was updated successfully, but these errors were encountered: