We use machine learning technology to do auto-translation. Click "English" on top navigation bar to check Chinese version.
Creating Smithy Projects with Smithy Init
The Smithy team is excited to announce the release of the init
command in
Before the Smithy init
command was introduced, developers had to carefully follow along with a developer guide or blog post to setup their Smithy projects. This involves copying and pasting code snippets, as well as creating various files and directories. With the introduction of the init
command, developers can use a single command to create a project with all the necessary Smithy files, configuration files, and directories, all tailored to their use case. The new init
command simplifies developer experience of getting started with Smithy, and it is less error-prone as it creates projects based on templates. The templates provided by the init
command cater to different project needs as well as to serve as great examples. Developers can use these templates to explore different project setups and learn about various Smithy features.
What is Smithy?
What is the Smithy CLI?
The
Getting Started
If you haven’t installed the Smithy CLI before, follow the
smithy --version
in a terminal to verify that the version is 1.36.0
or above. If Homebrew was used to install the Smithy CLI, you can update it to the latest version by running brew upgrade smithy-cli
in a terminal. Otherwise, please refer to the
With the Smithy CLI installed, you can view the help information for the init
command by using the --help
flag:
$ smithy init --help
Usage: smithy init [--help | -h] [--debug]
[--quiet] [--no-color]
[--force-color] [--stacktrace]
[--logging LOG_LEVEL]
[--template | -t quickstart-cli]
[--url https://github.com/smithy-lang/smithy-examples.git]
[--output | -o new-smithy-project]
[--list | -l]
Initialize a smithy project using a template
Next, we will demonstrate how the init
command can be used to create a new Smithy project.
Create a new Smithy project
Let’s create a new project by calling the init
command:
$ smithy init --output ./new-smithy-project
Smithy project created in directory: new-smithy-project
This will create a new project in the new-smithy-project
directory:
$ tree ./new-smithy-project
./new-smithy-project
├── README.md
├── models
│ └── weather.smithy
└── smithy-build.json
By default, the init
command line tool will create a new project using the quickstart-cli
template. In the following section, we will view the available templates and how to access them.
Utilizing project templates
The init
command offers a selection of project templates catering to different needs. Each template has its own
To view the available templates and their respective use cases, you can run the init
command with the --list
flag:
$ smithy init --list
──────────────────────────── ──────────────────────────────────────────────────────────────────────
NAME DOCUMENTATION
──────────────────────────── ──────────────────────────────────────────────────────────────────────
common-linting-configuration Gradle project to create a package to define a common set of model
validations.
custom-annotation-trait Gradle project for creating a package for a custom annotation trait.
custom-linter Gradle project to create a custom, configurable model linter.
custom-string-trait Gradle project for creating a package for a custom string trait.
custom-structure-trait Gradle project for creating a package for a custom structure trait.
custom-validator Gradle project to create a custom model validator.
decorators Gradle project to create a custom decorator for validation events.
filter-internal-projection Projection that filters out internal shapes and traits.
quickstart-cli Smithy Quick Start example weather service using the Smithy CLI.
quickstart-gradle Smithy Quick Start example weather service using the
Smithy-Gradle-Plugin.
shared-model-package Gradle project to create a shared package of common Smithy models.
smithy-to-openapi Generate an OpenAPI spec from a Smithy model
Let’s try using the quickstart-gradle
template to create a project for a
init
command using the --template
flag:
$ smithy init --template quickstart-gradle --output ./my-new-service
Smithy project created in directory: my-new-service
This will create a project consisting of the Smithy model file, the smithy-build.json
file and various Gradle config files within the my-new-service
directory:
$ tree ./my-new-service
./my-new-service
├── README.md
├── build.gradle.kts
├── gradle
│ └── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradle.properties
├── gradlew
├── gradlew.bat
├── models
│ └── weather.smithy
├── settings.gradle.kts
└── smithy-build.json
As you can see, the init
command simplifies the initiation of a new Smithy project. We encourage you to try out the other templates to learn more about different project setups and Smithy features!
Templates repository
Behind the scenes, the init
command checks the latest list of templates available from Smithy’s
Developers have the flexibility to override the default repository with an alternative one. Developers may want to set up their own template repository to share Smithy models specific to their products or use case. Alternatively, they may want to create a set of private templates to be shared within an organization.
The --url
parameter specifies a custom repository:
$ smithy init --template some-common-package --url https://github.com/user/repo.git
Smithy project created in directory: some-common-package
The init
command expects a smithy-templates.json
file at the root level of the repository. Here is an
What’s Next?
With the Smithy init
command now available, developers can quickly and easily initiate Smithy projects from a set of curated project templates. Developers can also utilize the templates to explore different project setups and learn about various Smithy features.
We encourage you to try out the Smithy init
command and tell us your thoughts by contacting us on
About the author:
The mentioned AWS GenAI Services service names relating to generative AI are only available or previewed in the Global Regions. Amazon Web Services China promotes AWS GenAI Services relating to generative AI solely for China-to-global business purposes and/or advanced technology introduction.