|
| 1 | +===================================== |
| 2 | +Smithy IDL 1.0 to 2.0 Migration Guide |
| 3 | +===================================== |
| 4 | + |
| 5 | +This guide describes how to migrate your models from Smithy IDL version 1.0 |
| 6 | +to version 2.0 without breaking your models or customers. |
| 7 | + |
| 8 | +.. contents:: Table of contents |
| 9 | + :depth: 2 |
| 10 | + :local: |
| 11 | + :backlinks: none |
| 12 | + |
| 13 | +Update the model file version |
| 14 | +============================= |
| 15 | + |
| 16 | +For each model file you are upgrading, change the version from ``1`` or |
| 17 | +``1.0`` to ``2.0``. In the IDL this is controlled with the |
| 18 | +:ref:`version statement <smithy-version>`, and in the AST it is controlled |
| 19 | +with the ``smithy`` :ref:`top level property <top-level-properties>`. For |
| 20 | +example, the following model: |
| 21 | + |
| 22 | +.. code-block:: smithy |
| 23 | +
|
| 24 | + $version: "1.0" |
| 25 | +
|
| 26 | + namespace smithy.example |
| 27 | +
|
| 28 | + string Foo |
| 29 | +
|
| 30 | +Should be updated to: |
| 31 | + |
| 32 | +.. code-block:: smithy |
| 33 | +
|
| 34 | + $version: "2.0" |
| 35 | +
|
| 36 | + namespace smithy.example |
| 37 | +
|
| 38 | + string Foo |
| 39 | +
|
| 40 | +An IDL model file may not have a version control statement at the top. In this |
| 41 | +case, it uses version 1.0 by default. For example: |
| 42 | + |
| 43 | +.. code-block:: smithy |
| 44 | +
|
| 45 | + namespace smithy.example |
| 46 | +
|
| 47 | + string Foo |
| 48 | +
|
| 49 | +Also needs to be updated to: |
| 50 | + |
| 51 | +.. code-block:: smithy |
| 52 | +
|
| 53 | + $version: "2.0" |
| 54 | +
|
| 55 | + namespace smithy.example |
| 56 | +
|
| 57 | + string Foo |
| 58 | +
|
| 59 | +Smithy's tooling is able to load both 1.0 model files and 2.0 model files into |
| 60 | +a single combined model. Therefore when migrating, it may be wise to migrate |
| 61 | +one file at a time. |
| 62 | + |
| 63 | + |
| 64 | +Remove the box trait |
| 65 | +==================== |
| 66 | + |
| 67 | +The ``box`` trait is removed in 2.0, so it must be removed from any shapes or |
| 68 | +members that use it. Smithy structure members are considered boxed by default, |
| 69 | +which can be changed using the :ref:`required-trait` or :ref:`default-trait`. |
| 70 | +In effect, this means you can indiscriminately remove the ``box`` trait from |
| 71 | +your models. |
| 72 | + |
| 73 | +.. seealso:: |
| 74 | + |
| 75 | + :ref:`optionality` |
| 76 | + |
| 77 | + |
| 78 | +Replace Primitive prelude shape targets |
| 79 | +======================================= |
| 80 | + |
| 81 | +The primitive shapes have been removed from the prelude, and so any member |
| 82 | +targeting one of them must update to target its equivalent non-primitive |
| 83 | +shape as well as add the :ref:`default-trait`. |
| 84 | + |
| 85 | +.. list-table: |
| 86 | + :header-rows: 1 |
| 87 | + :widths: 50 50 |
| 88 | +
|
| 89 | + * - Old target |
| 90 | + - New target |
| 91 | + * - ``PrimitiveBoolean`` |
| 92 | + - ``Boolean`` |
| 93 | + * - ``PrimitiveShort`` |
| 94 | + - ``Short`` |
| 95 | + * - ``PrimitiveInteger`` |
| 96 | + - ``Integer`` |
| 97 | + * - ``PrimitiveLong`` |
| 98 | + - ``Long`` |
| 99 | + * - ``PrimitiveFloat`` |
| 100 | + - ``Float`` |
| 101 | + * - ``PrimitiveDouble`` |
| 102 | + - ``Double`` |
| 103 | +
|
| 104 | +For example, the following model: |
| 105 | + |
| 106 | +.. code-block:: smithy |
| 107 | +
|
| 108 | + structure User { |
| 109 | + name: PrimitiveString |
| 110 | + } |
| 111 | +
|
| 112 | +Needs to be updated to: |
| 113 | + |
| 114 | +.. code-block:: smithy |
| 115 | +
|
| 116 | + structure User { |
| 117 | + @default |
| 118 | + name: String |
| 119 | + } |
| 120 | +
|
| 121 | +
|
| 122 | +Optional migration steps |
| 123 | +======================== |
| 124 | + |
| 125 | +The following steps are not required to update a model to be fully compatible |
| 126 | +with 2.0, but instead are refactoring steps that can be taken to simplify a |
| 127 | +your model. |
| 128 | + |
| 129 | + |
| 130 | +Move operation inputs and outputs inline |
| 131 | +---------------------------------------- |
| 132 | + |
| 133 | +The structures that define operation inputs and outputs very often use |
| 134 | +boilerplate names and for readability are usually placed close to their parent |
| 135 | +operation shapes to improve readability of the model. Smithy 2.0 introduced |
| 136 | +:ref:`inline input and output <idl-inline-input-output>`, which allows you |
| 137 | +to define those shapes as part of the definition of the operation rather than |
| 138 | +separately. This improves readability and reduces the amount of boilerplate |
| 139 | +needed to model an operation. For example, the following model: |
| 140 | + |
| 141 | +.. code-block:: smithy |
| 142 | +
|
| 143 | + $version: "1.0" |
| 144 | +
|
| 145 | + namespace smithy.example |
| 146 | +
|
| 147 | + operation PutUser { |
| 148 | + input: PutUserInput, |
| 149 | + output: PutUserOutput |
| 150 | + } |
| 151 | +
|
| 152 | + @input |
| 153 | + structure PutUserInput { |
| 154 | + email: String, |
| 155 | + id: String, |
| 156 | + username: String, |
| 157 | + description: String |
| 158 | + } |
| 159 | +
|
| 160 | + @output |
| 161 | + structure PutUserOutput {} |
| 162 | +
|
| 163 | +can be updated to: |
| 164 | + |
| 165 | +.. code-block:: |
| 166 | +
|
| 167 | + $version: "2.0" |
| 168 | +
|
| 169 | + namespace smithy.example |
| 170 | +
|
| 171 | + operation PutUser { |
| 172 | + input := { |
| 173 | + email: String |
| 174 | + id: String |
| 175 | + username: String |
| 176 | + description: String |
| 177 | + }, |
| 178 | + output := {} |
| 179 | + } |
| 180 | +
|
| 181 | +.. seealso:: |
| 182 | + |
| 183 | + the :ref:`inline input / output <idl-inline-input-output>` section of the |
| 184 | + spec for more details. |
| 185 | + |
| 186 | + |
| 187 | +Abstract shared shape configuration with mixins |
| 188 | +----------------------------------------------- |
| 189 | + |
| 190 | +Models often have several shapes that refer to the same sets of members, or |
| 191 | +which share a set of trait configurations. For example, resource instance |
| 192 | +operations all require that the resource's identifiers be present in input. |
| 193 | +With :ref:`mixins`, it is easy to simply share these member definitions without |
| 194 | +having to copy and paste them. The following model: |
| 195 | + |
| 196 | +.. code-block:: smithy |
| 197 | +
|
| 198 | + $version: "1.0" |
| 199 | +
|
| 200 | + namespace smithy.example |
| 201 | +
|
| 202 | + resource User { |
| 203 | + identifiers: { |
| 204 | + email: String, |
| 205 | + id: String, |
| 206 | + }, |
| 207 | + read: GetUser |
| 208 | + } |
| 209 | +
|
| 210 | + operation GetUser { |
| 211 | + input: GetUserInput, |
| 212 | + output: GetUserOutput |
| 213 | + } |
| 214 | +
|
| 215 | + @input |
| 216 | + structure GetUserInput { |
| 217 | + @required |
| 218 | + email: String, |
| 219 | +
|
| 220 | + @required |
| 221 | + id: String, |
| 222 | + } |
| 223 | +
|
| 224 | + @output |
| 225 | + structure GetUserOutput { |
| 226 | + @required |
| 227 | + email: String, |
| 228 | +
|
| 229 | + @required |
| 230 | + id: String, |
| 231 | +
|
| 232 | + description: String |
| 233 | + } |
| 234 | +
|
| 235 | +Can be updated to: |
| 236 | + |
| 237 | +.. code-block:: smithy |
| 238 | +
|
| 239 | + $version: "2.0" |
| 240 | +
|
| 241 | + namespace smithy.example |
| 242 | +
|
| 243 | + resource User { |
| 244 | + identifiers: { |
| 245 | + email: String |
| 246 | + id: String |
| 247 | + username: String |
| 248 | + }, |
| 249 | + read: GetUser |
| 250 | + } |
| 251 | +
|
| 252 | + @mixin |
| 253 | + structure UserIdentifiers { |
| 254 | + @required |
| 255 | + email: String |
| 256 | +
|
| 257 | + @required |
| 258 | + id: String |
| 259 | + } |
| 260 | +
|
| 261 | + operation GetUser { |
| 262 | + input := with [UserIdentifiers] {} |
| 263 | + output := with [UserIdentifiers] { |
| 264 | + description: String |
| 265 | + } |
| 266 | + } |
| 267 | +
|
| 268 | +Similarly, :ref:`mixins` can be useful if you have a shared set of traits |
| 269 | +that otherwise have to be copied and pasted. |
| 270 | + |
| 271 | +.. seealso:: |
| 272 | + |
| 273 | + the :ref:`mixins section <mixins>` of the spec for more details on how they |
| 274 | + work. |
| 275 | + |
| 276 | + |
| 277 | +Remove unsightly commas |
| 278 | +----------------------- |
| 279 | + |
| 280 | +Smithy IDL 2.0 removed the need to include commas when defining, lists, maps, |
| 281 | +and shape properties. For example, the following model: |
| 282 | + |
| 283 | +.. code-block:: smithy |
| 284 | +
|
| 285 | + $version: "1.0" |
| 286 | +
|
| 287 | + namespace smithy.example |
| 288 | +
|
| 289 | + operation GetUser { |
| 290 | + input: GetUserInput, |
| 291 | + output: GetUserOutput, |
| 292 | + errors: [ |
| 293 | + NotFoundError, |
| 294 | + AccessDeniedError, |
| 295 | + ], |
| 296 | + } |
| 297 | +
|
| 298 | +can be updated to: |
| 299 | + |
| 300 | +.. code-block:: smithy |
| 301 | +
|
| 302 | + $version: "1.0" |
| 303 | +
|
| 304 | + namespace smithy.example |
| 305 | +
|
| 306 | + operation GetUser { |
| 307 | + input: GetUserInput |
| 308 | + output: GetUserOutput |
| 309 | + errors: [ |
| 310 | + NotFoundError |
| 311 | + AccessDeniedError |
| 312 | + ] |
| 313 | + } |
0 commit comments