Version: 1.2: Updated based on feedback · apple/swift-openapi-generator@e1f5e42 (original) (raw)
`@@ -10,6 +10,7 @@ Introduce an alternative naming strategy for more idiomatic Swift identifiers, i
`
10
10
`- Versions:
`
11
11
`- v1.0 (2024-11-27): Initial version
`
12
12
`- v1.1 (2024-11-28): Also handle "/", "{", and "}" for better synthesized operation names
`
``
13
`+
- v1.2 (2024-12-10): Treat "/" as a word separator and improve handling of the lowercasing of acronyms at the start of an identifier.
`
13
14
`- Issues:
`
14
15
`- [apple/swift-openapi-generator#112][issuePlugin]
`
15
16
`- [apple/swift-openapi-generator#107][issue1]
`
`@@ -57,7 +58,7 @@ For clarity, we'll refer to the existing naming strategy as the "defensive" nami
`
57
58
``
58
59
`` Part of the new strategy is adjusting the capitalization, and producing UpperCamelCase
names for types, and lowerCamelCase
names for members, as is common in hand-written Swift code.
``
59
60
``
60
``
`-
After attempting to produce an more idiomatic identifier, this strategy will fall back to the defensive strategy, to replace any remaining invalid symbols.
`
``
61
`+
This strategy will fall back to the defensive strategy if it encounters any invalid symbols in the identifier.
`
61
62
``
62
63
`The second feature introduced as part of this proposal is a way to provide a string -> string map to fully override only specific OpenAPI names and provide their exact Swift identifiers. This is the ultimate escape hatch when both naming strategies fail to provide the desired result for the adopter.
`
63
64
``
`@@ -77,7 +78,8 @@ To get a sense for the proposed change, check out the table below that compares
`
77
78
`` | version 2.0
| version_space_2_period_0
| Version2_0
| version2_0
|
``
78
79
`` | naïve café
| naïve_space_café
| NaïveCafé
| naïveCafé
|
``
79
80
`` | __user
| __user
| __User
| __user
|
``
80
``
`` -
| get/pets/{petId}
Added in v1.1 | get_sol_pets_sol__lcub_petId_rcub_
| Get_pets_petId
| get_pets_petId
|
``
``
81
`` +
| get/pets/{petId}
Changed in v1.2 | get_sol_pets_sol__lcub_petId_rcub_
| GetPetsPetId
| getPetsPetId
|
``
``
82
`` +
| HTTPProxy
Added in v1.2 | HTTPProxy
| HTTPProxy
| httpProxy
|
``
81
83
`` | order#123
| order_num_123
| order_num_123
| order_num_123
|
``
82
84
``
83
85
`` Notice that in the last example, since the OpenAPI name contains the pound (#
) character, the idiomatic naming strategy falls back to the defensive naming strategy. In all the other cases, however, the resulting names are more idiomatic Swift identifiers.
``
`@@ -100,7 +102,7 @@ The idiomatic naming strategy (check out the current code [here][impl], look for
`
100
102
`` - dashes (-
, ASCII: 0x2d
)
``
101
103
`` - underscores (_
, ASCII: 0x5f
)
``
102
104
`` - spaces (
, ASCII: 0x20
)
``
103
``
`` -
- slashes (
/
, ASCII:0x2f
) Added in v1.1
``
``
105
`` +
- slashes (
/
, ASCII:0x2f
) Added in v1.1, changed meaning in 1.2
``
104
106
`` - curly braces ({
and }
, ASCII: 0x7b
and 0x7d
) Added in v1.1
``
105
107
``
106
108
`` > Note: We let Swift.String.isLetter
decide whether a character is a letter, which has the advantage of including letters in the non-ASCII range. Swift identifiers also support a wide range of alphanumeric characters.
``