smithy-lang/smithy

Feature request: SmithyBuildConfig -> Model utility

Opened this issue · 2 comments

There are a lot of tools that could be built on top of Smithy, which would use smithy-build.json as the source of information about a model.

Currently, in order to do so they would have to either:

  • shell out to the CLI (which is costly, including but not only because of having to start another JVM), or
  • duplicate some of its logic: this is what the LSP seems to be doing at the moment, just like smithy4s / smithy-playground (OSS projects I'm involved with), and some projects I'm involved in at work.

I think it would be beneficial for the ecosystem to have more out-of-the-box support for loading a build config into a model. Presumably, this would have to be part of smithy-build.

Are you looking for more than what's exposed in the SmithyBuildConfig class? If so, can you elaborate on what differences you're looking for?

yes, I looked at the class, and it's useful as a way of reading the build files, but one still has to implement the loading of such a build config into a model - that's the missing part (as far as I can tell).

so, in pseudocode:

Path file = ...;
SmithyBuildConfig bc = SmithyBuildConfig.load(file);

// we don't have this
Model model = Model.fromBuildConfig(bc).assemble().unwrap();
// alternative syntax
Model model = bc.load().assemble().unwrap();
// another one
Model model = SmithyBuildConfig.load(bc).assemble().unwrap()
// also, the methods currently are shown to return ModelAssembler, but maybe it makes sense to return a ValidatedResult<Model> instead.