Commit 577bafd
authored
Skip inferred properties (#381)
### Motivation
Fixes #379.
Context:
If you define an object schema as follows:
```yaml
Foo:
type: object
properties:
a:
type: string
required:
- b
```
OpenAPIKit will parse it as having two properties: `a` of type `string`
and `b` being a fragment, with `a` optional and `b` required.
Unfortunately, often property names appear _only_ in the `required` list
as a result of a typo, leading to non-compiling code and a difficult
debugging story.
It comes down to the fact that Swift OpenAPI Generator never officially
supported defining properties this way, and continues not to.
If adopters want to do this intentionally, they should do this:
```yaml
Foo:
type: object
properties:
a:
type: string
b: {}
required:
- b
```
### Modifications
This PR tightens the rules around inferred properties:
1. Inferred properties are skipped, so the result of the first example
will only have the property `a` generated, and the second example both
`a` and `b`.
2. The generator emits a warning diagnostic when encountering an
inferred property, which should help adopters who made a typo catch it
much earlier in the process.
3. Bumps OpenAPIKit to 3.1.0, as the `inferred` property was added just
yesterday.
### Result
Less likely typos and mismatch between `properties` and `required`, and
a diagnostic to help debug this case.
### Test Plan
Added a snippet test.1 parent 82323ce commit 577bafd
File tree
3 files changed
+47
-1
lines changed- Sources/_OpenAPIGeneratorCore/Translator/CommonTranslations
- Tests/OpenAPIGeneratorReferenceTests
3 files changed
+47
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
58 | | - | |
| 58 | + | |
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
| |||
Lines changed: 14 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
41 | 55 | | |
42 | 56 | | |
43 | 57 | | |
| |||
Lines changed: 32 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
156 | 156 | | |
157 | 157 | | |
158 | 158 | | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
159 | 191 | | |
160 | 192 | | |
161 | 193 | | |
| |||
0 commit comments