Commit 231436c
[crystal] Fix empty auth_settings Hash literal (#23625)
The Crystal client codegen template emits `Hash{...}` for the
`auth_settings` method. When an OpenAPI spec has no auth methods
recognized by the template (e.g. a non-standard OAuth2 flow URN like
`urn:ietf:params:oauth:grant-type:device_code`), the loop emits no
entries and the result is a bare `Hash{}` -- which Crystal rejects:
Error: for empty hashes use '{} of KeyType => ValueType'
This wraps the populated branch in `{{#authMethods.0}}...{{/authMethods.0}}`
and adds an empty branch via `{{^authMethods}}` that emits a typed
empty hash literal `{} of String => Hash(Symbol, String)`, which
compiles cleanly.
Adds two regression tests in CrystalClientCodegenTest:
- testAuthSettingsWithNoAuthMethodsEmitsValidCrystal: asserts the
no-auth case emits `{} of String => Hash(Symbol, String)` and not
`Hash{}`.
- testAuthSettingsWithAuthMethodsStillEmitsHashLiteral: asserts the
populated case still emits `Hash{` (no regression).
Co-authored-by: Jonathan Siegel <jonathan@aluminum.io>1 parent b3629fc commit 231436c
2 files changed
Lines changed: 76 additions & 0 deletions
File tree
- modules/openapi-generator/src
- main/resources/crystal
- test/java/org/openapitools/codegen/crystal
Lines changed: 5 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
209 | 209 | | |
210 | 210 | | |
211 | 211 | | |
| 212 | + | |
212 | 213 | | |
213 | 214 | | |
214 | 215 | | |
| |||
250 | 251 | | |
251 | 252 | | |
252 | 253 | | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
253 | 258 | | |
254 | 259 | | |
255 | 260 | | |
| |||
Lines changed: 71 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
133 | 133 | | |
134 | 134 | | |
135 | 135 | | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 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 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
136 | 207 | | |
137 | 208 | | |
138 | 209 | | |
| |||
0 commit comments