@@ -431,7 +431,7 @@ public CodegenConfigurator setResolveFully(boolean resolveFully) {
431
431
}
432
432
433
433
public String loadSpecContent (String location , List <AuthorizationValue > auths ) throws Exception {
434
- location = location . replaceAll ( " \\ \\ " , "/" );
434
+ location = sanitizeSpecificationUrl ( location );
435
435
String data = "" ;
436
436
if (location .toLowerCase ().startsWith ("http" )) {
437
437
data = RemoteUrl .urlToString (location , auths );
@@ -453,6 +453,10 @@ public String loadSpecContent(String location, List<AuthorizationValue> auths) t
453
453
return data ;
454
454
}
455
455
456
+ private String sanitizeSpecificationUrl (String specificationUrl ) {
457
+ return specificationUrl .replaceAll ("\\ \\ " ,"/" );
458
+ }
459
+
456
460
public ClientOptInput toClientOptInput () {
457
461
458
462
Validate .notEmpty (lang , "language must be specified" );
@@ -494,36 +498,37 @@ public ClientOptInput toClientOptInput() {
494
498
LOGGER .debug ("getClientOptInput - parsed inputSpec" );
495
499
} else {
496
500
String specContent = null ;
501
+ String sanitizedSpecificationUrl = sanitizeSpecificationUrl (inputSpecURL );
497
502
try {
498
- specContent = loadSpecContent (inputSpecURL , authorizationValues );
503
+ specContent = loadSpecContent (sanitizedSpecificationUrl , authorizationValues );
499
504
} catch (Exception e ) {
500
- String msg = "Unable to read URL: " + inputSpecURL ;
505
+ String msg = "Unable to read URL: " + sanitizedSpecificationUrl ;
501
506
LOGGER .error (msg , e );
502
507
throw new IllegalArgumentException (msg );
503
508
}
504
509
505
510
if (StringUtils .isBlank (specContent )) {
506
- String msg = "Empty content found in URL: " + inputSpecURL ;
511
+ String msg = "Empty content found in URL: " + sanitizedSpecificationUrl ;
507
512
LOGGER .error (msg );
508
513
throw new IllegalArgumentException (msg );
509
514
}
510
515
config .setInputSpec (specContent );
511
- config .setInputURL (inputSpecURL );
516
+ config .setInputURL (sanitizedSpecificationUrl );
512
517
ParseOptions options = new ParseOptions ();
513
518
options .setResolve (true );
514
519
options .setResolveFully (resolveFully );
515
520
options .setFlatten (true );
516
521
options .setFlattenComposedSchemas (flattenInlineSchema );
517
- SwaggerParseResult result = new OpenAPIParser ().readLocation (inputSpecURL , authorizationValues , options );
522
+ SwaggerParseResult result = new OpenAPIParser ().readLocation (sanitizedSpecificationUrl , authorizationValues , options );
518
523
OpenAPI openAPI = result .getOpenAPI ();
519
- LOGGER .debug ("getClientOptInput - parsed inputSpecURL " + inputSpecURL );
524
+ LOGGER .debug ("getClientOptInput - parsed inputSpecURL " + sanitizedSpecificationUrl );
520
525
input .opts (new ClientOpts ())
521
526
.openAPI (openAPI );
522
527
523
528
if (config .needsUnflattenedSpec ()) {
524
529
ParseOptions optionsUnflattened = new ParseOptions ();
525
530
optionsUnflattened .setResolve (true );
526
- SwaggerParseResult resultUnflattened = new OpenAPIParser ().readLocation (inputSpecURL , authorizationValues , optionsUnflattened );
531
+ SwaggerParseResult resultUnflattened = new OpenAPIParser ().readLocation (sanitizedSpecificationUrl , authorizationValues , optionsUnflattened );
527
532
OpenAPI openAPIUnflattened = resultUnflattened .getOpenAPI ();
528
533
config .setUnflattenedOpenAPI (openAPIUnflattened );
529
534
}
0 commit comments