From 8e91b8c62a1710ae4924b9c5f931c549f40d4e5a Mon Sep 17 00:00:00 2001 From: Hemant Zope <42613258+zhemant@users.noreply.github.com> Date: Thu, 9 May 2019 09:31:58 +0200 Subject: [PATCH] [core] add support for model as query params (#2489) * add support for model as query params * add logging incase of multiple schemas are present --- .../openapitools/codegen/DefaultCodegen.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java index 0762c91d0a..8fd12a5faf 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java @@ -2931,8 +2931,22 @@ public class DefaultCodegen implements CodegenConfig { codegenParameter.vendorExtensions.putAll(parameter.getExtensions()); } - if (parameter.getSchema() != null) { - Schema parameterSchema = ModelUtils.unaliasSchema(this.openAPI, parameter.getSchema()); + Schema s; + if(parameter.getSchema() != null) { + s = parameter.getSchema(); + } else if (parameter.getContent() != null) { + Content content = parameter.getContent(); + if (content.size() > 1) { + LOGGER.warn("Multiple schemas found in content, returning only the first one"); + } + MediaType mediaType = content.values().iterator().next(); + s = mediaType.getSchema(); + } else { + s = null; + } + + if (s != null) { + Schema parameterSchema = ModelUtils.unaliasSchema(this.openAPI, s); if (parameterSchema == null) { LOGGER.warn("warning! Schema not found for parameter \"" + parameter.getName() + "\", using String"); parameterSchema = new StringSchema().description("//TODO automatically added by openapi-generator due to missing type definition.");