Commit df52530
authored
Support empty string OpenAPI identifiers (#59)
### Motivation
The OpenAPI specification allows the use of the empty string in some
places, for example in the following enum, which we've seen in some
real-world OpenAPI documents:
```yaml
type: string
enum:
- ""
- foo
- bar
```
We have code that converts an OpenAPI identifier to a suitable string
that can be used as a Swift identifier. It currently returns an empty
string when given an empty string as input, which is not a valid Swift
identifier. We already have some logic there to avoid clashing with some
Swift keywords, so this can be extended to handle the empty string.
### Modifications
- Map the empty string OpenAPI identifier to "_empty"
### Result
We can generate compiling code when presented with empty string OpenAPI
identifiers.
### Test Plan
- Added unit test.
- Extended reference test.
### Resolves
- Resolves #33.
- Fixes #61.
---------
Signed-off-by: Si Beaumont <[email protected]>1 parent 6aae3f5 commit df52530
File tree
4 files changed
+9
-2
lines changed- Sources/_OpenAPIGeneratorCore/Extensions
- Tests
- OpenAPIGeneratorCoreTests/Extensions
- OpenAPIGeneratorReferenceTests/Resources
- Docs
- ReferenceSources/Petstore
4 files changed
+9
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
66 | | - | |
| 66 | + | |
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
| |||
Lines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
32 | 35 | | |
33 | 36 | | |
34 | 37 | | |
| |||
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| 38 | + | |
38 | 39 | | |
39 | 40 | | |
40 | 41 | | |
| |||
Lines changed: 4 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
691 | 691 | | |
692 | 692 | | |
693 | 693 | | |
| 694 | + | |
694 | 695 | | |
695 | 696 | | |
696 | 697 | | |
697 | 698 | | |
698 | 699 | | |
699 | 700 | | |
700 | 701 | | |
| 702 | + | |
701 | 703 | | |
702 | 704 | | |
703 | 705 | | |
| |||
707 | 709 | | |
708 | 710 | | |
709 | 711 | | |
| 712 | + | |
710 | 713 | | |
711 | 714 | | |
712 | | - | |
| 715 | + | |
713 | 716 | | |
714 | 717 | | |
715 | 718 | | |
| |||
0 commit comments