11 个版本

0.2.7 2021 年 7 月 13 日
0.2.6 2021 年 7 月 12 日
0.2.5 2021 年 6 月 25 日
0.2.4 2021 年 4 月 30 日
0.1.0 2020 年 6 月 22 日

#250Cargo 插件


weld-bin 中使用

MIT 许可证

85KB
510

工作室:crate cargo_atelier

A cargo 命令,用于将 Smithy 模型作为构建过程的一部分使用。

crates.io docs.rs

用法

> cargo atelier --help
cargo-atelier 0.2.2
Tools for the Smithy IDL.

USAGE:
    cargo-atelier [FLAGS] <SUBCOMMAND>

FLAGS:
    -h, --help        Prints help information
    -n, --no-color    Turn off color in the output
    -V, --version     Prints version information
    -v, --verbose     The level of logging to perform; from off to trace

SUBCOMMANDS:
    convert     Convert model from one representation to another
    document    Create human-readable documentation from a model
    help        Prints this message or the help of the given subcommand(s)
    lint        Run standard linter rules on a model file
    validate    Run standard validators on a model file

lint 和 validate 命令都使用相同的机制来打印结果,并且默认使用彩色输出。由于可以使用不同的代码检查和验证规则,"报告的" 行会告知您哪个规则集确定了错误。

document 命令从模型创建文档,依赖于特定的特征来处理文本,以及依赖预定义特征来处理某些语义属性。它使用了 somedoc crate 来进行格式化,因此该工具指定的输出格式可以选择 somedoc 支持的任何格式。

示例 Lint

对于以下格式错误的 Smithy 文件,在 test-models/lint-test.smithy

namespace org.example.smithy

@ThisIsNotAGoodName
structure thisIsMyStructure {
    lower: String,
    Upper: String,
    someJSONThing: someUnknownShape,
    OK: Boolean
}

string someUnknownShape

@trait
structure ThisIsNotAGoodName {}

代码检查运行时将输出以下问题。

> cargo atelier lint -i test-models/lint-test.smithy

[info] Shape names should conform to UpperCamelCase, i.e. ThisIsMyStructure
	Reported by NamingConventions on/for element `thisIsMyStructure`.

[info] Trait names should conform to lowerCamelCase, i.e. thisIsNotAGoodName
	Reported by NamingConventions on/for element `ThisIsNotAGoodName`.

[info] Member names should conform to lowerCamelCase, i.e. ok
	Reported by NamingConventions on/for element `thisIsMyStructure$OK`.

[info] Member name 'OK' appears to contain a known acronym, consider renaming i.e. ok
	Reported by NamingConventions on/for element `thisIsMyStructure`.

[info] Member names should conform to lowerCamelCase, i.e. someJsonThing
	Reported by NamingConventions on/for element `thisIsMyStructure$someJSONThing`.

[info] Member name 'someJSONThing' appears to contain a known acronym, consider renaming i.e. Json
	Reported by NamingConventions on/for element `thisIsMyStructure`.

[info] Shape names should conform to UpperCamelCase, i.e. SomeUnknownShape
	Reported by NamingConventions on/for element `someUnknownShape`.

[info] Member names should conform to lowerCamelCase, i.e. upper
	Reported by NamingConventions on/for element `thisIsMyStructure$Upper`.

示例 Validate

对于以下错误的 Smithy 文件,在 test-models/validation-test.smithy

namespace org.example.smithy

structure MyStructure {
    known: String,
    wrongType: SomeOperation,
}

operation SomeOperation {
    input: SomeService
}

service SomeService {
    version: "1.0",
    operations: [MyStructure]
}

验证运行时将输出以下问题。

> cargo atelier validate -i test-models/validation-test.smithy

[error] Structure member may not refer to a service, operation, resource or apply.
	Reported by CorrectTypeReferences on/for element `MyStructure$wrongType`.

[warning] Structure member's type (smithy.api#NotString) cannot be resolved to a shape in this model.
	Reported by CorrectTypeReferences on/for element `MyStructure$unknown`.

[error] Service operation must be an operation.
	Reported by CorrectTypeReferences on/for element `SomeService`.

[error] Operation input may not refer to a service, operation, resource or apply.
	Reported by CorrectTypeReferences on/for element `SomeOperation`.

示例 Documentation

> cargo atelier document -i test-models/lint-test.smithy -w xwiki
{{comment}}
title: Smithy Model
{{/comment}}


Smith Version: 1.0

= Namespace org.example.smithy =

(% id="shape:ThisIsNotAGoodName" %) == ThisIsNotAGoodName (structure) ==

|=Trait|=Value|
|Is Trait|##true##|


(% id="shape:someUnknownShape" %) == someUnknownShape (string) ==

(% id="shape:thisIsMyStructure" %) == thisIsMyStructure (structure) ==

=== Members ===

* ##Upper##: ##smithy.api#String##
* ##lower##: ##smithy.api#String##
* ##OK##: ##smithy.api#Boolean##
* ##someJSONThing##: [[someUnknownShape>>.||anchor=shape:someUnknownShape]]

参数

任何命令都可能包含的通用参数。

  • -V--version;打印版本信息(并退出)。
  • -h--help;打印帮助信息(并退出)。
  • -v, --verbose;开启更多日志,添加参数的次数越多,日志越多。
  • --no-color;关闭颜色支持。

以下参数适用于所有文件输入。文件输入使用 atelier_assembler 包来读取多个文件并支持多种文件表示。默认情况下,模型汇编器不使用搜索路径来加载文件。但是,可以通过 -d 标志来更改这一点,该标志将在环境变量 $SMITHY_PATH 中找到的任何文件进行加载。或者,-s 参数提供了替代 $SMITHY_PATH 使用的环境变量名称。

  • -d, --default-search-env;如果设置,则将标准环境变量 SMITHY_PATH 用作搜索路径。
  • -, --in-file <in-file>;要读取的文件名,可以指定多个文件。
  • -, --search-env <search-env>;用作搜索路径的环境变量名称。

以下参数适用于所有文件输出。

  • -, --namespace <namespace>;需要时写入的命名空间。
  • -, --out-file <out-file>;要写入的文件名或标准输出。
  • -, --write-format <write-format>;输出文件的表示形式,默认值取决于命令。

变更

版本 0.2.7

  • 添加了在 cargo 下运行时正确的参数检查。

版本 0.2.6

  • 添加了 'default_search_env' 和 'search_env' 参数来控制模型汇编器。

版本 0.2.5

  • 实现了使用模型汇编器通过多个命名空间文件构建的模型来运行 cargo-atelier 的 lint 和 validate。
    • 更新了所有命令,以接受文件路径列表作为输入,汇编器将确定文件类型。
    • 更新了错误报告。

版本 0.2.4

  • 更改到 lib API。

版本 0.2.3

  • 修复:升级了 somedoc 依赖项版本。

版本 0.2.2

  • 为文档编写器添加了新命令;此命令采用 somedoc::write::OutputFormat 来选择格式。

版本 0.2.1

  • 根据新的核心特质 HasIdentityHasTraits 进行了变更。
  • 添加了文档编写器。

版本 0.1.3

  • 支持彩色输出。
  • 添加了 lint/validate 测试的示例文件。
  • 在此处添加了示例。

版本 0.1.2

  • 更新了库依赖项以获取最新的 Smithy 读取器。

版本 0.1.1

  • 检查器和验证器命令正常工作
  • 从 json/smithy 转换为 json/smithy/uml

版本 0.1.0

  • 占位符发布。

TODO

  1. 验证器。
  2. 代码生成器。

依赖关系

~8–21MB
~258K SLoC