ts_schema_spec 0.6.1 → 0.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +17 -17
- data/lib/ts_schema_spec/version.rb +1 -1
- data/skills/ts-schema-spec/SKILL.md +9 -6
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: aa0e8f7875f653a96d983cef0b248b9a1aeeb94afc948ebf1ef1ac3bf75154f3
|
|
4
|
+
data.tar.gz: 4b0a49cea4dc148e4a28228f9fb877331cf04543e8f906e8ceffd04ba798f8e4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: aeb87cc7d2e5fffc8a0b3c31519fe0b40f0d22f2a44216c32f9129252bff2e25d8327fc1064c61609ac25da881af50d35a2eb56e8fd9b2f14e204a675d7251f0
|
|
7
|
+
data.tar.gz: 6b5a662b7e8cba8b5a00cf85c4a7f8f33f76738d255a01c46633221e6d46452cf9f4e743b071be8bd8cc046677ef5957f5f407ee71b4ba96f182a55a38b20d4f
|
data/README.md
CHANGED
|
@@ -148,14 +148,14 @@ empty array.
|
|
|
148
148
|
|
|
149
149
|
## API
|
|
150
150
|
|
|
151
|
-
| Call
|
|
152
|
-
|
|
|
153
|
-
| `TsSchemaSpec.schema_for(path, type)`
|
|
154
|
-
| `match_ts_schema(path, type)`
|
|
155
|
-
| `react_component_props(name[, html])`
|
|
156
|
-
| `TsSchemaSpec::Skill.check!(root)`
|
|
157
|
-
| `TsSchemaSpec.configure`
|
|
158
|
-
| `TsSchemaSpec.clear_cache!`
|
|
151
|
+
| Call | Returns |
|
|
152
|
+
| ------------------------------------- | ---------------------------------------------------- |
|
|
153
|
+
| `TsSchemaSpec.schema_for(path, type)` | a `JSONSchemer` schema scoped to that exported type |
|
|
154
|
+
| `match_ts_schema(path, type)` | matcher; validates a hash, or every item of an array |
|
|
155
|
+
| `react_component_props(name[, html])` | array of props hashes, one per mount |
|
|
156
|
+
| `TsSchemaSpec::Skill.check!(root)` | raises if the installed skill is stale or missing |
|
|
157
|
+
| `TsSchemaSpec.configure` | sets `tsconfig` and extra generator arguments |
|
|
158
|
+
| `TsSchemaSpec.clear_cache!` | drops the generated-schema cache |
|
|
159
159
|
|
|
160
160
|
`match_ts_schema` was called `match_schema` before 0.6.1. The old name still
|
|
161
161
|
works but is deprecated and will be removed.
|
|
@@ -246,14 +246,14 @@ The cache lives in the process, so parallel test workers each pay for it once.
|
|
|
246
246
|
|
|
247
247
|
## Troubleshooting
|
|
248
248
|
|
|
249
|
-
| Symptom
|
|
250
|
-
|
|
|
251
|
-
| `GenerationError: ... Is it exported?`
|
|
252
|
-
| `GenerationError` listing a rerunnable command
|
|
253
|
-
| passes against an obviously wrong payload
|
|
254
|
-
| `could not run npx ts-json-schema-generator`
|
|
255
|
-
| `disallowed additional property`
|
|
256
|
-
| `has no data-react-props attribute`
|
|
249
|
+
| Symptom | Cause |
|
|
250
|
+
| ---------------------------------------------- | -------------------------------------------------------------- |
|
|
251
|
+
| `GenerationError: ... Is it exported?` | the type has no `export`, or the name is misspelled |
|
|
252
|
+
| `GenerationError` listing a rerunnable command | run it — the generator's own stderr is in the message |
|
|
253
|
+
| passes against an obviously wrong payload | the type is all-optional, or an unresolved import became `{}` |
|
|
254
|
+
| `could not run npx ts-json-schema-generator` | the generator is not in your `node_modules` |
|
|
255
|
+
| `disallowed additional property` | see above — the payload sends what TypeScript does not declare |
|
|
256
|
+
| `has no data-react-props attribute` | hand-written markup, or a mount from another integration |
|
|
257
257
|
|
|
258
258
|
## What this can't catch
|
|
259
259
|
|
|
@@ -263,7 +263,7 @@ Worth knowing before you rely on it.
|
|
|
263
263
|
a spec for; an uncovered endpoint is exactly as exposed as before. That is what
|
|
264
264
|
the skill is for, and it is convention rather than enforcement.
|
|
265
265
|
|
|
266
|
-
**It only checks what TypeScript declares.** If Rails
|
|
266
|
+
**It only checks what TypeScript declares.** If Rails _intends_ to send a field
|
|
267
267
|
nobody typed — say `as_json(only:)` carrying a misspelled attribute, which
|
|
268
268
|
Rails drops silently — no generated schema requires it, so nothing fails. A
|
|
269
269
|
structured serializer catches that class of mistake; this does not.
|
|
@@ -65,9 +65,9 @@ implying the spec covers them.
|
|
|
65
65
|
|
|
66
66
|
## Step 4 — Write the test
|
|
67
67
|
|
|
68
|
-
| Action
|
|
69
|
-
|
|
|
70
|
-
| `render json:`
|
|
68
|
+
| Action | Data source |
|
|
69
|
+
| ----------------- | ---------------------------------------- |
|
|
70
|
+
| `render json:` | `response.parsed_body["key"]` |
|
|
71
71
|
| `react_component` | `react_component_props("ComponentName")` |
|
|
72
72
|
|
|
73
73
|
`react_component_props` returns **an array**, one entry per mount, and needs
|
|
@@ -79,6 +79,8 @@ times on an empty array and asserts nothing.
|
|
|
79
79
|
describe "the props handed to MyComponent" do
|
|
80
80
|
render_views
|
|
81
81
|
|
|
82
|
+
my_component = "app/javascript/MyComponent.tsx"
|
|
83
|
+
|
|
82
84
|
it "matches MyComponentProps" do
|
|
83
85
|
record = create(:factory_name, trait_a: true)
|
|
84
86
|
create(:factory_name, :some_trait)
|
|
@@ -87,13 +89,14 @@ describe "the props handed to MyComponent" do
|
|
|
87
89
|
|
|
88
90
|
expect(response).to be_successful
|
|
89
91
|
props = react_component_props("MyComponent")
|
|
90
|
-
expect(props).to match_ts_schema(
|
|
92
|
+
expect(props).to match_ts_schema(my_component, "MyComponentProps")
|
|
91
93
|
end
|
|
92
94
|
end
|
|
93
95
|
```
|
|
94
96
|
|
|
95
|
-
Name the file and type at the assertion.
|
|
96
|
-
|
|
97
|
+
Name the file and type at the assertion. Bind the path to a local variable or a
|
|
98
|
+
`let`, not a constant: a constant assigned inside a `describe` block is global
|
|
99
|
+
and collides between spec files.
|
|
97
100
|
|
|
98
101
|
Rules:
|
|
99
102
|
|