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