feat: Add option to plugin doc command to output tables as JSON#347
feat: Add option to plugin doc command to output tables as JSON#347kodiakhq[bot] merged 10 commits intomainfrom
Conversation
yevgenypats
left a comment
There was a problem hiding this comment.
Sorry for the delayed review, forgot about it. It looks good. One nit and one question.
plugins/source_docs.go
Outdated
| return string(s) | ||
| } | ||
|
|
||
| func (s SourceDocsFormat) Validate() error { |
There was a problem hiding this comment.
I think this can be just an enum (https://github.com/cloudquery/plugin-sdk/blob/main/serve/source.go#L67) which already include the validation.
There was a problem hiding this comment.
Good point, but I think the enum code is private to the serve package so I'll have to refactor a bit first.
| } | ||
| } | ||
|
|
||
| type jsonTable struct { |
There was a problem hiding this comment.
I think this is fine but can't we re-use the same tables definition that we already have? we also encode them to json or we want a different structure.
There was a problem hiding this comment.
I tried this initially, and if I recall correctly the issue I faced was that column type came out as an integer, which isn't very useful without the mappings. So I figured that it would be good to decouple the GRPC representation from the one we use here, but I could be convinced that we shouldn't do that, and figure out a way to turn the type to a string here instead?
There was a problem hiding this comment.
Yeah I don't have a good idea right now so maybe we can merge this as is and maybe fix later on if it becomes a maintains burden. But actually now that I think about it why the gRPC representation is not good ? especially if it's intended to be read by computers? Maybe we can have some flag that will marshal the Type in a different way.
There was a problem hiding this comment.
I think one use case for this is going to be outputting the schema in a different format than the markdown we support. Maybe a different markdown format, maybe HTML? But having a number for the type is not very useful then, you'd either need access to the plugin-sdk or copy-paste the list of constants to know how it maps to a string. I also think it's probably good if we can evolve the internal representations separately. We may even move away from JSON for internal communication purposes if it turns out to be a drag on performance, but we'd still want to keep this.
|
@hermanschaaf I think we can do just the enum and we can merge it/roll this out so user can use it. |
|
@yevgenypats Updated to use enums, PTAL |
| "is_primary_key": true | ||
| } | ||
| ], | ||
| "relations": [ |
There was a problem hiding this comment.
Sorry for jumping late to this, but can we also have the relations at the top level? Might be easier to process it that way. For example if I was to get a list of all tables, I'll need to recurse into the JSON at the moment.
We can add a another property parent to link to the parent table, and keep it nil for top level ones, WDYT?
There was a problem hiding this comment.
Yeah, I was in two minds about it 🤔 I think having it flattened will be good for some use cases, and not-so-good for others. I'm fine with changing it to flattened though. @yevgenypats WDYT?
🤖 I have created a release *beep* *boop* --- ## [1.6.0](v1.5.3...v1.6.0) (2022-11-21) ### Features * Add option to plugin doc command to output tables as JSON ([#347](#347)) ([c1b4240](c1b4240)) * Support ${file:./path} expansion in spec ([#418](#418)) ([58d7c44](58d7c44)) ### Bug Fixes * Fix Destination testing suite ([#417](#417)) ([4771efa](4771efa)) * Increase GRPC message size limit to 50MiB ([#419](#419)) ([a54c6ea](a54c6ea)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).

Fixes #309
This adds a
--format jsonoption to the source plugindoccommand, which allows all tables to be dumped as a single JSON file. This can then be further parsed withjqfor various purposes (such as comparing two versions of a plugin to see what changed).Example: List first 5 top-level tables of AWS plugin