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
Fyro-Ing authored Oct 22, 2023
2 parents 8ebbdaf + 681ec40 commit c69a87b
Show file tree
Hide file tree
Showing 19 changed files with 94 additions and 115 deletions.
26 changes: 13 additions & 13 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.43-SNAPSHOT</version>
<version>1.0.44</version>
<packaging>jar</packaging>

<build>
Expand Down Expand Up @@ -68,7 +68,7 @@
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit4</artifactId>
<version>3.0.0</version>
<version>${surefire-version}</version>
</dependency>
</dependencies>
<configuration>
Expand Down Expand Up @@ -251,33 +251,33 @@
<dependency>
<groupId>com.atlassian.commonmark</groupId>
<artifactId>commonmark</artifactId>
<version>0.9.0</version>
<version>0.17.0</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>2.8.47</version>
<version>2.28.2</version>
<scope>test</scope>
</dependency>
</dependencies>
<properties>
<maven.compiler.release>8</maven.compiler.release>
<swagger-codegen-version>3.0.45</swagger-codegen-version>
<swagger-parser-version>2.1.14</swagger-parser-version>
<swagger-core-version>2.2.11</swagger-core-version>
<jackson-version>2.15.1</jackson-version>
<jackson-databind-version>2.15.1</jackson-databind-version>
<swagger-codegen-version>3.0.48</swagger-codegen-version>
<swagger-parser-version>2.1.18</swagger-parser-version>
<swagger-core-version>2.2.17</swagger-core-version>
<jackson-version>2.15.3</jackson-version>
<jackson-databind-version>2.15.3</jackson-databind-version>
<scala-version>2.11.1</scala-version>
<felix-version>3.3.0</felix-version>
<commons-io-version>2.11.0</commons-io-version>
<commons-io-version>2.14.0</commons-io-version>
<commons-cli-version>1.5.0</commons-cli-version>
<junit-version>4.13.2</junit-version>
<maven-plugin-version>1.0.0</maven-plugin-version>
<commons-lang-version>3.12.0</commons-lang-version>
<commons-lang-version>3.13.0</commons-lang-version>
<slf4j-version>1.7.36</slf4j-version>
<scala-maven-plugin-version>3.2.1</scala-maven-plugin-version>
<testng-version>7.7.1</testng-version>
<surefire-version>3.0.0</surefire-version>
<testng-version>7.8.0</testng-version>
<surefire-version>3.1.2</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 @@ -1344,6 +1344,9 @@ public CodegenModel fromModel(String name, Schema schema, Map<String, Schema> al
codegenModel.getVendorExtensions().put(CodegenConstants.IS_ALIAS_EXT_NAME, typeAliases.containsKey(name));

codegenModel.discriminator = schema.getDiscriminator();
if (codegenModel.discriminator != null && codegenModel.discriminator.getPropertyName() != null) {
codegenModel.discriminator.setPropertyName(toVarName(codegenModel.discriminator.getPropertyName()));
}

if (schema.getXml() != null) {
codegenModel.xmlPrefix = schema.getXml().getPrefix();
Expand Down Expand Up @@ -1404,11 +1407,6 @@ else if (schema instanceof ComposedSchema) {
final List<Schema> allOf = composed.getAllOf();
// interfaces (intermediate models)
if (allOf != null && !allOf.isEmpty()) {

if (codegenModel.discriminator != null && codegenModel.discriminator.getPropertyName() != null) {
codegenModel.discriminator.setPropertyName(toVarName(codegenModel.discriminator.getPropertyName()));
}

for (int i = 0; i < allOf.size(); i++) {
if (i == 0 && !copyFistAllOfProperties) {
continue;
Expand All @@ -1435,16 +1433,6 @@ else if (schema instanceof ComposedSchema) {
}
}

final List<Schema> oneOf = composed.getOneOf();
if (oneOf != null && !oneOf.isEmpty()) {
if (schema.getDiscriminator() != null) {
codegenModel.discriminator = schema.getDiscriminator();
if (codegenModel.discriminator != null && codegenModel.discriminator.getPropertyName() != null) {
codegenModel.discriminator.setPropertyName(toVarName(codegenModel.discriminator.getPropertyName()));
}
}
}

if (parent != null) {
codegenModel.parentSchema = parentName;
codegenModel.parent = typeMapping.containsKey(parentName) ? typeMapping.get(parentName): toModelName(parentName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import io.swagger.codegen.v3.CodegenSecurity;
import io.swagger.codegen.v3.CodegenType;
import io.swagger.codegen.v3.SupportingFile;
import io.swagger.codegen.v3.utils.SemVer;
import io.swagger.v3.core.util.Json;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.security.SecurityScheme;
Expand All @@ -30,7 +31,9 @@ public class AspNetCoreServerCodegen extends AbstractCSharpCodegen {
private static final String ASP_NET_CORE_VERSION_OPTION = "--aspnet-core-version";
private static final String INTERFACE_ONLY_OPTION = "--interface-only";
private static final String INTERFACE_CONTROLLER_OPTION = "--interface-controller";
private final String DEFAULT_ASP_NET_CORE_VERSION = "3.1";
private static final String SWASH_BUCKLE_VERSION_OPTION = "swashBuckleVersion";
private static final String TARGET_FRAMEWORK = "targetFramework";
private final String DEFAULT_ASP_NET_CORE_VERSION = "7.0";
private String aspNetCoreVersion;

@SuppressWarnings("hiding")
Expand Down Expand Up @@ -162,6 +165,7 @@ public void processOpts() {
supportingFiles.add(new SupportingFile("Filters" + File.separator + "GeneratePathParamsValidationFilter.mustache", packageFolder + File.separator + "Filters", "GeneratePathParamsValidationFilter.cs"));
supportingFiles.add(new SupportingFile("Startup.mustache", packageFolder, "Startup.cs"));
} else {
final SemVer semVer = new SemVer(aspNetCoreVersion);
apiTemplateFiles.put("3.0/controller.mustache", ".cs");
addInterfaceControllerTemplate();

Expand All @@ -170,7 +174,20 @@ public void processOpts() {

supportingFiles.add(new SupportingFile("3.0/Startup.mustache", packageFolder, "Startup.cs"));
supportingFiles.add(new SupportingFile("3.0/Program.mustache", packageFolder, "Program.cs"));
if (isThreeDotOneVersion) {

if (semVer.atLeast("5.0")) {
additionalProperties.put(SWASH_BUCKLE_VERSION_OPTION, "6.4.0");
supportingFiles.add(new SupportingFile("3.1/Project.csproj.mustache", packageFolder, this.packageName + ".csproj"));
}
if (semVer.atLeast("7.0")) {
additionalProperties.put(TARGET_FRAMEWORK, "net7.0");
} else if (semVer.atLeast("6.0")) {
additionalProperties.put(TARGET_FRAMEWORK, "net6.0");
} else if (semVer.atLeast("5.0")) {
additionalProperties.put(TARGET_FRAMEWORK, "net5.0");
} else if (semVer.atLeast("3.1")) {
additionalProperties.put(SWASH_BUCKLE_VERSION_OPTION, "5.5.1");
additionalProperties.put(TARGET_FRAMEWORK, "netcoreapp3.1");
supportingFiles.add(new SupportingFile("3.1/Project.csproj.mustache", packageFolder, this.packageName + ".csproj"));
} else {
supportingFiles.add(new SupportingFile("3.0/Project.csproj.mustache", packageFolder, this.packageName + ".csproj"));
Expand Down Expand Up @@ -284,7 +301,8 @@ protected void processOperation(CodegenOperation operation) {
List <CodegenContent> contents = operation.getContents()
.stream()
.filter(codegenContent -> !codegenContent.getIsForm())
.collect(Collectors.toList());
.collect(
Collectors.toList());
operation.getContents().clear();
operation.getContents().addAll(contents);
}
Expand Down Expand Up @@ -345,7 +363,7 @@ private void addInterfaceControllerTemplate() {
boolean interfaceController = false;
if (StringUtils.isNotBlank(interfaceControllerOption)) {
interfaceController = Boolean.valueOf(getOptionValue(INTERFACE_CONTROLLER_OPTION));
} else {
} else {
if (additionalProperties.get(INTERFACE_CONTROLLER_OPTION.substring(2)) != null) {
interfaceController = Boolean.valueOf(additionalProperties.get(INTERFACE_CONTROLLER_OPTION.substring(2)).toString());
}
Expand Down Expand Up @@ -378,7 +396,8 @@ private void setAspNetCoreVersion() {
} else {
this.aspNetCoreVersion = optionValue;
}
if (!this.aspNetCoreVersion.equals("2.0") && !this.aspNetCoreVersion.equals("2.1") && !this.aspNetCoreVersion.equals("2.2") && !this.aspNetCoreVersion.equals("3.0")) {
final SemVer semVer = new SemVer(this.aspNetCoreVersion);
if (semVer.compareTo(new SemVer("2.0")) < 0) {
LOGGER.error("version '" + this.aspNetCoreVersion + "' is not supported, switching to default version: '" + DEFAULT_ASP_NET_CORE_VERSION + "'");
this.aspNetCoreVersion = DEFAULT_ASP_NET_CORE_VERSION;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1052,7 +1052,7 @@ protected void fixUpParentAndInterfaces(CodegenModel codegenModel, Map<String, C

for (CodegenProperty codegenProperty : codegenModel.vars) {
CodegenModel parentModel = codegenModel.parentModel;

while (parentModel != null) {
if (parentModel.vars == null || parentModel.vars.isEmpty()) {
parentModel = parentModel.parentModel;
Expand Down Expand Up @@ -1677,11 +1677,6 @@ public void setLanguageArguments(List<CodegenArgument> languageArguments) {
super.setLanguageArguments(languageArguments);
}

@Override
public boolean defaultIgnoreImportMappingOption() {
return true;
}

@Override
public boolean checkAliasModel() {
return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
{{#withXml}}
@XmlType(name="{{datatypeWithEnum}}")
@XmlEnum({{datatypeWithEnum}}.class)
{{/withXml}}
public enum {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}} {
{{#allowableValues}}
{{#enumVars}}
{{#withXml}}
@XmlEnumValue({{#value}}{{{value}}}{{/value}}{{^value}}""{{/value}})
{{/withXml}}
{{{name}}}({{#value}}{{{value}}}{{/value}}{{^value}}null{{/value}}){{^@last}},{{/@last}}{{#@last}};{{/@last}}
{{/enumVars}}
{{/allowableValues}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
{{^springBootV2}}
springfox.documentation.swagger.v2.path=/api-docs
{{/springBootV2}}
{{#springBootV2}}
{{#useOas2}}
springfox.documentation.swagger.v2.path=/api-docs
server.contextPath={{^contextPath}}/{{/contextPath}}{{#contextPath}}{{contextPath}}{{/contextPath}}
{{/useOas2}}
{{^useOas2}}
springfox.documentation.open-api.v3.path=/api-docs
springdoc.api-docs.path=/api-docs
{{/useOas2}}
{{/springBootV2}}
server.servlet.contextPath={{^contextPath}}/{{/contextPath}}{{#contextPath}}{{contextPath}}{{/contextPath}}
server.port={{serverPort}}
spring.jackson.date-format={{basePackage}}.RFC3339DateFormat
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
springfox.documentation.swagger.v2.path=/api-docs
{{/useOas2}}
{{^useOas2}}
springfox.documentation.open-api.v3.path=/api-docs
springdoc.api-docs.path=/api-docs
{{/useOas2}}
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@ public class HomeController {
@RequestMapping(value = "/")
public String index() {
{{#useOas2}}
System.out.println("swagger-ui.html");
return "redirect:swagger-ui.html";
{{/useOas2}}
{{^useOas2}}
System.out.println("/swagger-ui/index.html");
return "redirect:/swagger-ui/";
{{/useOas2}}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@
<springfox-version>2.9.2</springfox-version>
{{/useOas2}}
{{^useOas2}}
{{^springBootV2}}
<springdoc-version>1.2.9</springdoc-version>
{{/springBootV2}}
{{#springBootV2}}
<springfox-version>3.0.0</springfox-version>
{{/springBootV2}}
<springdoc-version>1.7.0</springdoc-version>
{{/useOas2}}
</properties>
<parent>
Expand Down Expand Up @@ -79,37 +74,19 @@
<artifactId>springfox-swagger2</artifactId>
<version>${springfox-version}</version>
</dependency>
{{/useOas2}}
{{^useOas2}}
{{#springBootV2}}
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-oas</artifactId>
<version>${springfox-version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${springfox-version}</version>
</dependency>
{{/springBootV2}}
{{/useOas2}}
{{#useOas2}}
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${springfox-version}</version>
</dependency>
{{/useOas2}}
{{^useOas2}}
{{^springBootV2}}
<!-- SpringDoc dependencies -->
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>${springdoc-version}</version>
</dependency>
{{/springBootV2}}
{{/useOas2}}

{{#withXml}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ import org.springframework.context.annotation.ComponentScan;
{{#useOas2}}
import springfox.documentation.swagger2.annotations.EnableSwagger2;
{{/useOas2}}
{{^useOas2}}
import springfox.documentation.oas.annotations.EnableOpenApi;
{{/useOas2}}

import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
Expand All @@ -24,9 +21,6 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
{{#useOas2}}
@EnableSwagger2
{{/useOas2}}
{{^useOas2}}
@EnableOpenApi
{{/useOas2}}
@ComponentScan(basePackages = { "{{basePackage}}", "{{apiPackage}}" , "{{configPackage}}"})
public class Swagger2SpringBoot implements CommandLineRunner {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,27 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
{{>generatedAnnotation}}
@Configuration
public class SwaggerUiConfiguration implements WebMvcConfigurer {
@Override
{{#useOas2}}
public void addResourceHandlers(ResourceHandlerRegistry registry) {
{{#useOas2}}
registry
.addResourceHandler("/swagger-ui.html")
.addResourceLocations("classpath:/META-INF/resources/");
registry
.addResourceHandler("/webjars/**")
.addResourceLocations("classpath:/META-INF/resources/webjars/");
{{/useOas2}}
{{^useOas2}}
registry.
addResourceHandler("/swagger-ui/**")
.addResourceLocations("classpath:/META-INF/resources/webjars/springfox-swagger-ui/")
.resourceChain(false);
{{/useOas2}}
}

@Override
{{/useOas2}}
{{^useOas2}}
public void addViewControllers(ViewControllerRegistry registry) {
{{^useOas2}}
registry.addViewController("/swagger-ui/").setViewName("forward:/swagger-ui/index.html");
{{/useOas2}}
}
{{/useOas2}}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
springfox.documentation.open-api.v3.path=/api-docs
springdoc.api-docs.path=/api-docs
server.servlet.contextPath={{^contextPath}}/{{/contextPath}}{{#contextPath}}{{contextPath}}{{/contextPath}}
server.port={{serverPort}}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<maven.compiler.release>17</maven.compiler.release>
<springboot-version>3.1.1</springboot-version>
<swagger-annotations-version>2.2.14</swagger-annotations-version>
<springdoc-version>1.7.0</springdoc-version>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
Expand Down Expand Up @@ -74,6 +75,12 @@
<version>2.10.1</version>
</dependency>
{{/notNullJacksonAnnotation}}
<!-- SpringDoc dependencies -->
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>${springdoc-version}</version>
</dependency>

<dependency>
<groupId>io.swagger.core.v3</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,6 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
{{>generatedAnnotation}}
@Configuration
public class SwaggerUiConfiguration implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.
addResourceHandler("/swagger-ui/**")
.addResourceLocations("classpath:/META-INF/resources/webjars/springfox-swagger-ui/")
.resourceChain(false);
}
@Override
public void addViewControllers(ViewControllerRegistry registry) {
Expand Down
Loading

0 comments on commit c69a87b

Please sign in to comment.