Skip to content

Commit 450ac35

Browse files
authored
Merge pull request #258 from disneystreaming/publish-docs
Publish docs
2 parents 826df66 + 19d4279 commit 450ac35

File tree

9 files changed

+1247
-1278
lines changed

9 files changed

+1247
-1278
lines changed

README.md

Lines changed: 2 additions & 1265 deletions
Large diffs are not rendered by default.

build.sc

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -276,10 +276,7 @@ object traits extends BaseJavaModule with BasePublishModule {
276276
}
277277

278278
object tests extends Cross[TestsModule](scalaVersions)
279-
trait TestsModule
280-
extends CrossScalaModule
281-
with JavaModuleTests
282-
with BaseMunitTests
279+
trait TestsModule extends CrossScalaModule with JavaTests with BaseMunitTests
283280
}
284281

285282
object `readme-validator` extends BaseScala213Module {
@@ -291,10 +288,8 @@ object `readme-validator` extends BaseScala213Module {
291288
buildDeps.lihaoyi.oslib
292289
)
293290

294-
def readmeFile = T.sources { os.pwd / "README.md" }
295-
296291
def validate() = T.command {
297-
val args = Seq(readmeFile().head.path.toString)
292+
val args = docs.docFiles().map(_.path.toString)
298293
mill.util.Jvm.runSubprocess(
299294
finalMainClass(),
300295
runClasspath().map(_.path),
@@ -303,6 +298,19 @@ object `readme-validator` extends BaseScala213Module {
303298
}
304299
}
305300

301+
object docs extends BasePublishModule {
302+
303+
override def publishArtifactName = "smithytranslate-docs"
304+
305+
def docFiles =
306+
T.sources(os.walk(millSourcePath).map(mill.api.PathRef(_)))
307+
308+
override def resources = T.sources {
309+
docFiles()
310+
}
311+
312+
}
313+
306314
object proto extends Cross[ProtoModule](scalaVersions)
307315
trait ProtoModule
308316
extends CrossScalaModule

modules/docs/formatter.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Formatter
2+
3+
### CLI Usage
4+
5+
The `smithytranslate` CLI will recursively go through all child directories of the
6+
input directory provided and format any Smithy files it finds. The output
7+
8+
```
9+
> smithytranslate format --help
10+
11+
Usage: smithytranslate format [--no-clobber] <path to Smithy file or directory containing Smithy files>...
12+
13+
validates and formats smithy files
14+
15+
Options and flags:
16+
--help
17+
Display this help text.
18+
--no-clobber
19+
dont overwrite existing file instead create a new file with the word 'formatted' appended so test.smithy -> test_formatted.smithy
20+
```
21+
22+
### Capabilities and Design
23+
- The formatter is based off the ABNF defined at [Smithy-Idl-ABNF](https://smithy.io/2.0/spec/idl.html#smithy-idl-abnf)
24+
- The formatter assumes the file is a valid Smithy file and must be able to pass the Model Assembler validation , otherwise it will return an error
25+
- use --no-clobber to create a new file to avoid overwriting the original file
26+
- actual formatting rules are still WIP and will be updated as the formatter is developed

modules/docs/json_schema.md

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
# JSON Schema
2+
3+
### CLI Usage
4+
5+
```
6+
> smithytranslate json-schema-to-smithy --help
7+
8+
Usage: smithytranslate json-schema-to-smithy --input <path> [--input <path>]... [--verboseNames] [--failOnValidationErrors] [--useEnumTraitSyntax] [--outputJson] <directory>
9+
10+
Take Json Schema specs as input and produce Smithy files as output.
11+
12+
Options and flags:
13+
--help
14+
Display this help text.
15+
--input <path>, -i <path>
16+
input source files
17+
--verbose-names
18+
If set, names of shapes not be simplified and will be as verbose as possible
19+
--validate-input
20+
If set, abort the conversion if any input specs contains a validation error
21+
--validate-output
22+
If set, abort the conversion if any produced smithy spec contains a validation error
23+
--enum-trait-syntax
24+
output enum types with the smithy v1 enum trait (deprecated) syntax
25+
--json-output
26+
changes output format to be json representations of the smithy models
27+
```
28+
29+
Run `smithytranslate json-schema-to-smithy --help` for all usage information.
30+
31+
### Differences from OpenAPI
32+
33+
Most of the functionality of the `OpenAPI => Smithy` conversion is the same for the `JSON Schema => Smithy` one. As such, here
34+
we will outline any differences that exist. Everything else is the same. See [OpenAPI docs](openapi.md) for more information.
35+
36+
#### Default Values
37+
38+
Default values from JSON Schema will be captured in the `smithy.api#default` trait.
39+
40+
JSON Schema:
41+
```json
42+
{
43+
"$id": "test.json",
44+
"$schema": "http://json-schema.org/draft-07/schema#",
45+
"title": "Person",
46+
"type": "object",
47+
"properties": {
48+
"firstName": {
49+
"type": "string",
50+
"default": "Sally"
51+
}
52+
}
53+
}
54+
```
55+
56+
Smithy:
57+
```smithy
58+
structure Person {
59+
@default("Sally")
60+
firstName: String
61+
}
62+
```
63+
64+
#### Null Values
65+
66+
JSON Schemas allows for declaring types such as `["string", "null"]`. This type declaration
67+
on a required field means that the value cannot be omitted from the `JSON` payload entirely,
68+
but may be set to `null`. For example:
69+
70+
JSON Schema:
71+
```json
72+
{
73+
"$id": "test.json",
74+
"$schema": "http://json-schema.org/draft-07/schema#",
75+
"title": "Foo",
76+
"type": "object",
77+
"properties": {
78+
"bar": {
79+
"type": ["string", "null"]
80+
}
81+
},
82+
"required": ["bar"]
83+
}
84+
```
85+
86+
Smithy:
87+
```smithy
88+
use alloy#nullable
89+
90+
structure Foo {
91+
@required
92+
@nullable
93+
bar: String
94+
}
95+
```
96+
97+
In most protocols, there is likely no difference between an optional field and a nullable optional field.
98+
Similarly, some protocols may not allow for required fields to be nullable. These considerations are left
99+
up to the protocol itself.
100+
101+
#### Maps
102+
103+
JSON Schema doesn't provide a first-class type for defining maps. As such, we translate a commonly-used
104+
convention into map types when encountered. When `patternProperties` is set to have a single entry, `.*`,
105+
we translate that to a smithy map type.
106+
107+
JSON Schema:
108+
```json
109+
{
110+
"$id": "test.json",
111+
"$schema": "http://json-schema.org/draft-07/schema#",
112+
"title": "TestMap",
113+
"type": "object",
114+
"patternProperties": {
115+
".*": {
116+
"type": "string"
117+
}
118+
}
119+
}
120+
```
121+
122+
Smithy:
123+
```smithy
124+
map TestMap {
125+
key: String,
126+
value: String
127+
}
128+
```

0 commit comments

Comments
 (0)