diff --git a/README.md b/README.md index 8e21254fe81..ec9b3822b97 100644 --- a/README.md +++ b/README.md @@ -567,6 +567,7 @@ Here are some companies/projects (alphabetical order) using OpenAPI Generator in - [Adaptant Solutions AG](https://www.adaptant.io/) - [Agoda](https://www.agoda.com/) +- [Allianz](https://www.allianz.com) - [Angular.Schule](https://angular.schule/) - [Australia and New Zealand Banking Group (ANZ)](http://www.anz.com/) - [ASKUL](https://www.askul.co.jp) diff --git a/bin/ci/java-rest-assured-jackson.json b/bin/ci/java-rest-assured-jackson.json new file mode 100644 index 00000000000..1ff56d80ea8 --- /dev/null +++ b/bin/ci/java-rest-assured-jackson.json @@ -0,0 +1,16 @@ +{ + "!include": "bin/java-petstore-rest-assured-jackson.json", + "generatorName": "java", + "inputSpec": "modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml", + "outputDir": "samples/client/petstore/java/rest-assured-jackson", + "templateDir": "modules/openapi-generator/src/main/resources/Java/libraries/rest-assured", + "additionalProperties": { + "hideGenerationTimestamp": true, + "booleanGetterPrefix": "is", + "java8": "true", + "dateLibrary": "java8", + "serializationLibrary": "jackson", + "useBeanValidation": "true", + "performBeanValidation": "true" + } +} diff --git a/bin/csharp-dotnet2-petstore.sh b/bin/csharp-dotnet2-petstore.sh index d3641ed1ce5..c953170bfaa 100755 --- a/bin/csharp-dotnet2-petstore.sh +++ b/bin/csharp-dotnet2-petstore.sh @@ -27,6 +27,6 @@ fi # if you've executed sbt assembly previously it will use that instead. export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties" -ags="generate -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g csharp-dotnet2 -o samples/client/petstore/csharp-dotnet2/OpenAPIClientTest/Lib/OpenAPIClient --additional-properties hideGenerationTimestamp=true $@" +ags="generate -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g csharp-dotnet2 -t modules/openapi-generator/src/main/resources/csharp-dotnet2 -o samples/client/petstore/csharp-dotnet2/OpenAPIClientTest/Lib/OpenAPIClient --additional-properties hideGenerationTimestamp=true $@" java $JAVA_OPTS -jar $executable $ags diff --git a/bin/html2-petstore.sh b/bin/html2-petstore.sh index 3b82165d103..d125551e133 100755 --- a/bin/html2-petstore.sh +++ b/bin/html2-petstore.sh @@ -27,6 +27,6 @@ fi # if you've executed sbt assembly previously it will use that instead. export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties" -ags="generate -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g html2 -o samples/documentation/html2 --additional-properties hideGenerationTimestamp=true $@" +ags="generate -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g html2 -o samples/documentation/html2 -t modules/openapi-generator/src/main/resources/htmlDocs2/ --additional-properties hideGenerationTimestamp=true $@" java $JAVA_OPTS -jar $executable $ags diff --git a/bin/java-petstore-all.sh b/bin/java-petstore-all.sh index 6eed10ebe38..05b50835c99 100755 --- a/bin/java-petstore-all.sh +++ b/bin/java-petstore-all.sh @@ -12,6 +12,7 @@ ./bin/java-petstore-okhttp-gson-parcelable.sh ./bin/java-petstore-okhttp-gson.sh ./bin/java-petstore-rest-assured.sh +./bin/java-petstore-rest-assured-jackson.sh ./bin/java-petstore-resteasy.sh ./bin/java-petstore-resttemplate-withxml.sh ./bin/java-petstore-resttemplate.sh diff --git a/bin/java-petstore-rest-assured-jackson.json b/bin/java-petstore-rest-assured-jackson.json new file mode 100644 index 00000000000..d6e6035df80 --- /dev/null +++ b/bin/java-petstore-rest-assured-jackson.json @@ -0,0 +1,4 @@ +{ + "library": "rest-assured", + "artifactId": "petstore-rest-assured-jackson" +} diff --git a/bin/java-petstore-rest-assured-jackson.sh b/bin/java-petstore-rest-assured-jackson.sh new file mode 100755 index 00000000000..eeffe6aacee --- /dev/null +++ b/bin/java-petstore-rest-assured-jackson.sh @@ -0,0 +1,36 @@ +#!/bin/sh + +SCRIPT="$0" +echo "# START SCRIPT: $SCRIPT" + +while [ -h "$SCRIPT" ] ; do + ls=`ls -ld "$SCRIPT"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + SCRIPT="$link" + else + SCRIPT=`dirname "$SCRIPT"`/"$link" + fi +done + +if [ ! -d "${APP_DIR}" ]; then + APP_DIR=`dirname "$SCRIPT"`/.. + APP_DIR=`cd "${APP_DIR}"; pwd` +fi + +executable="./modules/openapi-generator-cli/target/openapi-generator-cli.jar" +target_dir="./samples/client/petstore/java/rest-assured-jackson/" + +if [ ! -f "$executable" ] +then + mvn -B clean package +fi + +# if you've executed sbt assembly previously it will use that instead. +export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties" +args="generate -t modules/openapi-generator/src/main/resources/Java/libraries/rest-assured -i modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -g java -c bin/java-petstore-rest-assured-jackson.json -o ${target_dir} --additional-properties hideGenerationTimestamp=true --additional-properties useBeanValidation=true --additional-properties performBeanValidation=true --additional-properties booleanGetterPrefix=is --additional-properties java8=true --additional-properties dateLibrary=java8 --additional-properties serializationLibrary=jackson $@" + +echo "Removing ${target_dir}" +rm -rf "${target_dir}" + +java $JAVA_OPTS -jar $executable $args diff --git a/bin/windows/csharp-dotnet2-petstore.bat b/bin/windows/csharp-dotnet2-petstore.bat index 6951617bed9..f5bc77332e6 100755 --- a/bin/windows/csharp-dotnet2-petstore.bat +++ b/bin/windows/csharp-dotnet2-petstore.bat @@ -5,6 +5,6 @@ If Not Exist %executable% ( ) REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M -set ags=generate -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g csharp-dotnet2 -o samples/client/petstore/csharp-dotnet2/OpenApiClientTest/Lib/OpenApiClient --additional-properties hideGenerationTimestamp=true +set ags=generate -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g csharp-dotnet2 -t modules/openapi-generator/src/main/resources/csharp-dotnet2 -o samples/client/petstore/csharp-dotnet2/OpenApiClientTest/Lib/OpenApiClient --additional-properties hideGenerationTimestamp=true java %JAVA_OPTS% -jar %executable% %ags% diff --git a/bin/windows/java-petstore-all.bat b/bin/windows/java-petstore-all.bat index dd357cfd56d..816919bb8fd 100644 --- a/bin/windows/java-petstore-all.bat +++ b/bin/windows/java-petstore-all.bat @@ -20,4 +20,5 @@ call .\bin\windows\java-petstore-webclient.bat call .\bin\windows\java-petstore-resteasy.bat call .\bin\windows\java-petstore-google-api-client.bat call .\bin\windows\java-petstore-rest-assured.bat +call .\bin\windows\java-petstore-rest-assured-jackson.bat call .\bin\windows\java-petstore-vertx.bat diff --git a/bin/windows/java-petstore-rest-assured-jackson.bat b/bin/windows/java-petstore-rest-assured-jackson.bat new file mode 100644 index 00000000000..8104df8b771 --- /dev/null +++ b/bin/windows/java-petstore-rest-assured-jackson.bat @@ -0,0 +1,10 @@ +set executable=.\modules\openapi-generator-cli\target\openapi-generator-cli.jar + +If Not Exist %executable% ( + mvn clean package +) + +REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M +set ags=generate -t modules\openapi-generator\src\main\resources\Java\libraries\rest-assured -i modules\openapi-generator\src\test\resources\2_0\petstore-with-fake-endpoints-models-for-testing.yaml -g java -c bin\java-petstore-rest-assured-jackson.json -o samples\client\petstore\java\rest-assured-jackson --additional-properties hideGenerationTimestamp=true,booleanGetterPrefix=is,java8=true,dateLibrary=java8,serializationLibrary=jackson,useBeanValidation=true,performBeanValidation=true, + +java %JAVA_OPTS% -jar %executable% %ags% diff --git a/modules/openapi-generator-gradle-plugin/src/main/kotlin/org/openapitools/generator/gradle/plugin/tasks/GenerateTask.kt b/modules/openapi-generator-gradle-plugin/src/main/kotlin/org/openapitools/generator/gradle/plugin/tasks/GenerateTask.kt index 93087a986e1..f273d12427a 100644 --- a/modules/openapi-generator-gradle-plugin/src/main/kotlin/org/openapitools/generator/gradle/plugin/tasks/GenerateTask.kt +++ b/modules/openapi-generator-gradle-plugin/src/main/kotlin/org/openapitools/generator/gradle/plugin/tasks/GenerateTask.kt @@ -640,7 +640,7 @@ open class GenerateTask : DefaultTask() { DefaultGenerator().opts(clientOptInput).generate() - out.println("Successfully generated code to $outputDir") + out.println("Successfully generated code to ${outputDir.get()}") } catch (e: RuntimeException) { throw GradleException("Code generation failed.", e) } diff --git a/modules/openapi-generator-maven-plugin/src/main/java/org/openapitools/codegen/plugin/CodeGenMojo.java b/modules/openapi-generator-maven-plugin/src/main/java/org/openapitools/codegen/plugin/CodeGenMojo.java index aa386a2995f..0d33707e32d 100644 --- a/modules/openapi-generator-maven-plugin/src/main/java/org/openapitools/codegen/plugin/CodeGenMojo.java +++ b/modules/openapi-generator-maven-plugin/src/main/java/org/openapitools/codegen/plugin/CodeGenMojo.java @@ -70,7 +70,7 @@ import com.google.common.io.Files; * Goal which generates client/server code from a OpenAPI json/yaml definition. */ @SuppressWarnings({"unused", "MismatchedQueryAndUpdateOfCollection"}) -@Mojo(name = "generate", defaultPhase = LifecyclePhase.GENERATE_SOURCES) +@Mojo(name = "generate", defaultPhase = LifecyclePhase.GENERATE_SOURCES, threadSafe = true) public class CodeGenMojo extends AbstractMojo { private static final Logger LOGGER = LoggerFactory.getLogger(CodeGenMojo.class); diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenModel.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenModel.java index c0519355cd5..16a296f84e1 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenModel.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenModel.java @@ -74,7 +74,7 @@ public class CodegenModel implements IJsonSchemaValidationProperties { public Set allMandatory = new TreeSet(); // with parent's required properties public Set imports = new TreeSet(); - public boolean hasVars, emptyVars, hasMoreModels, hasEnums, isEnum, isNullable, hasRequired, hasOptional, isArrayModel, hasChildren, isMapModel; + public boolean hasVars, emptyVars, hasMoreModels, hasEnums, isEnum, isNullable, hasRequired, hasOptional, isArrayModel, hasChildren, isMapModel, isDeprecated; public boolean hasOnlyReadOnly = true; // true if all properties are read-only public ExternalDocumentation externalDocumentation; @@ -543,6 +543,7 @@ public class CodegenModel implements IJsonSchemaValidationProperties { isArrayModel == that.isArrayModel && hasChildren == that.hasChildren && isMapModel == that.isMapModel && + isDeprecated == that.isDeprecated && hasOnlyReadOnly == that.hasOnlyReadOnly && getUniqueItems() == that.getUniqueItems() && getExclusiveMinimum() == that.getExclusiveMinimum() && @@ -609,7 +610,7 @@ public class CodegenModel implements IJsonSchemaValidationProperties { getVars(), getAllVars(), getRequiredVars(), getOptionalVars(), getReadOnlyVars(), getReadWriteVars(), getParentVars(), getAllowableValues(), getMandatory(), getAllMandatory(), getImports(), hasVars, isEmptyVars(), hasMoreModels, hasEnums, isEnum, isNullable, hasRequired, hasOptional, isArrayModel, - hasChildren, isMapModel, hasOnlyReadOnly, getExternalDocumentation(), getVendorExtensions(), + hasChildren, isMapModel, isDeprecated, hasOnlyReadOnly, getExternalDocumentation(), getVendorExtensions(), getAdditionalPropertiesType(), getMaxProperties(), getMinProperties(), getUniqueItems(), getMaxItems(), getMinItems(), getMaxLength(), getMinLength(), getExclusiveMinimum(), getExclusiveMaximum(), getMinimum(), getMaximum(), getPattern(), getMultipleOf()); @@ -673,6 +674,7 @@ public class CodegenModel implements IJsonSchemaValidationProperties { sb.append(", isArrayModel=").append(isArrayModel); sb.append(", hasChildren=").append(hasChildren); sb.append(", isMapModel=").append(isMapModel); + sb.append(", isDeprecated=").append(isDeprecated); sb.append(", hasOnlyReadOnly=").append(hasOnlyReadOnly); sb.append(", externalDocumentation=").append(externalDocumentation); sb.append(", vendorExtensions=").append(vendorExtensions); 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 757fd03ff3d..cf2e8d2e931 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 @@ -2134,6 +2134,10 @@ public class DefaultCodegen implements CodegenConfig { || isAliasOfSimpleTypes(schema)); // check if the unaliased schema is an alias of simple OAS types m.discriminator = createDiscriminator(name, schema); + if (schema.getDeprecated() != null) { + m.isDeprecated = schema.getDeprecated(); + } + if (schema.getXml() != null) { m.xmlPrefix = schema.getXml().getPrefix(); m.xmlNamespace = schema.getXml().getNamespace(); @@ -5539,6 +5543,8 @@ public class DefaultCodegen implements CodegenConfig { setParameterNullable(codegenParameter, codegenProperty); } + addJsonSchemaForBodyRequestInCaseItsNotPresent(codegenParameter, body); + // set the parameter's example value // should be overridden by lang codegen setParameterExampleValue(codegenParameter, body); @@ -5546,6 +5552,11 @@ public class DefaultCodegen implements CodegenConfig { return codegenParameter; } + private void addJsonSchemaForBodyRequestInCaseItsNotPresent(CodegenParameter codegenParameter, RequestBody body){ + if(codegenParameter.jsonSchema == null) + codegenParameter.jsonSchema = Json.pretty(body); + } + protected void addOption(String key, String description, String defaultValue) { CliOption option = new CliOption(key, description); if (defaultValue != null) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/InlineModelResolver.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/InlineModelResolver.java index 32f6023d695..c1f26c8ad77 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/InlineModelResolver.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/InlineModelResolver.java @@ -332,11 +332,11 @@ public class InlineModelResolver { * Flattens properties of inline object schemas that belong to a composed schema into a * single flat list of properties. This is useful to generate a single or multiple * inheritance model. - * + * * In the example below, codegen may generate a 'Dog' class that extends from the * generated 'Animal' class. 'Dog' has additional properties 'name', 'age' and 'breed' that * are flattened as a single list of properties. - * + * * Dog: * allOf: * - $ref: '#/components/schemas/Animal' @@ -350,7 +350,7 @@ public class InlineModelResolver { * properties: * breed: * type: string - * + * * @param openAPI the OpenAPI document * @param key a unique name ofr the composed schema. * @param children the list of nested schemas within a composed schema (allOf, anyOf, oneOf). @@ -362,8 +362,10 @@ public class InlineModelResolver { ListIterator listIterator = children.listIterator(); while (listIterator.hasNext()) { Schema component = listIterator.next(); - if (component instanceof ObjectSchema) { - ObjectSchema op = (ObjectSchema) component; + if (component instanceof ObjectSchema || // for inline schema with type:object + (component != null && component.getProperties() != null && + !component.getProperties().isEmpty())) { // for inline schema without type:object + Schema op = component; if (op.get$ref() == null && op.getProperties() != null && op.getProperties().size() > 0) { // If a `title` attribute is defined in the inline schema, codegen uses it to name the // inline schema. Otherwise, we'll use the default naming such as InlineObject1, etc. @@ -390,6 +392,8 @@ public class InlineModelResolver { listIterator.set(schema); } } + } else { + // likely a reference to schema (not inline schema) } } } @@ -465,7 +469,7 @@ public class InlineModelResolver { * with underscores * * e.g. io.schema.User_name => io_schema_User_name - * + * * @param title String title field in the schema if present * @param key String model name * @@ -607,7 +611,7 @@ public class InlineModelResolver { } } - private Schema modelFromProperty(ObjectSchema object, String path) { + private Schema modelFromProperty(Schema object, String path) { String description = object.getDescription(); String example = null; Object obj = object.getExample(); diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/config/CodegenConfigurator.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/config/CodegenConfigurator.java index a60f824278b..840790ed4c8 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/config/CodegenConfigurator.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/config/CodegenConfigurator.java @@ -79,69 +79,74 @@ public class CodegenConfigurator { public static CodegenConfigurator fromFile(String configFile, Module... modules) { if (isNotEmpty(configFile)) { - ObjectMapper mapper; + DynamicSettings settings = readDynamicSettings(configFile, modules); - if (FilenameUtils.isExtension(configFile, new String[]{"yml", "yaml"})) { - mapper = Yaml.mapper(); - } else { - mapper = Json.mapper(); + CodegenConfigurator configurator = new CodegenConfigurator(); + + GeneratorSettings generatorSettings = settings.getGeneratorSettings(); + WorkflowSettings workflowSettings = settings.getWorkflowSettings(); + + // We copy "cached" properties into configurator so it is appropriately configured with all settings in external files. + // FIXME: target is to eventually move away from CodegenConfigurator properties except gen/workflow settings. + configurator.generatorName = generatorSettings.getGeneratorName(); + configurator.inputSpec = workflowSettings.getInputSpec(); + configurator.templatingEngineName = workflowSettings.getTemplatingEngineName(); + if (workflowSettings.getSystemProperties() != null) { + configurator.systemProperties.putAll(workflowSettings.getSystemProperties()); + } + if(generatorSettings.getInstantiationTypes() != null) { + configurator.instantiationTypes.putAll(generatorSettings.getInstantiationTypes()); + } + if(generatorSettings.getTypeMappings() != null) { + configurator.typeMappings.putAll(generatorSettings.getTypeMappings()); + } + if(generatorSettings.getAdditionalProperties() != null) { + configurator.additionalProperties.putAll(generatorSettings.getAdditionalProperties()); + } + if(generatorSettings.getImportMappings() != null) { + configurator.importMappings.putAll(generatorSettings.getImportMappings()); + } + if(generatorSettings.getLanguageSpecificPrimitives() != null) { + configurator.languageSpecificPrimitives.addAll(generatorSettings.getLanguageSpecificPrimitives()); + } + if(generatorSettings.getReservedWordMappings() != null) { + configurator.reservedWordMappings.putAll(generatorSettings.getReservedWordMappings()); + } + if(generatorSettings.getServerVariables() != null) { + configurator.serverVariables.putAll(generatorSettings.getServerVariables()); } - if (modules != null && modules.length > 0) { - mapper.registerModules(modules); - } + configurator.generatorSettingsBuilder = GeneratorSettings.newBuilder(generatorSettings); + configurator.workflowSettingsBuilder = WorkflowSettings.newBuilder(workflowSettings); - mapper.registerModule(new GuavaModule()); - - try { - DynamicSettings settings = mapper.readValue(new File(configFile), DynamicSettings.class); - CodegenConfigurator configurator = new CodegenConfigurator(); - - GeneratorSettings generatorSettings = settings.getGeneratorSettings(); - WorkflowSettings workflowSettings = settings.getWorkflowSettings(); - - // We copy "cached" properties into configurator so it is appropriately configured with all settings in external files. - // FIXME: target is to eventually move away from CodegenConfigurator properties except gen/workflow settings. - configurator.generatorName = generatorSettings.getGeneratorName(); - configurator.inputSpec = workflowSettings.getInputSpec(); - configurator.templatingEngineName = workflowSettings.getTemplatingEngineName(); - if (workflowSettings.getSystemProperties() != null) { - configurator.systemProperties.putAll(workflowSettings.getSystemProperties()); - } - if(generatorSettings.getInstantiationTypes() != null) { - configurator.instantiationTypes.putAll(generatorSettings.getInstantiationTypes()); - } - if(generatorSettings.getTypeMappings() != null) { - configurator.typeMappings.putAll(generatorSettings.getTypeMappings()); - } - if(generatorSettings.getAdditionalProperties() != null) { - configurator.additionalProperties.putAll(generatorSettings.getAdditionalProperties()); - } - if(generatorSettings.getImportMappings() != null) { - configurator.importMappings.putAll(generatorSettings.getImportMappings()); - } - if(generatorSettings.getLanguageSpecificPrimitives() != null) { - configurator.languageSpecificPrimitives.addAll(generatorSettings.getLanguageSpecificPrimitives()); - } - if(generatorSettings.getReservedWordMappings() != null) { - configurator.reservedWordMappings.putAll(generatorSettings.getReservedWordMappings()); - } - if(generatorSettings.getServerVariables() != null) { - configurator.serverVariables.putAll(generatorSettings.getServerVariables()); - } - - configurator.generatorSettingsBuilder = GeneratorSettings.newBuilder(generatorSettings); - configurator.workflowSettingsBuilder = WorkflowSettings.newBuilder(workflowSettings); - - return configurator; - } catch (IOException ex) { - LOGGER.error(ex.getMessage()); - throw new RuntimeException("Unable to deserialize config file: " + configFile); - } + return configurator; } return null; } + private static DynamicSettings readDynamicSettings(String configFile, Module... modules) { + ObjectMapper mapper; + + if (FilenameUtils.isExtension(configFile.toLowerCase(Locale.ROOT), new String[]{"yml", "yaml"})) { + mapper = Yaml.mapper().copy(); + } else { + mapper = Json.mapper().copy(); + } + + if (modules != null && modules.length > 0) { + mapper.registerModules(modules); + } + + mapper.registerModule(new GuavaModule()); + + try { + return mapper.readValue(new File(configFile), DynamicSettings.class); + } catch (IOException ex) { + LOGGER.error(ex.getMessage()); + throw new RuntimeException("Unable to deserialize config file: " + configFile); + } + } + public CodegenConfigurator addServerVariable(String key, String value) { this.serverVariables.put(key, value); generatorSettingsBuilder.withServerVariable(key, value); diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PowerShellExperimentalClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PowerShellExperimentalClientCodegen.java index 2b5ae61765c..5896ee99efe 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PowerShellExperimentalClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PowerShellExperimentalClientCodegen.java @@ -19,6 +19,7 @@ package org.openapitools.codegen.languages; import io.swagger.v3.oas.models.media.ArraySchema; import io.swagger.v3.oas.models.media.Schema; import org.apache.commons.io.FilenameUtils; +import org.apache.commons.lang3.StringEscapeUtils; import org.apache.commons.lang3.StringUtils; import org.openapitools.codegen.*; import org.openapitools.codegen.meta.GeneratorMetadata; @@ -622,6 +623,28 @@ public class PowerShellExperimentalClientCodegen extends DefaultCodegen implemen supportingFiles.add(new SupportingFile("appveyor.mustache", "", "appveyor.yml")); } + @SuppressWarnings("static-method") + @Override + public String escapeText(String input) { + + if (input == null) { + return input; + } + + // remove \t, \n, \r + // replace \ with \\ + // replace " with \" + // outter unescape to retain the original multi-byte characters + // finally escalate characters avoiding code injection + return escapeUnsafeCharacters( + StringEscapeUtils.unescapeJava( + StringEscapeUtils.escapeJava(input) + .replace("\\/", "/")) + .replaceAll("[\\t\\n\\r]", " ") + .replace("\\", "\\\\") + .replace("\"", "\"\"")); + } + @Override public String escapeUnsafeCharacters(String input) { return input.replace("#>", "#_>").replace("<#", "<_#"); diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ScalaAkkaHttpServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ScalaAkkaHttpServerCodegen.java index 4b98b531b26..d8c33f499da 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ScalaAkkaHttpServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ScalaAkkaHttpServerCodegen.java @@ -409,6 +409,7 @@ public class ScalaAkkaHttpServerCodegen extends AbstractScalaCodegen implements entityMarshallerTypes.add(marshaller); operationSpecificMarshallers.add(marshaller); } + response.vendorExtensions.put("x-empty-response", response.baseType == null && response.message == null); response.vendorExtensions.put("x-is-default", response.code.equals("0")); } op.vendorExtensions.put("x-specific-marshallers", operationSpecificMarshallers); diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptAxiosClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptAxiosClientCodegen.java index a441027bff0..023db027014 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptAxiosClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptAxiosClientCodegen.java @@ -110,6 +110,7 @@ public class TypeScriptAxiosClientCodegen extends AbstractTypeScriptClientCodege supportingFiles.add(new SupportingFile("configuration.mustache", "", "configuration.ts")); supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh")); supportingFiles.add(new SupportingFile("gitignore", "", ".gitignore")); + supportingFiles.add(new SupportingFile("npmignore", "", ".npmignore")); if (additionalProperties.containsKey(SEPARATE_MODELS_AND_API)) { boolean separateModelsAndApi = Boolean.parseBoolean(additionalProperties.get(SEPARATE_MODELS_AND_API).toString()); diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java index e55479e4a31..6dbefe36db4 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java @@ -1104,9 +1104,9 @@ public class ModelUtils { public static Map> getChildrenMap(OpenAPI openAPI) { Map allSchemas = getSchemas(openAPI); - // FIXME: The collect here will throw NPE if a spec document has only a single oneOf hierarchy. Map>> groupedByParent = allSchemas.entrySet().stream() .filter(entry -> isComposedSchema(entry.getValue())) + .filter(entry -> getParentName((ComposedSchema) entry.getValue(), allSchemas)!=null) .collect(Collectors.groupingBy(entry -> getParentName((ComposedSchema) entry.getValue(), allSchemas))); return groupedByParent.entrySet().stream() @@ -1165,14 +1165,6 @@ public class ModelUtils { int nullSchemaChildrenCount = 0; boolean hasAmbiguousParents = false; List refedWithoutDiscriminator = new ArrayList<>(); - String schemaName = ""; - for (String thisSchemaName : allSchemas.keySet()) { - Schema sc = allSchemas.get(thisSchemaName); - if (isComposedSchema(sc) && (ComposedSchema) sc == composedSchema) { - schemaName = thisSchemaName; - break; - } - } if (interfaces != null && !interfaces.isEmpty()) { for (Schema schema : interfaces) { @@ -1189,10 +1181,7 @@ public class ModelUtils { } else { // not a parent since discriminator.propertyName is not set hasAmbiguousParents = true; - boolean isNotExtractedInlineSchema = !parentName.equals(schemaName+"_allOf"); - if (isNotExtractedInlineSchema) { - refedWithoutDiscriminator.add(parentName); - } + refedWithoutDiscriminator.add(parentName); } } else { // not a ref, doing nothing, except counting the number of times the 'null' type @@ -1236,7 +1225,6 @@ public class ModelUtils { public static List getAllParentsName(ComposedSchema composedSchema, Map allSchemas, boolean includeAncestors) { List interfaces = getInterfaces(composedSchema); List names = new ArrayList(); - List refedWithoutDiscriminator = new ArrayList<>(); if (interfaces != null && !interfaces.isEmpty()) { for (Schema schema : interfaces) { @@ -1255,7 +1243,6 @@ public class ModelUtils { } } else { // not a parent since discriminator.propertyName is not set - refedWithoutDiscriminator.add(parentName); } } else { // not a ref, doing nothing @@ -1263,10 +1250,11 @@ public class ModelUtils { } } - if (names.size() == 0 && refedWithoutDiscriminator.size() == 1) { - LOGGER.warn("[deprecated] inheritance without use of 'discriminator.propertyName' is deprecated " + - "and will be removed in a future release. Generating model for {}. Title: {}", composedSchema.getName(), composedSchema.getTitle()); - return refedWithoutDiscriminator; + // ensure `allParents` always includes `parent` + // this is more robust than keeping logic in getParentName() and getAllParentsName() in sync + String parentName = getParentName(composedSchema, allSchemas); + if (parentName != null && !names.contains(parentName)) { + names.add(parentName); } return names; diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/rest-assured/build.gradle.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/rest-assured/build.gradle.mustache index 640ad1cd18c..0868a2aa7c0 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/rest-assured/build.gradle.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/rest-assured/build.gradle.mustache @@ -101,7 +101,10 @@ ext { {{#jackson}} jackson_version = "2.10.3" jackson_databind_version = "2.10.3" - jackson_databind_nullable_version = 0.2.1 + jackson_databind_nullable_version = "0.2.1" + {{#threetenbp}} + jackson_threetenbp_version = "2.10.0" + {{/threetenbp}} {{/jackson}} {{#gson}} gson_version = "2.8.6" @@ -119,13 +122,25 @@ ext { dependencies { compile "io.swagger:swagger-annotations:$swagger_annotations_version" compile "com.google.code.findbugs:jsr305:3.0.2" - compile "io.rest-assured:scala-support:$rest_assured_version" + compile "io.rest-assured:rest-assured:$rest_assured_version" {{#jackson}} compile "com.fasterxml.jackson.core:jackson-core:$jackson_version" compile "com.fasterxml.jackson.core:jackson-annotations:$jackson_version" compile "com.fasterxml.jackson.core:jackson-databind:$jackson_databind_version" compile "com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:$jackson_version" compile "org.openapitools:jackson-databind-nullable:$jackson_databind_nullable_version" + {{#withXml}} + compile "com.fasterxml.jackson.dataformat:jackson-dataformat-xml:$jackson_version" + {{/withXml}} + {{#joda}} + compile "com.fasterxml.jackson.datatype:jackson-datatype-joda:$jackson_version" + {{/joda}} + {{#java8}} + compile "com.fasterxml.jackson.datatype:jackson-datatype-jsr310:$jackson_version" + {{/java8}} + {{#threetenbp}} + compile "com.github.joschi.jackson:jackson-datatype-threetenbp:$jackson_threetenbp_version" + {{/threetenbp}} {{/jackson}} {{#gson}} compile "io.gsonfire:gson-fire:$gson_fire_version" diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/rest-assured/build.sbt.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/rest-assured/build.sbt.mustache index 77f8af4f436..955f515fc70 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/rest-assured/build.sbt.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/rest-assured/build.sbt.mustache @@ -10,11 +10,26 @@ lazy val root = (project in file(".")). resolvers += Resolver.mavenLocal, libraryDependencies ++= Seq( "io.swagger" % "swagger-annotations" % "1.5.21", + "io.rest-assured" % "rest-assured" % "4.3.0", "io.rest-assured" % "scala-support" % "4.3.0", + "com.google.code.findbugs" % "jsr305" % "3.0.2", {{#jackson}} - "com.fasterxml.jackson.core" % "jackson-core" % "2.10.3" % "compile", - "com.fasterxml.jackson.core" % "jackson-annotations" % "2.10.3" % "compile", - "com.fasterxml.jackson.core" % "jackson-databind" % "2.10.3" % "compile", + "com.fasterxml.jackson.core" % "jackson-core" % "2.10.3", + "com.fasterxml.jackson.core" % "jackson-annotations" % "2.10.3", + "com.fasterxml.jackson.core" % "jackson-databind" % "2.10.3", + "org.openapitools" % "jackson-databind-nullable" % "0.2.1", + {{#withXml}} + "com.fasterxml.jackson.dataformat" % "jackson-dataformat-xml" % "2.10.3", + {{/withXml}} + {{#joda}} + "com.fasterxml.jackson.datatype" % "jackson-datatype-joda" % "2.10.3", + {{/joda}} + {{#java8}} + "com.fasterxml.jackson.datatype" % "jackson-datatype-jsr310" % "2.10.3", + {{/java8}} + {{#threetenbp}} + "com.github.joschi.jackson" % "jackson-datatype-threetenbp" % "2.10.0", + {{/threetenbp}} {{/jackson}} {{#gson}} "com.google.code.gson" % "gson" % "2.8.6", @@ -31,7 +46,7 @@ lazy val root = (project in file(".")). "javax.validation" % "validation-api" % "2.0.1.Final" % "compile", {{/useBeanValidation}} {{#performBeanValidation}} - "org.hibernate" % "hibernate-validator" "6.0.19.Final" % "compile", + "org.hibernate" % "hibernate-validator" % "6.0.19.Final" % "compile", {{/performBeanValidation}} "junit" % "junit" % "4.13" % "test", "com.novocode" % "junit-interface" % "0.10" % "test" diff --git a/modules/openapi-generator/src/main/resources/csharp-dotnet2/ApiClient.mustache b/modules/openapi-generator/src/main/resources/csharp-dotnet2/ApiClient.mustache index c382839d898..1938e277989 100644 --- a/modules/openapi-generator/src/main/resources/csharp-dotnet2/ApiClient.mustache +++ b/modules/openapi-generator/src/main/resources/csharp-dotnet2/ApiClient.mustache @@ -261,8 +261,25 @@ namespace {{clientPackage}} { {{#authMethods}} case "{{name}}": - {{#isApiKey}}{{#isKeyInHeader}}headerParams["{{keyParamName}}"] = GetApiKeyWithPrefix("{{keyParamName}}");{{/isKeyInHeader}}{{#isKeyInQuery}}queryParams["{{keyParamName}}"] = GetApiKeyWithPrefix("{{keyParamName}}");{{/isKeyInQuery}}{{/isApiKey}}{{#isBasic}}headerParams["Authorization"] = "Basic " + Base64Encode(Configuration.Username + ":" + Configuration.Password);{{/isBasic}} - {{#isOAuth}}//TODO support oauth{{/isOAuth}} + {{#isApiKey}} + {{#isKeyInHeader}} + headerParams["{{keyParamName}}"] = GetApiKeyWithPrefix("{{keyParamName}}"); + {{/isKeyInHeader}} + {{#isKeyInQuery}} + queryParams["{{keyParamName}}"] = GetApiKeyWithPrefix("{{keyParamName}}"); + {{/isKeyInQuery}} + {{/isApiKey}} + {{#isBasic}} + {{#isBasicBasic}} + headerParams["Authorization"] = "Basic " + Base64Encode(Configuration.Username + ":" + Configuration.Password); + {{/isBasicBasic}} + {{#isBasicBearer}} + headerParams["Authorization"] = "Bearer " + Configuration.AccessToken; + {{/isBasicBearer}} + {{/isBasic}} + {{#isOAuth}} + headerParams["Authorization"] = "Bearer " + Configuration.AccessToken; + {{/isOAuth}} break; {{/authMethods}} default: diff --git a/modules/openapi-generator/src/main/resources/csharp-dotnet2/Configuration.mustache b/modules/openapi-generator/src/main/resources/csharp-dotnet2/Configuration.mustache index e09f39fc601..77f755d6114 100644 --- a/modules/openapi-generator/src/main/resources/csharp-dotnet2/Configuration.mustache +++ b/modules/openapi-generator/src/main/resources/csharp-dotnet2/Configuration.mustache @@ -37,6 +37,12 @@ namespace {{clientPackage}} /// The password. public static String Password { get; set; } + /// + /// Gets or sets the access token (Bearer/OAuth authentication). + /// + /// The access token. + public static String AccessToken { get; set; } + /// /// Gets or sets the API key based on the authentication name. /// diff --git a/modules/openapi-generator/src/main/resources/csharp-dotnet2/README.mustache b/modules/openapi-generator/src/main/resources/csharp-dotnet2/README.mustache index 041dec963b0..0d8dfd814d4 100644 --- a/modules/openapi-generator/src/main/resources/csharp-dotnet2/README.mustache +++ b/modules/openapi-generator/src/main/resources/csharp-dotnet2/README.mustache @@ -56,16 +56,31 @@ namespace Example { public void main() { - {{#apiInfo}}{{#apis}}{{#-first}}{{#operations}}{{#operation}}{{#-first}}{{#hasAuthMethods}}{{#authMethods}}{{#isBasic}} + {{#apiInfo}}{{#apis}}{{#-first}}{{#operations}}{{#operation}}{{#-first}} + {{#hasAuthMethods}} + {{#authMethods}} + {{#isBasic}} + {{#isBasicBasic}} // Configure HTTP basic authorization: {{{name}}} Configuration.Default.Username = "YOUR_USERNAME"; - Configuration.Default.Password = "YOUR_PASSWORD";{{/isBasic}}{{#isApiKey}} + Configuration.Default.Password = "YOUR_PASSWORD"; + {{/isBasicBasic}} + {{#isBasicBearer}} + // Configure Bearer access token for authorization: {{{name}}} + Configuration.Default.AccessToken = "YOUR_ACCESS_TOKEN"; + {{/isBasicBearer}} + {{/isBasic}} + {{#isApiKey}} // Configure API key authorization: {{{name}}} Configuration.Default.ApiKey.Add("{{{keyParamName}}}", "YOUR_API_KEY"); // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed - // Configuration.Default.ApiKeyPrefix.Add("{{{keyParamName}}}", "Bearer");{{/isApiKey}}{{#isOAuth}} + // Configuration.Default.ApiKeyPrefix.Add("{{{keyParamName}}}", "Bearer"); + {{/isApiKey}} + {{#isOAuth}} // Configure OAuth2 access token for authorization: {{{name}}} - Configuration.Default.AccessToken = "YOUR_ACCESS_TOKEN";{{/isOAuth}}{{/authMethods}} + Configuration.Default.AccessToken = "YOUR_ACCESS_TOKEN"; + {{/isOAuth}} + {{/authMethods}} {{/hasAuthMethods}} var apiInstance = new {{classname}}(); @@ -123,21 +138,29 @@ No model defined in this package All endpoints do not require authorization. {{/authMethods}} {{#authMethods}} -{{#last}} +{{#-last}} Authentication schemes defined for the API: -{{/last}} +{{/-last}} {{/authMethods}} {{#authMethods}} ### {{name}} -{{#isApiKey}}- **Type**: API key +{{#isApiKey}} +- **Type**: API key - **API key parameter name**: {{keyParamName}} - **Location**: {{#isKeyInQuery}}URL query string{{/isKeyInQuery}}{{#isKeyInHeader}}HTTP header{{/isKeyInHeader}} {{/isApiKey}} -{{#isBasic}}- **Type**: HTTP basic authentication +{{#isBasic}} +{{#isBasicBasic}} +- **Type**: HTTP basic authentication +{{/isBasicBasic}} +{{#isBasicBearer}} +- **Type**: HTTP bearer authentication +{{/isBasicBearer}} {{/isBasic}} -{{#isOAuth}}- **Type**: OAuth +{{#isOAuth}} +- **Type**: OAuth - **Flow**: {{flow}} - **Authorization URL**: {{authorizationUrl}} - **Scopes**: {{^scopes}}N/A{{/scopes}} diff --git a/modules/openapi-generator/src/main/resources/csharp-dotnet2/api_doc.mustache b/modules/openapi-generator/src/main/resources/csharp-dotnet2/api_doc.mustache index 1a772761894..325e1426014 100644 --- a/modules/openapi-generator/src/main/resources/csharp-dotnet2/api_doc.mustache +++ b/modules/openapi-generator/src/main/resources/csharp-dotnet2/api_doc.mustache @@ -32,18 +32,32 @@ namespace Example { public void main() { - {{#hasAuthMethods}}{{#authMethods}}{{#isBasic}} + {{#hasAuthMethods}} + {{#authMethods}} + {{#isBasic}} + {{#isBasicBasic}} // Configure HTTP basic authorization: {{{name}}} Configuration.Default.Username = "YOUR_USERNAME"; - Configuration.Default.Password = "YOUR_PASSWORD";{{/isBasic}}{{#isApiKey}} + Configuration.Default.Password = "YOUR_PASSWORD"; + {{/isBasicBasic}} + {{#isBasicBearer}} + // Configure Bearer access token: {{{name}}} + Configuration.Default.AccessToken = "YOUR_ACCESS_TOKEN"; + {{/isBasicBearer}} + {{/isBasic}} + {{#isApiKey}} // Configure API key authorization: {{{name}}} Configuration.Default.ApiKey.Add("{{{keyParamName}}}", "YOUR_API_KEY"); // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed - // Configuration.Default.ApiKeyPrefix.Add("{{{keyParamName}}}", "Bearer");{{/isApiKey}}{{#isOAuth}} + // Configuration.Default.ApiKeyPrefix.Add("{{{keyParamName}}}", "Bearer"); + {{/isApiKey}} + {{#isOAuth}} // Configure OAuth2 access token for authorization: {{{name}}} - Configuration.Default.AccessToken = "YOUR_ACCESS_TOKEN";{{/isOAuth}}{{/authMethods}} - {{/hasAuthMethods}} + Configuration.Default.AccessToken = "YOUR_ACCESS_TOKEN"; + {{/isOAuth}} + {{/authMethods}} + {{/hasAuthMethods}} var apiInstance = new {{classname}}(); {{#allParams}} {{#isPrimitiveType}} diff --git a/modules/openapi-generator/src/main/resources/csharp-netcore/ClientUtils.mustache b/modules/openapi-generator/src/main/resources/csharp-netcore/ClientUtils.mustache index b407a4edd08..f756a2c86ae 100755 --- a/modules/openapi-generator/src/main/resources/csharp-netcore/ClientUtils.mustache +++ b/modules/openapi-generator/src/main/resources/csharp-netcore/ClientUtils.mustache @@ -169,7 +169,7 @@ namespace {{packageName}}.Client public static String SelectHeaderContentType(String[] contentTypes) { if (contentTypes.Length == 0) - return "application/json"; + return null; foreach (var contentType in contentTypes) { diff --git a/modules/openapi-generator/src/main/resources/csharp/README.mustache b/modules/openapi-generator/src/main/resources/csharp/README.mustache index 474bfe829b4..da6053f4aa2 100644 --- a/modules/openapi-generator/src/main/resources/csharp/README.mustache +++ b/modules/openapi-generator/src/main/resources/csharp/README.mustache @@ -119,9 +119,15 @@ namespace Example {{#hasAuthMethods}} {{#authMethods}} {{#isBasic}} + {{#isBasicBasic}} // Configure HTTP basic authorization: {{{name}}} Configuration.Default.Username = "YOUR_USERNAME"; Configuration.Default.Password = "YOUR_PASSWORD"; + {{/isBasicBasic}} + {{#isBasicBearer}} + // Configure HTTP bearer authorization: {{{name}}} + Configuration.Default.AccessToken = "YOUR_ACCESS_TOKEN"; + {{/isBasicBearer}} {{/isBasic}} {{#isApiKey}} // Configure API key authorization: {{{name}}} @@ -205,8 +211,14 @@ Authentication schemes defined for the API: - **Location**: {{#isKeyInQuery}}URL query string{{/isKeyInQuery}}{{#isKeyInHeader}}HTTP header{{/isKeyInHeader}} {{/isApiKey}} {{#isBasic}} +{{#isBasicBasic}} - **Type**: HTTP basic authentication +{{/isBasicBasic}} +{{#isBasicBearer}} + +- **Type**: HTTP bearer authentication +{{/isBasicBearer}} {{/isBasic}} {{#isOAuth}} diff --git a/modules/openapi-generator/src/main/resources/csharp/api.mustache b/modules/openapi-generator/src/main/resources/csharp/api.mustache index f040c439025..a0300971694 100644 --- a/modules/openapi-generator/src/main/resources/csharp/api.mustache +++ b/modules/openapi-generator/src/main/resources/csharp/api.mustache @@ -278,11 +278,20 @@ namespace {{packageName}}.{{apiPackage}} {{/isKeyInQuery}} {{/isApiKey}} {{#isBasic}} + {{#isBasicBasic}} // http basic authentication required if (!String.IsNullOrEmpty(this.Configuration.Username) || !String.IsNullOrEmpty(this.Configuration.Password)) { localVarHeaderParams["Authorization"] = "Basic " + ApiClient.Base64Encode(this.Configuration.Username + ":" + this.Configuration.Password); } + {{/isBasicBasic}} + {{#isBasicBearer}} + // http beerer authentication required + if (!String.IsNullOrEmpty(this.Configuration.AccessToken)) + { + localVarHeaderParams["Authorization"] = "Bearer " + this.Configuration.AccessToken; + } + {{/isBasicBearer}} {{/isBasic}} {{#isOAuth}} // oauth required @@ -414,11 +423,20 @@ namespace {{packageName}}.{{apiPackage}} {{/isKeyInQuery}} {{/isApiKey}} {{#isBasic}} + {{#isBasicBasic}} // http basic authentication required if (!String.IsNullOrEmpty(this.Configuration.Username) || !String.IsNullOrEmpty(this.Configuration.Password)) { localVarHeaderParams["Authorization"] = "Basic " + ApiClient.Base64Encode(this.Configuration.Username + ":" + this.Configuration.Password); } + {{/isBasicBasic}} + {{#isBasicBearer}} + // http bearer authentication required + if (!String.IsNullOrEmpty(this.Configuration.AccessToken)) + { + localVarHeaderParams["Authorization"] = "Bearer " + this.Configuration.AccessToken; + } + {{/isBasicBearer}} {{/isBasic}} {{#isOAuth}} // oauth required diff --git a/modules/openapi-generator/src/main/resources/csharp/api_doc.mustache b/modules/openapi-generator/src/main/resources/csharp/api_doc.mustache index df59f42415c..6e4bbf7c9a4 100644 --- a/modules/openapi-generator/src/main/resources/csharp/api_doc.mustache +++ b/modules/openapi-generator/src/main/resources/csharp/api_doc.mustache @@ -39,9 +39,15 @@ namespace Example {{#hasAuthMethods}} {{#authMethods}} {{#isBasic}} + {{#isBasicBasic}} // Configure HTTP basic authorization: {{{name}}} Configuration.Default.Username = "YOUR_USERNAME"; Configuration.Default.Password = "YOUR_PASSWORD"; + {{/isBasicBasic}} + {{#isBasicBearer}} + // Configure HTTP bearer authorization: {{{name}}} + Configuration.Default.AccessToken = "YOUR_ACCESS_TOKEN"; + {{/isBasicBearer}} {{/isBasic}} {{#isApiKey}} // Configure API key authorization: {{{name}}} diff --git a/modules/openapi-generator/src/main/resources/htmlDocs2/index.mustache b/modules/openapi-generator/src/main/resources/htmlDocs2/index.mustache index 1cb04a58a9f..e82cd10725d 100644 --- a/modules/openapi-generator/src/main/resources/htmlDocs2/index.mustache +++ b/modules/openapi-generator/src/main/resources/htmlDocs2/index.mustache @@ -101,6 +101,31 @@ //Convert elements with "marked" class to markdown processMarked(); }); + + function findNode(id, currentNode) { + return (Object.keys(currentNode)[0] === id) ? currentNode : findNodeInChildren(id, currentNode); + } + + function findNodeInChildren(id, currentNode) { + for (let prop in currentNode) { + if (currentNode.hasOwnProperty(prop)) { + let currentChild = currentNode[prop]; + if (id === prop) { + return currentChild; + } else { + // Search in the current child + if (typeof (currentChild) === 'object') { + let result = findNode(id, currentChild); + if (result !== false) { + return result; + } + } + } + } + } + return false; + } +