Repository navigation
Commit 295f6c2
fix(python-flask, python-aiohttp): generate valid security function names for scheme names with '-' or '.' (#25458)
* fix(python-flask, python-aiohttp): generate valid security function names for scheme names with '-' or '.'
Security scheme names may contain '-' and '.' (component keys match
^[a-zA-Z0-9.\-_]+$), but the generated security_controller.py used them
verbatim in function names, e.g. 'def info_from_api-key(', and the
x-apikeyInfoFunc / x-basicInfoFunc / x-bearerInfoFunc / x-tokenInfoFunc /
x-scopeValidateFunc extensions pointed at the same invalid names. The
module didn't compile, so the app couldn't start.
Each scheme name now gets one Python identifier suffix, computed once in
preprocessOpenAPI in spec order: characters other than [A-Za-z0-9_]
become '_', and names that would collide (e.g. 'api-key' and 'api.key')
are numbered (_2, _3, ...). Both addSecurityExtensions and the
security_controller templates use it, the latter through a fromSecurity
override that sets x-python-connexion-security-function-suffix. Names
that are already valid identifiers produce exactly the same output as
before, and user-provided x-*InfoFunc extensions are kept.
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(python-flask, python-aiohttp): keep unnumbered function names for already-valid security scheme names
Reserve the security function name suffix of scheme names that are already
valid Python identifiers before numbering the names that need character
replacement. Previously suffixes were assigned purely in spec order, so a
sanitized name like "api-key" -> "api_key" claimed the suffix first and
"api_key" listed after it was bumped to "api_key_2" (and a literal
"api_key_2" to "api_key_2_2"), changing the generated output for names that
were already valid.
Also make testSecuritySchemeNamesProduceValidPythonFunctions parse the
generated openapi.yaml and assert, per scheme, that each x-*Func extension
points at the expected function defined in security_controller.py, instead
of only checking that the reference strings occur somewhere in the file.
Add an "api_key" scheme listed after "api-key" to the fixture to cover the
ordering regression.
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
* docs(python-flask, python-aiohttp): correct comment on how security function name suffixes are computed
---------
Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>1 parent 4043efc commit 295f6c2
5 files changed
Lines changed: 381 additions & 16 deletions
File tree
- modules/openapi-generator/src
- main
- java/org/openapitools/codegen/languages
- resources
- python-aiohttp
- python-flask
- test
- java/org/openapitools/codegen/python
- resources/3_0/python-flask
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
86 | 86 | | |
87 | 87 | | |
88 | 88 | | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
89 | 98 | | |
90 | 99 | | |
91 | 100 | | |
| |||
459 | 468 | | |
460 | 469 | | |
461 | 470 | | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
462 | 482 | | |
463 | 483 | | |
464 | 484 | | |
| 485 | + | |
465 | 486 | | |
466 | 487 | | |
467 | 488 | | |
468 | | - | |
| 489 | + | |
469 | 490 | | |
470 | 491 | | |
471 | 492 | | |
472 | | - | |
| 493 | + | |
473 | 494 | | |
474 | | - | |
| 495 | + | |
475 | 496 | | |
476 | 497 | | |
477 | 498 | | |
478 | 499 | | |
479 | 500 | | |
480 | | - | |
481 | | - | |
| 501 | + | |
| 502 | + | |
482 | 503 | | |
483 | 504 | | |
484 | 505 | | |
| |||
487 | 508 | | |
488 | 509 | | |
489 | 510 | | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
490 | 557 | | |
491 | 558 | | |
492 | 559 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
| 17 | + | |
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
| 24 | + | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
| 36 | + | |
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
48 | | - | |
| 48 | + | |
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
| 21 | + | |
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | | - | |
| 37 | + | |
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
| |||
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
55 | | - | |
| 55 | + | |
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
| |||
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
75 | | - | |
| 75 | + | |
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
| |||
0 commit comments