diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavascriptApolloClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavascriptApolloClientCodegen.java index 0191719c9c75..9676b9bf34ca 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavascriptApolloClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavascriptApolloClientCodegen.java @@ -17,11 +17,13 @@ package org.openapitools.codegen.languages; import io.swagger.v3.oas.models.OpenAPI; +import io.swagger.v3.oas.models.examples.Example; import io.swagger.v3.oas.models.info.Info; import io.swagger.v3.oas.models.info.License; import io.swagger.v3.oas.models.media.ArraySchema; import io.swagger.v3.oas.models.media.ComposedSchema; import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.parameters.Parameter; import org.apache.commons.io.FilenameUtils; import org.apache.commons.lang3.StringUtils; import org.openapitools.codegen.*; @@ -671,10 +673,10 @@ public String toDefaultValueWithParam(String name, Schema p) { public void setParameterExampleValue(CodegenParameter p) { String example; - if (p.defaultValue == null) { - example = p.example; - } else { + if (p.example == null) { example = p.defaultValue; + } else { + example = p.example; } String type = p.baseType; @@ -740,6 +742,24 @@ public void setParameterExampleValue(CodegenParameter p) { p.example = example; } + @Override + public void setParameterExampleValue(CodegenParameter codegenParameter, Parameter parameter) { + Schema schema = parameter.getSchema(); + + if (parameter.getExample() != null) { + codegenParameter.example = parameter.getExample().toString(); + } else if (parameter.getExamples() != null && !parameter.getExamples().isEmpty()) { + Example example = parameter.getExamples().values().iterator().next(); + if (example.getValue() != null) { + codegenParameter.example = example.getValue().toString(); + } + } else if (schema != null && schema.getExample() != null) { + codegenParameter.example = schema.getExample().toString(); + } + + setParameterExampleValue(codegenParameter); + } + protected String setPropertyExampleValue(CodegenProperty p) { String example; diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavascriptClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavascriptClientCodegen.java index 9586efe7f7f8..1eaede84d600 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavascriptClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavascriptClientCodegen.java @@ -18,11 +18,13 @@ package org.openapitools.codegen.languages; import io.swagger.v3.oas.models.OpenAPI; +import io.swagger.v3.oas.models.examples.Example; import io.swagger.v3.oas.models.info.Info; import io.swagger.v3.oas.models.info.License; import io.swagger.v3.oas.models.media.ArraySchema; import io.swagger.v3.oas.models.media.ComposedSchema; import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.parameters.Parameter; import org.apache.commons.io.FilenameUtils; import org.apache.commons.lang3.StringUtils; import org.openapitools.codegen.*; @@ -671,10 +673,10 @@ public String toDefaultValueWithParam(String name, Schema p) { public void setParameterExampleValue(CodegenParameter p) { String example; - if (p.defaultValue == null) { - example = p.example; - } else { + if (p.example == null) { example = p.defaultValue; + } else { + example = p.example; } String type = p.baseType; @@ -740,6 +742,24 @@ public void setParameterExampleValue(CodegenParameter p) { p.example = example; } + @Override + public void setParameterExampleValue(CodegenParameter codegenParameter, Parameter parameter) { + Schema schema = parameter.getSchema(); + + if (parameter.getExample() != null) { + codegenParameter.example = parameter.getExample().toString(); + } else if (parameter.getExamples() != null && !parameter.getExamples().isEmpty()) { + Example example = parameter.getExamples().values().iterator().next(); + if (example.getValue() != null) { + codegenParameter.example = example.getValue().toString(); + } + } else if (schema != null && schema.getExample() != null) { + codegenParameter.example = schema.getExample().toString(); + } + + setParameterExampleValue(codegenParameter); + } + protected String setPropertyExampleValue(CodegenProperty p) { String example;