| 1 | package OpenAPI::Generator::Util; | ||||||||||
| 2 | |||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 3 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 3 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 3 | ▶ | use Exporter qw(import); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 3 | our @EXPORT_OK = qw( | |||||||||
| 10 | merge_definitions | ||||||||||
| 11 | ); | ||||||||||
| 12 | |||||||||||
| 13 | sub merge_definitions { | ||||||||||
| 14 | |||||||||||
| 15 | 3 | ▶ | my(@definitions) = @_; | ||||||||
|
Subroutine
merge_definitions: called CC=13 SCAR=26.3
Pod
documented
| |||||||||||
| 16 | |||||||||||
| 17 | 3 | ▶ | croak 'no definitions to merge' unless @definitions; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 18 | |||||||||||
| 19 | 3 | ▶ | if (scalar @definitions == 1) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 20 | 1 | return $definitions[0]; | |||||||||
| 21 | } | ||||||||||
| 22 | |||||||||||
| 23 | 2 | my %common_def = ( | |||||||||
| 24 | paths => {}, | ||||||||||
| 25 | components => { | ||||||||||
| 26 | schemas => {}, | ||||||||||
| 27 | securitySchemes => {}, | ||||||||||
| 28 | parameters => {} | ||||||||||
| 29 | }, | ||||||||||
| 30 | ); | ||||||||||
| 31 | |||||||||||
| 32 | 2 | for my $def (@definitions) { | |||||||||
| 33 | |||||||||||
| 34 | # paths | ||||||||||
| 35 | 6 | ▶ | while (my($path, $path_schema) = each %{$def->{paths}}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 36 | 8 | ▶ | while (my($method, $method_schema) = each %{$path_schema}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | 8 | ▶ | if (exists $common_def{paths}{$path}{$method}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 38 | 0 | croak "$method $path duplicates"; | |||||||||
| 39 | } | ||||||||||
| 40 | 8 | $common_def{paths}{$path}{$method} = $method_schema; | |||||||||
| 41 | } | ||||||||||
| 42 | } | ||||||||||
| 43 | |||||||||||
| 44 | # comp param | ||||||||||
| 45 | 6 | ▶ | while (my($param, $param_schema) = each %{$def->{components}{parameters}}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 46 | 5 | ▶ | if (exists $common_def{components}{parameters}{$param}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 47 | 0 | croak "param $param duplicates" | |||||||||
| 48 | } | ||||||||||
| 49 | 5 | $common_def{components}{parameters}{$param} = $param_schema; | |||||||||
| 50 | } | ||||||||||
| 51 | |||||||||||
| 52 | # comp schemas | ||||||||||
| 53 | 6 | ▶ | while (my($comp, $comp_schema) = each %{$def->{components}{schemas}}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 54 | 5 | ▶ | if (exists $common_def{components}{schemas}{$comp}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 55 | 0 | croak "schema $comp duplicates" | |||||||||
| 56 | } | ||||||||||
| 57 | 5 | $common_def{components}{schemas}{$comp} = $comp_schema; | |||||||||
| 58 | } | ||||||||||
| 59 | |||||||||||
| 60 | # comp security | ||||||||||
| 61 | 6 | ▶ | while (my($security, $security_schema) = each %{$def->{components}{securitySchemes}}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 62 | 5 | ▶ | if (exists $common_def{components}{securitySchemes}{$security}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 63 | 0 | croak "security $security duplicates" | |||||||||
| 64 | } | ||||||||||
| 65 | 5 | $common_def{components}{securitySchemes}{$security} = $security_schema; | |||||||||
| 66 | } | ||||||||||
| 67 | } | ||||||||||
| 68 | |||||||||||
| 69 | 2 | return \%common_def; | |||||||||
| 70 | } | ||||||||||
| 71 | |||||||||||
| 72 | 3 | 1 | |||||||||
| 73 | |||||||||||
| 74 | __END__ | ||||||||||