Skip to content

Commit ceb918b

Browse files
committed
Validation passes.
1 parent 2066e0b commit ceb918b

File tree

2 files changed

+178
-43
lines changed

2 files changed

+178
-43
lines changed

bin/validate

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
#!/usr/bin/env perl
2+
3+
use v5.20;
4+
use strict;
5+
use warnings;
6+
use File::Basename;
7+
use File::Spec;
8+
use Cwd qw(abs_path);
9+
use Getopt::Long;
10+
11+
# Get project root directory (one level up from bin/)
12+
my $script_dir = dirname(abs_path($0));
13+
my $project_root = dirname($script_dir);
14+
15+
# Parse command line arguments
16+
my $capi_version;
17+
my $help;
18+
my $verbose;
19+
20+
GetOptions(
21+
'version=s' => \$capi_version,
22+
'verbose' => \$verbose,
23+
'help' => \$help,
24+
) or die usage();
25+
26+
# Show usage if help requested or missing required arguments
27+
if ($help || !$capi_version) {
28+
print usage();
29+
exit($help ? 0 : 1);
30+
}
31+
32+
# Validate inputs
33+
validate_inputs();
34+
35+
# Validate the OpenAPI specification
36+
validate_spec();
37+
38+
sub usage {
39+
return <<EOF;
40+
Usage: $0 --version=VERSION [--verbose]
41+
42+
Validate CAPI OpenAPI specification
43+
44+
Required options:
45+
--version=VERSION CAPI version to validate (e.g., 3.195.0)
46+
47+
Optional options:
48+
--verbose Show detailed validation output
49+
--help Show this help message
50+
51+
Examples:
52+
$0 --version=3.195.0
53+
$0 --version=3.181.0 --verbose
54+
EOF
55+
}
56+
57+
sub validate_inputs {
58+
# Check if spec file exists
59+
my $spec_file = File::Spec->catfile($project_root, 'capi', "${capi_version}.openapi.yml");
60+
unless (-f $spec_file) {
61+
die "Error: OpenAPI spec file not found: $spec_file\n" .
62+
"Please run 'make gen-openapi-spec' first to generate the specification.\n";
63+
}
64+
65+
# Check if openapi-generator is available
66+
my $generator_check = `which openapi-generator 2>/dev/null || which openapi-generator-cli 2>/dev/null`;
67+
chomp $generator_check;
68+
unless ($generator_check) {
69+
die "Error: openapi-generator-cli not found.\n" .
70+
"Please run 'make deps' to install dependencies.\n";
71+
}
72+
}
73+
74+
sub validate_spec {
75+
my $spec_file = File::Spec->catfile($project_root, 'capi', "${capi_version}.openapi.yml");
76+
77+
# Determine which command to use (openapi-generator or openapi-generator-cli)
78+
my $generator_cmd = `which openapi-generator 2>/dev/null`;
79+
chomp $generator_cmd;
80+
$generator_cmd = 'openapi-generator-cli' unless $generator_cmd;
81+
82+
# Build the validation command
83+
my $cmd = "$generator_cmd validate -i '$spec_file'";
84+
85+
# Execute the validation
86+
say "Validating CAPI $capi_version OpenAPI specification...";
87+
say "Spec file: $spec_file" if $verbose;
88+
say "Command: $cmd" if $verbose;
89+
90+
my $result = system($cmd);
91+
92+
if ($result == 0) {
93+
say "\n✓ Validation passed!";
94+
say " The OpenAPI specification is valid.";
95+
96+
# Check if there were warnings in the output
97+
my $output = `$cmd 2>&1`;
98+
if ($output =~ /Warning/) {
99+
say "\n⚠ Note: There are some warnings (usually about unused models).";
100+
say " These are typically not critical issues.";
101+
}
102+
103+
# Also check JSON version if verbose
104+
check_json_spec() if $verbose;
105+
106+
} else {
107+
say "\n✗ Validation failed!";
108+
say " Please check the errors above and fix the specification.";
109+
exit(1);
110+
}
111+
}
112+
113+
sub check_json_spec {
114+
my $json_file = File::Spec->catfile($project_root, 'capi', "${capi_version}.openapi.json");
115+
116+
if (-f $json_file) {
117+
say "\nAlso validating JSON format...";
118+
119+
# Determine which command to use
120+
my $generator_cmd = `which openapi-generator 2>/dev/null`;
121+
chomp $generator_cmd;
122+
$generator_cmd = 'openapi-generator-cli' unless $generator_cmd;
123+
124+
my $json_cmd = "$generator_cmd validate -i '$json_file'";
125+
say "Command: $json_cmd" if $verbose;
126+
127+
my $result = system($json_cmd);
128+
129+
if ($result == 0) {
130+
say "✓ JSON specification is valid.";
131+
} else {
132+
say "✗ JSON specification validation failed.";
133+
}
134+
}
135+
}

capi/3.195.0/apps.yml

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1421,49 +1421,6 @@ components:
14211421
type: string
14221422
enum: [GET, POST, PUT, PATCH, DELETE]
14231423

1424-
responses:
1425-
Unauthorized:
1426-
description: Unauthorized
1427-
content:
1428-
application/json:
1429-
schema:
1430-
$ref: '#/components/schemas/Error'
1431-
1432-
Forbidden:
1433-
description: Forbidden
1434-
content:
1435-
application/json:
1436-
schema:
1437-
$ref: '#/components/schemas/Error'
1438-
1439-
NotFound:
1440-
description: Not Found
1441-
content:
1442-
application/json:
1443-
schema:
1444-
$ref: '#/components/schemas/Error'
1445-
1446-
BadRequest:
1447-
description: Bad Request
1448-
content:
1449-
application/json:
1450-
schema:
1451-
$ref: '#/components/schemas/Errors'
1452-
1453-
UnprocessableEntity:
1454-
description: Unprocessable Entity
1455-
content:
1456-
application/json:
1457-
schema:
1458-
$ref: '#/components/schemas/Error'
1459-
1460-
UnexpectedError:
1461-
description: Unexpected Error
1462-
content:
1463-
application/json:
1464-
schema:
1465-
$ref: '#/components/schemas/Error'
1466-
14671424
AppFeature:
14681425
type: object
14691426
required:
@@ -1537,6 +1494,49 @@ components:
15371494
enabled-by: [email protected]
15381495
enabled-date: "2024-01-15"
15391496

1497+
responses:
1498+
Unauthorized:
1499+
description: Unauthorized
1500+
content:
1501+
application/json:
1502+
schema:
1503+
$ref: '#/components/schemas/Error'
1504+
1505+
Forbidden:
1506+
description: Forbidden
1507+
content:
1508+
application/json:
1509+
schema:
1510+
$ref: '#/components/schemas/Error'
1511+
1512+
NotFound:
1513+
description: Not Found
1514+
content:
1515+
application/json:
1516+
schema:
1517+
$ref: '#/components/schemas/Error'
1518+
1519+
BadRequest:
1520+
description: Bad Request
1521+
content:
1522+
application/json:
1523+
schema:
1524+
$ref: '#/components/schemas/Errors'
1525+
1526+
UnprocessableEntity:
1527+
description: Unprocessable Entity
1528+
content:
1529+
application/json:
1530+
schema:
1531+
$ref: '#/components/schemas/Error'
1532+
1533+
UnexpectedError:
1534+
description: Unexpected Error
1535+
content:
1536+
application/json:
1537+
schema:
1538+
$ref: '#/components/schemas/Error'
1539+
15401540
securitySchemes:
15411541
bearerAuth:
15421542
type: http

0 commit comments

Comments
 (0)