1212import io .swagger .models .Swagger ;
1313import io .swagger .models .auth .UrlMatcher ;
1414import io .swagger .parser .SwaggerParser ;
15+ import io .swagger .parser .util .ParseOptions ;
1516import io .swagger .v3 .core .util .Json ;
1617import org .apache .commons .lang3 .StringUtils ;
1718import org .apache .commons .lang3 .Validate ;
@@ -108,15 +109,26 @@ public static io.swagger.codegen.ClientOptInput getClientOptInputV2(GenerationRe
108109 }
109110 LOGGER .debug ("getClientOptInputV2 - processed auth" );
110111
112+ CodegenConfig codegenConfig =null ;
113+ try {
114+ codegenConfig = CodegenConfigLoader .forName (lang );
115+ } catch (RuntimeException e ) {
116+ throw new BadRequestException ("Unsupported target " + lang + " supplied" );
117+ }
118+ ParseOptions parseOptions = new ParseOptions ();
119+ parseOptions .setResolve (true );
120+ if (codegenConfig .isUsingFlattenSpec () && !Boolean .FALSE .equals (generationRequest .getOptions ().isUsingFlattenSpecForV2 ())) {
121+ parseOptions .setFlatten (true );
122+ }
111123 Swagger swagger ;
112124 if (StringUtils .isBlank (inputSpec )) {
113125 if (inputSpecURL != null ) {
114126 if (!authorizationValues .isEmpty ()) {
115127 swagger =
116128 new SwaggerParser ().read (inputSpecURL , authorizationValues ,
117- true );
129+ parseOptions );
118130 } else {
119- swagger = new SwaggerParser ().read (inputSpecURL );
131+ swagger = new SwaggerParser ().read (inputSpecURL , null , parseOptions );
120132 }
121133 } else {
122134 throw new BadRequestException ("No swagger specification was supplied" );
@@ -126,9 +138,9 @@ public static io.swagger.codegen.ClientOptInput getClientOptInputV2(GenerationRe
126138 try {
127139 JsonNode node = io .swagger .util .Json .mapper ().readTree (inputSpec );
128140 if (!authorizationValues .isEmpty ()) {
129- swagger = new SwaggerParser ().read (node , authorizationValues , true );
141+ swagger = new SwaggerParser ().read (node , authorizationValues , parseOptions );
130142 } else {
131- swagger = new SwaggerParser ().read (node , true );
143+ swagger = new SwaggerParser ().read (node , null , parseOptions );
132144 }
133145 } catch (Exception e ) {
134146 LOGGER .error ("Exception parsing input spec" , e );
@@ -144,12 +156,6 @@ public static io.swagger.codegen.ClientOptInput getClientOptInputV2(GenerationRe
144156 io .swagger .codegen .ClientOptInput clientOptInput = new io .swagger .codegen .ClientOptInput ();
145157 ClientOpts clientOpts = new ClientOpts ();
146158
147- CodegenConfig codegenConfig =null ;
148- try {
149- codegenConfig = CodegenConfigLoader .forName (lang );
150- } catch (RuntimeException e ) {
151- throw new BadRequestException ("Unsupported target " + lang + " supplied" );
152- }
153159 codegenConfig .setOutputDir (generationRequest .getOptions ().getOutputDir ());
154160 codegenConfig .setInputSpec (inputSpec );
155161 if (isNotEmpty (options .getApiPackage ())) {
0 commit comments