Skip to content

Commit

Permalink
Merge branch 'swagger-api:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Bobdugrand8 authored Jan 22, 2025
2 parents 89e8269 + 454249e commit 2f18815
Show file tree
Hide file tree
Showing 15 changed files with 116 additions and 32 deletions.
20 changes: 10 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<groupId>io.swagger.codegen.v3</groupId>
<artifactId>swagger-codegen-generators</artifactId>
<version>1.0.52</version>
<version>1.0.55</version>
<packaging>jar</packaging>

<build>
Expand Down Expand Up @@ -256,28 +256,28 @@
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>5.12.0</version>
<version>5.14.2</version>
<scope>test</scope>
</dependency>
</dependencies>
<properties>
<maven.compiler.release>8</maven.compiler.release>
<swagger-codegen-version>3.0.62</swagger-codegen-version>
<swagger-parser-version>2.1.22</swagger-parser-version>
<swagger-core-version>2.2.22</swagger-core-version>
<jackson-version>2.17.2</jackson-version>
<jackson-databind-version>2.17.2</jackson-databind-version>
<swagger-codegen-version>3.0.65</swagger-codegen-version>
<swagger-parser-version>2.1.23</swagger-parser-version>
<swagger-core-version>2.2.26</swagger-core-version>
<jackson-version>2.18.0</jackson-version>
<jackson-databind-version>2.18.0</jackson-databind-version>
<scala-version>2.11.1</scala-version>
<felix-version>3.3.0</felix-version>
<commons-io-version>2.16.1</commons-io-version>
<commons-io-version>2.17.0</commons-io-version>
<commons-cli-version>1.9.0</commons-cli-version>
<junit-version>4.13.2</junit-version>
<maven-plugin-version>1.0.0</maven-plugin-version>
<commons-lang-version>3.16.0</commons-lang-version>
<commons-lang-version>3.17.0</commons-lang-version>
<slf4j-version>2.0.9</slf4j-version>
<scala-maven-plugin-version>3.2.1</scala-maven-plugin-version>
<testng-version>7.10.2</testng-version>
<surefire-version>3.3.0</surefire-version>
<surefire-version>3.5.1</surefire-version>
<jmockit-version>1.49</jmockit-version>
<reflections-version>0.10.2</reflections-version>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,11 @@ public abstract class DefaultCodegenConfig implements CodegenConfig {
protected String templateVersion;
protected String embeddedTemplateDir;
protected String commonTemplateDir = "_common";
protected Map<String, Object> additionalProperties = new HashMap<String, Object>();
protected Map<String, Object> additionalProperties = new HashMap<>();
protected Map<String, Object> vendorExtensions = new HashMap<String, Object>();
protected List<SupportingFile> supportingFiles = new ArrayList<SupportingFile>();
protected List<CliOption> cliOptions = new ArrayList<CliOption>();
protected List<SupportingFile> supportingFiles = new ArrayList<>();
protected List<SupportingFile> configFiles = new ArrayList<>();
protected List<CliOption> cliOptions = new ArrayList<>();
protected List<CodegenArgument> languageArguments;
protected boolean skipOverwrite;
protected boolean removeOperationIdPrefix;
Expand Down Expand Up @@ -664,6 +665,10 @@ public List<SupportingFile> supportingFiles() {
return supportingFiles;
}

public List<SupportingFile> configFiles() {
return configFiles;
}

public String outputFolder() {
return outputFolder;
}
Expand Down Expand Up @@ -2163,7 +2168,7 @@ public CodegenOperation fromOperation(String path, String httpMethod, Operation

if (schema == null) {
CodegenParameter codegenParameter = CodegenModelFactory.newInstance(CodegenModelType.PARAMETER);
codegenParameter.description = body.getDescription();
codegenParameter.description = escapeText(body.getDescription());
codegenParameter.unescapedDescription = body.getDescription();
String bodyName = REQUEST_BODY_NAME;
if (body.getExtensions() != null && body.getExtensions().get("x-codegen-request-body-name") != null) {
Expand Down Expand Up @@ -2674,7 +2679,7 @@ public CodegenParameter fromRequestBody(RequestBody body, String name, Schema sc
}
codegenParameter.baseName = bodyName;
codegenParameter.paramName = bodyName;
codegenParameter.description = body.getDescription();
codegenParameter.description = escapeText(body.getDescription());
codegenParameter.unescapedDescription = body.getDescription();
codegenParameter.required = body.getRequired() != null ? body.getRequired() : Boolean.FALSE;
codegenParameter.getVendorExtensions().put(CodegenConstants.IS_BODY_PARAM_EXT_NAME, Boolean.TRUE);
Expand Down Expand Up @@ -3807,13 +3812,16 @@ protected String getOptionValue(String optionName) {
return codegenArgumentOptional.get().getValue();
}

public void writeOptional(String outputFolder, SupportingFile supportingFile) {
writeOptional(outputFolder, supportingFile, false);
}
/**
* Only write if the file doesn't exist
*
* @param outputFolder Output folder
* @param supportingFile Supporting file
*/
public void writeOptional(String outputFolder, SupportingFile supportingFile) {
public void writeOptional(String outputFolder, SupportingFile supportingFile, boolean configFile) {
String folder = "";

if(outputFolder != null && !"".equals(outputFolder)) {
Expand All @@ -3826,8 +3834,9 @@ public void writeOptional(String outputFolder, SupportingFile supportingFile) {
else {
folder = supportingFile.destinationFilename;
}
List<SupportingFile> targetFiles = configFile ? this.configFiles : this.supportingFiles;
if(!new File(folder).exists()) {
supportingFiles.add(supportingFile);
targetFiles.add(supportingFile);
} else {
LOGGER.info("Skipped overwriting " + supportingFile.destinationFilename + " as the file already exists in " + folder);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ public AbstractCSharpCodegen() {
"String",
"Boolean",
"Double",
"Decimal",
"BigDecimal",
"Int32",
"Int64",
"Float",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ public void processOpts() {

if (isSpringBoot3Library()) {
setDateLibrary("java8");
setJakarta(true);
additionalProperties.put(JAKARTA, jakarta);
}

super.processOpts();
Expand Down Expand Up @@ -291,6 +293,7 @@ public void processOpts() {

if (additionalProperties.containsKey(USE_BEANVALIDATION)) {
this.setUseBeanValidation(convertPropertyToBoolean(USE_BEANVALIDATION));
writePropertyBack(USE_BEANVALIDATION, this.useBeanValidation);
}

if (additionalProperties.containsKey(USE_OPTIONAL)) {
Expand Down Expand Up @@ -318,10 +321,10 @@ public void processOpts() {
if (useBeanValidation) {
writePropertyBack(USE_BEANVALIDATION, useBeanValidation);
if (VALIDATION_MODE_LOOSE.equals(validationMode) || VALIDATION_MODE_STRICT.equals(validationMode)) {
supportingFiles.add(new SupportingFile("NotUndefined.mustache",
(sourceFolder + File.separator + configPackage).replace(".", java.io.File.separator), "NotUndefined.java"));
supportingFiles.add(new SupportingFile("NotUndefinedValidator.mustache",
(sourceFolder + File.separator + configPackage).replace(".", java.io.File.separator), "NotUndefinedValidator.java"));
writeOptional(outputFolder, new SupportingFile("NotUndefined.mustache",
(sourceFolder + File.separator + configPackage).replace(".", java.io.File.separator), "NotUndefined.java"), true);
writeOptional(outputFolder, new SupportingFile("NotUndefinedValidator.mustache",
(sourceFolder + File.separator + configPackage).replace(".", java.io.File.separator), "NotUndefinedValidator.java"), true);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {{invokerPackage}}.ProgressRequestBody;
import {{invokerPackage}}.ProgressResponseBody;
{{#performBeanValidation}}
import {{invokerPackage}}.BeanValidationException;
import org.hibernate.validator.messageinterpolation.ParameterMessageInterpolator;
{{/performBeanValidation}}

import com.google.gson.reflect.TypeToken;
Expand Down Expand Up @@ -42,6 +43,7 @@ import javax.validation.executable.ExecutableValidator;
import java.util.Set;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import org.hibernate.validator.messageinterpolation.ParameterMessageInterpolator;
{{/performBeanValidation}}

{{#imports}}import {{import}};
Expand Down Expand Up @@ -165,7 +167,10 @@ public class {{classname}} {
{{/performBeanValidation}}
{{#performBeanValidation}}
try {
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
ValidatorFactory factory = Validation.byDefaultProvider()
.configure()
.messageInterpolator(new ParameterMessageInterpolator())
.buildValidatorFactory();
ExecutableValidator executableValidator = factory.getValidator().forExecutables();
Object[] parameterValues = { {{#parameters}}{{paramName}}{{#has this 'more'}}, {{/has}}{{/parameters}} };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import javax.validation.executable.ExecutableValidator;
import java.util.Set;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import org.hibernate.validator.messageinterpolation.ParameterMessageInterpolator;
{{/performBeanValidation}}

{{#imports}}import {{import}};
Expand Down Expand Up @@ -147,7 +148,10 @@ public class {{classname}} {
{{/performBeanValidation}}
{{#performBeanValidation}}
try {
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
ValidatorFactory factory = Validation.byDefaultProvider()
.configure()
.messageInterpolator(new ParameterMessageInterpolator())
.buildValidatorFactory();
ExecutableValidator executableValidator = factory.getValidator().forExecutables();
Object[] parameterValues = { {{#parameters}}{{paramName}}{{#has this 'more'}}, {{/has}}{{/parameters}} };
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
package {{configPackage}};

{{#jakarta}}
import jakarta.validation.Constraint;
import jakarta.validation.Payload;
{{/jakarta}}
{{^jakarta}}
import javax.validation.Constraint;
import javax.validation.Payload;
{{/jakarta}}
import java.lang.annotation.*;

@Target({ElementType.TYPE})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
package {{configPackage}};

import org.openapitools.jackson.nullable.JsonNullable;
{{#jakarta}}
import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;
{{/jakarta}}
{{^jakarta}}
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
{{/jakarta}}
import java.lang.reflect.Field;

public class NotUndefinedValidator implements ConstraintValidator<NotUndefined, Object>{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,13 @@ public class CustomInstantDeserializer<T extends Temporal>
return value;
}
}
{{#jakarta}}
context.reportInputMismatch(handledType(), "Expected type float, integer, or string.");
return null;
{{/jakarta}}
{{^jakarta}}
throw context.mappingException("Expected type float, integer, or string.");
{{/jakarta}}
}

private ZoneId getZone(DeserializationContext context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@
<name>{{artifactId}}</name>
<version>{{artifactVersion}}</version>
<properties>
{{#jakarta}}
<maven.compiler.release>17</maven.compiler.release>
{{/jakarta}}
{{^jakarta}}
<java.version>{{#java11}}11{{/java11}}{{^java11}}{{#java8}}1.8{{/java8}}{{^java8}}1.7{{/java8}}{{/java11}}</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
{{/jakarta}}
{{#useOas2}}
<springfox-version>2.9.2</springfox-version>
{{/useOas2}}
Expand All @@ -19,7 +24,12 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
{{#jakarta}}
<version>3.3.4</version>
{{/jakarta}}
{{^jakarta}}
<version>{{springBootVersion}}</version>
{{/jakarta}}
</parent>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
Expand Down Expand Up @@ -66,7 +76,13 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>

{{#jakarta}}
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
<version>8.0.1.Final</version>
</dependency>
{{/jakarta}}
<!--SpringFox dependencies -->
{{#useOas2}}
<dependency>
Expand Down Expand Up @@ -139,6 +155,7 @@
<dependency>
<groupId>jakarta.validation</groupId>
<artifactId>jakarta.validation-api</artifactId>
<version>3.0.2</version>
</dependency>
{{/jakarta}}
{{^jakarta}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,12 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2;

import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
{{#jakarta}}
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
{{/jakarta}}
{{^jakarta}}
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

{{/jakarta}}
@SpringBootApplication
{{#useOas2}}
@EnableSwagger2
Expand Down Expand Up @@ -62,7 +66,12 @@ public class Swagger2SpringBoot implements CommandLineRunner {
{{/useBeanValidation}}

@Configuration
{{#jakarta}}
static class CustomDateConfig implements WebMvcConfigurer {
{{/jakarta}}
{{^jakarta}}
static class CustomDateConfig extends WebMvcConfigurerAdapter {
{{/jakarta}}
@Override
public void addFormatters(FormatterRegistry registry) {
registry.addConverter(new LocalDateConverter("{{#datePattern}}{{datePattern}}{{/datePattern}}{{^datePattern}}yyyy-MM-dd{{/datePattern}}"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.release>17</maven.compiler.release>
<springboot-version>3.1.1</springboot-version>
<swagger-annotations-version>2.2.14</swagger-annotations-version>
<springboot-version>3.3.4</springboot-version>
<swagger-annotations-version>2.2.25</swagger-annotations-version>
<springdoc-version>1.7.0</springdoc-version>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.1.1</version>
<version>3.3.4</version>
</parent>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
Expand Down Expand Up @@ -44,6 +44,11 @@
<artifactId>spring-boot-starter-tomcat</artifactId>
<version>${springboot-version}</version>
</dependency>
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
<version>8.0.1.Final</version>
</dependency>
{{#withXml}}
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/handlebars/JavaSpring/model.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import java.io.Serializable;
import org.springframework.validation.annotation.Validated;
{{#isLooseValidation}}
import org.openapitools.jackson.nullable.JsonNullable;
import io.swagger.configuration.NotUndefined;
import {{configPackage}}.NotUndefined;
{{/isLooseValidation}}
{{#isStrictValidation}}
import org.openapitools.jackson.nullable.JsonNullable;
import io.swagger.configuration.NotUndefined;
import {{configPackage}}.NotUndefined;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonSetter;
import com.fasterxml.jackson.annotation.Nulls;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ var JSONSchemaView = (function () {
this.isPrimitive = !this.isAny && !this.isArray && !this.isObject;
//
this.showToggle = this.schema.description || this.schema.title || this.isPrimitive && (this.schema.minimum || this.schema.maximum || this.schema.exclusiveMinimum || this.schema.exclusiveMaximum);
this.showToggle = this.schema.description || this.schema.title || this.isPrimitive && (this.schema.minimum || this.schema.maximum || this.schema.exclusiveMinimum || this.schema.exclusiveMaximum || this.schema.maxLength || this.schema.minLength || this.schema.pattern || this.schema.format);
// populate isRequired property down to properties
if (this.schema && Array.isArray(this.schema.required)) {
Expand Down
Loading

0 comments on commit 2f18815

Please sign in to comment.