From 8de0b58350256c8c2f627743a962e3b6b7400ff5 Mon Sep 17 00:00:00 2001 From: frantuma Date: Wed, 30 Oct 2019 13:55:28 +0100 Subject: [PATCH] [openapi, openapi-yaml] - option not to flatten resolved spec, refactor --- .../io/swagger/codegen/v3/CodegenConfig.java | 4 ++++ .../codegen/v3/config/CodegenConfigurator.java | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/v3/CodegenConfig.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/v3/CodegenConfig.java index 14f5ce6c581..f3836c59681 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/v3/CodegenConfig.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/v3/CodegenConfig.java @@ -233,4 +233,8 @@ public interface CodegenConfig { List getLanguageArguments(); void setLanguageArguments(List codegenArguments); + + boolean needsUnflattenedSpec(); + + void setUnflattenedOpenAPI(OpenAPI unflattenedOpenAPI); } diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/v3/config/CodegenConfigurator.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/v3/config/CodegenConfigurator.java index b050c882d6a..1ffd14384c3 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/v3/config/CodegenConfigurator.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/v3/config/CodegenConfigurator.java @@ -468,6 +468,14 @@ public ClientOptInput toClientOptInput() { SwaggerParseResult result = new OpenAPIParser().readContents(inputSpec, authorizationValues, options); OpenAPI openAPI = result.getOpenAPI(); + if (config.needsUnflattenedSpec()) { + ParseOptions optionsUnflattened = new ParseOptions(); + optionsUnflattened.setResolve(true); + SwaggerParseResult resultUnflattened = new OpenAPIParser().readContents(inputSpec, authorizationValues, optionsUnflattened); + OpenAPI openAPIUnflattened = resultUnflattened.getOpenAPI(); + config.setUnflattenedOpenAPI(openAPIUnflattened); + } + input.opts(new ClientOpts()) .openAPI(openAPI); @@ -497,6 +505,15 @@ public ClientOptInput toClientOptInput() { LOGGER.debug("getClientOptInput - parsed inputSpecURL " + inputSpecURL); input.opts(new ClientOpts()) .openAPI(openAPI); + + if (config.needsUnflattenedSpec()) { + ParseOptions optionsUnflattened = new ParseOptions(); + optionsUnflattened.setResolve(true); + SwaggerParseResult resultUnflattened = new OpenAPIParser().readLocation(inputSpecURL, authorizationValues, optionsUnflattened); + OpenAPI openAPIUnflattened = resultUnflattened.getOpenAPI(); + config.setUnflattenedOpenAPI(openAPIUnflattened); + } + } config.setOutputDir(outputDir);