@@ -26,7 +26,7 @@ const operationsList = ["get", "post", "put", "delete", "patch", "options", "hea
26
26
*/
27
27
function fixServers ( server , path ) {
28
28
// Server url starting with "/" tells that it is not an http(s) url
29
- if ( server . url ? .startsWith ( "/" ) ) {
29
+ if ( server . url && server . url . startsWith ( "/" ) ) {
30
30
const inUrl = new URL ( path ) ;
31
31
const finalUrl = inUrl . protocol + "//" + inUrl . hostname + server . url ;
32
32
server . url = finalUrl ;
@@ -39,7 +39,7 @@ function fixServers (server, path) {
39
39
* be at root, path or operation's level
40
40
*/
41
41
function fixOasRelativeServers ( schema , filePath ) {
42
- if ( schema ? .openapi && ( filePath ? .startsWith ( "http:" ) || filePath ? .startsWith ( "https:" ) ) ) {
42
+ if ( schema . openapi && ( filePath && ( filePath . startsWith ( "http:" ) || filePath . startsWith ( "https:" ) ) ) ) {
43
43
/**
44
44
* From OpenAPI v3 spec for Server object's url property: "REQUIRED. A URL to the target host.
45
45
* This URL supports Server Variables and MAY be relative, to indicate that the host location is relative to the location where
@@ -48,7 +48,9 @@ function fixOasRelativeServers (schema, filePath) {
48
48
* However, interpretation of the spec says that relative paths for servers should take into account the hostname that
49
49
* serves the OpenAPI file.
50
50
*/
51
- schema . servers ?. map ( server => fixServers ( server , filePath ) ) ; // Root level servers array's fixup
51
+ if ( schema . servers ) {
52
+ schema . servers . map ( server => fixServers ( server , filePath ) ) ; // Root level servers array's fixup
53
+ }
52
54
53
55
// Path or Operation level servers array's fixup
54
56
Object . keys ( schema . paths ) . forEach ( path => {
@@ -60,7 +62,9 @@ function fixOasRelativeServers (schema, filePath) {
60
62
}
61
63
else if ( operationsList . includes ( opItem ) ) {
62
64
// servers at operation level
63
- pathItem [ opItem ] . servers ?. map ( server => fixServers ( server , filePath ) ) ;
65
+ if ( pathItem [ opItem ] . servers ) {
66
+ pathItem [ opItem ] . servers . map ( server => fixServers ( server , filePath ) ) ;
67
+ }
64
68
}
65
69
} ) ;
66
70
} ) ;
0 commit comments