Commit 8d5b397
Calculate required response header parameters for initialize (#150)
### Motivation
Resolve #30
### Modifications
Define a computed property on StructBlueprint that tells you whether the
struct has an empty initializer, and it is used when response header
struct blueprint is created.
### Result
If one or more required response header parameters are present,
Generates code that needs to set request header parameters when create
response.
For example you define the yaml below
```yaml
responses:
'200':
description: A success response with a greeting.
headers:
X-Extra-Arguments:
required: false
description: "A description here."
content:
application/json:
schema:
$ref: '#/components/schemas/Greeting'
```
`Types.swift` is generated like below, and you can set the "headers"
parameter if necessary ,
<img width="765" alt="スクリーンショット 2023-07-29 14 44 45"
src="https://github.com/apple/swift-openapi-generator/assets/16571394/c8e5779a-e851-40d6-9c68-9ced8af4dcc2">
if you set required true
```yaml
X-Extra-Arguments:
required: true
```
`Types.swift` is generated like below, and you should set reponse
headers when initialize

### Test Plan
Add test optional response header in SnipetBasedReferenceTests, and
modify ReferenceSource a little.
---------
Co-authored-by: Honza Dvorsky <[email protected]>
Co-authored-by: Si Beaumont <[email protected]>1 parent 379b047 commit 8d5b397
File tree
4 files changed
+63
-11
lines changed- Sources/_OpenAPIGeneratorCore/Translator
- CommonTypes
- Responses
- Tests/OpenAPIGeneratorReferenceTests
- Resources/ReferenceSources/Petstore
4 files changed
+63
-11
lines changedLines changed: 15 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
83 | 98 | | |
84 | 99 | | |
85 | 100 | | |
| |||
Lines changed: 9 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
39 | 46 | | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
| 47 | + | |
47 | 48 | | |
48 | 49 | | |
49 | 50 | | |
50 | 51 | | |
51 | 52 | | |
52 | | - | |
| 53 | + | |
53 | 54 | | |
54 | 55 | | |
55 | 56 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
686 | 686 | | |
687 | 687 | | |
688 | 688 | | |
689 | | - | |
| 689 | + | |
690 | 690 | | |
691 | 691 | | |
692 | 692 | | |
| |||
1006 | 1006 | | |
1007 | 1007 | | |
1008 | 1008 | | |
1009 | | - | |
| 1009 | + | |
1010 | 1010 | | |
1011 | 1011 | | |
1012 | 1012 | | |
| |||
Lines changed: 37 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
519 | 519 | | |
520 | 520 | | |
521 | 521 | | |
522 | | - | |
| 522 | + | |
523 | 523 | | |
524 | 524 | | |
525 | 525 | | |
| |||
541 | 541 | | |
542 | 542 | | |
543 | 543 | | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
544 | 580 | | |
545 | 581 | | |
546 | 582 | | |
| |||
0 commit comments