Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moved to Swagger 2 annotations as well as SpringDoc instead of Springfox #4779

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -445,8 +445,9 @@ public void processOpts() {
importMapping.put("JsonSerialize", "com.fasterxml.jackson.databind.annotation.JsonSerialize");

// imports for pojos
importMapping.put("ApiModelProperty", "io.swagger.annotations.ApiModelProperty");
importMapping.put("ApiModel", "io.swagger.annotations.ApiModel");
//importMapping.put("ApiModelProperty", "io.swagger.v3.oas.annotations.media.Schema");
//importMapping.put("ApiModel", "io.swagger.v3.oas.annotations.media.Schema");
importMapping.put("Schema", "io.swagger.v3.oas.annotations.media.Schema");
importMapping.put("BigDecimal", "java.math.BigDecimal");
importMapping.put("JsonProperty", "com.fasterxml.jackson.annotation.JsonProperty");
importMapping.put("JsonSubTypes", "com.fasterxml.jackson.annotation.JsonSubTypes");
Expand Down Expand Up @@ -986,7 +987,8 @@ public CodegenModel fromModel(String name, Schema model) {
Map<String, Schema> allDefinitions = ModelUtils.getSchemas(this.openAPI);
CodegenModel codegenModel = super.fromModel(name, model);
if (codegenModel.description != null) {
codegenModel.imports.add("ApiModel");
//codegenModel.imports.add("ApiModel");
codegenModel.imports.add("Schema");
}
if (codegenModel.discriminator != null && additionalProperties.containsKey("jackson")) {
codegenModel.imports.add("JsonSubTypes");
Expand Down Expand Up @@ -1031,8 +1033,9 @@ public void postProcessModelProperty(CodegenModel model, CodegenProperty propert

if (!BooleanUtils.toBoolean(model.isEnum)) {
// needed by all pojos, but not enums
model.imports.add("ApiModelProperty");
model.imports.add("ApiModel");
model.imports.add("Schema");
//model.imports.add("ApiModel");
//model.imports.add("ApiModelProperty");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ public void processOpts() {


if (!this.apiFirst && !this.reactive) {
additionalProperties.put("useSpringfox", true);
additionalProperties.put("useSpringDoc", true);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ package {{package}};

{{#imports}}import {{import}};
{{/imports}}
import io.swagger.annotations.*;
import io.swagger.v3.oas.annotations.*;
import io.swagger.v3.oas.annotations.enums.*;
import io.swagger.v3.oas.annotations.media.*;
import io.swagger.v3.oas.annotations.responses.*;
import io.swagger.v3.oas.annotations.security.*;
{{#jdk8-no-delegate}}
{{#virtualService}}
import io.virtualan.annotation.ApiVirtual;
Expand Down Expand Up @@ -61,7 +65,6 @@ import java.util.concurrent.{{^jdk8}}Callable{{/jdk8}}{{#jdk8}}CompletableFuture
{{#useBeanValidation}}
@Validated
{{/useBeanValidation}}
@Api(value = "{{{baseName}}}", description = "the {{{baseName}}} API")
{{#operations}}
{{#virtualService}}
@VirtualService
Expand Down Expand Up @@ -107,22 +110,10 @@ public interface {{classname}} {
{{#virtualService}}
@ApiVirtual
{{/virtualService}}
@ApiOperation(value = "{{{summary}}}", nickname = "{{{operationId}}}", notes = "{{{notes}}}"{{#returnBaseType}}, response = {{{returnBaseType}}}.class{{/returnBaseType}}{{#returnContainer}}, responseContainer = "{{{returnContainer}}}"{{/returnContainer}}{{#hasAuthMethods}}, authorizations = {
{{#authMethods}}@Authorization(value = "{{name}}"{{#isOAuth}}, scopes = {
{{#scopes}}@AuthorizationScope(scope = "{{scope}}", description = "{{description}}"){{#hasMore}},
{{/hasMore}}{{/scopes}}
}{{/isOAuth}}){{#hasMore}},
{{/hasMore}}{{/authMethods}}
}{{/hasAuthMethods}}, tags={ {{#vendorExtensions.x-tags}}"{{tag}}",{{/vendorExtensions.x-tags}} })
@ApiResponses(value = { {{#responses}}
@ApiResponse(code = {{{code}}}, message = "{{{message}}}"{{#baseType}}, response = {{{baseType}}}.class{{/baseType}}{{#containerType}}, responseContainer = "{{{containerType}}}"{{/containerType}}){{#hasMore}},{{/hasMore}}{{/responses}} })
{{#implicitHeaders}}
@ApiImplicitParams({
{{#headerParams}}
{{>implicitHeader}}
{{/headerParams}}
})
{{/implicitHeaders}}
@Operation(summary = "{{{summary}}}", operationId = "{{{operationId}}}", description = "{{{notes}}}", responses={ {{#responses}}
@ApiResponse(responseCode = "{{{code}}}", description = "{{{message}}}"{{#baseType}}, content = @Content(schema = @Schema(implementation = {{{baseType}}}.class)){{/baseType}}){{#hasMore}},{{/hasMore}}{{/responses}} }
{{#implicitHeaders}}, parameters = { {{#headerParams}}{{>implicitHeader}}{{/headerParams}} }{{/implicitHeaders}}
{{#hasAuthMethods}}, security = { {{#authMethods}}@SecurityRequirement(name = "{{name}}"{{#isOAuth}}, scopes = { {{#scopes}}"{{scope}}"{{#hasMore}}, {{/hasMore}}{{/scopes}} }{{/isOAuth}}){{#hasMore}},{{/hasMore}}{{/authMethods}} }{{/hasAuthMethods}}, tags={ {{#vendorExtensions.x-tags}}"{{tag}}",{{/vendorExtensions.x-tags}} })
@RequestMapping(value = "{{{path}}}",{{#singleContentTypes}}{{#hasProduces}}
produces = "{{{vendorExtensions.x-accepts}}}", {{/hasProduces}}{{#hasConsumes}}
consumes = "{{{vendorExtensions.x-contentType}}}",{{/hasConsumes}}{{/singleContentTypes}}{{^singleContentTypes}}{{#hasProduces}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ package {{package}};
{{^jdk8}}
{{#imports}}import {{import}};
{{/imports}}
import io.swagger.annotations.*;
import io.swagger.v3.oas.annotations.*;
import io.swagger.v3.oas.annotations.enums.*;
import io.swagger.v3.oas.annotations.media.*;
import io.swagger.v3.oas.annotations.responses.*;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package {{package}};

{{#imports}}import {{import}};
{{/imports}}
import io.swagger.annotations.*;
import io.swagger.v3.oas.annotations.*;
import io.swagger.v3.oas.annotations.media.*;
import io.swagger.v3.oas.annotations.responses.*;
{{#jdk8}}
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{{#isBodyParam}}@ApiParam(value = "{{{description}}}" {{#required}},required=true{{/required}} {{^isContainer}}{{#allowableValues}}, allowableValues="{{{allowableValues}}}"{{/allowableValues}}{{#defaultValue}}, defaultValue={{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{{defaultValue}}}{{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{/defaultValue}}{{/isContainer}}) {{#useBeanValidation}}@Valid{{/useBeanValidation}} @RequestBody{{^required}}(required = false){{/required}} {{^reactive}}{{{dataType}}}{{/reactive}}{{#reactive}}{{^isListContainer}}Mono{{/isListContainer}}{{#isListContainer}}Flux{{/isListContainer}}<{{{baseType}}}>{{/reactive}} {{paramName}}{{/isBodyParam}}
{{#isBodyParam}}@Parameter(description = "{{{description}}}" {{#required}},required=true{{/required}}{{^isContainer}}{{#allowableValues}}{{#defaultValue}}, schema=@Schema(allowableValues="{{{allowableValues}}}", defaultValue={{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{{defaultValue}}}{{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}){{/defaultValue}}{{/allowableValues}}{{^allowableValues}}{{#defaultValue}}, schema=@Schema(defaultValue={{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{{defaultValue}}}{{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}){{/defaultValue}}{{/allowableValues}}{{#allowableValues}}{{^defaultValue}}, schema=@Schema(allowableValues="{{{allowableValues}}}"){{/defaultValue}}{{/allowableValues}}{{/isContainer}}){{#useBeanValidation}}@Valid{{/useBeanValidation}} @RequestBody {{^reactive}}{{{dataType}}}{{/reactive}}{{#reactive}}{{^isListContainer}}Mono{{/isListContainer}}{{#isListContainer}}Flux{{/isListContainer}}<{{{baseType}}}>{{/reactive}} {{paramName}}{{/isBodyParam}}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{{#isFormParam}}{{^isFile}}@ApiParam(value = "{{{description}}}"{{#required}}, required=true{{/required}}{{#allowableValues}}, allowableValues="{{#values}}{{{.}}}{{^-last}}, {{/-last}}{{#-last}}{{/-last}}{{/values}}"{{/allowableValues}}{{^isContainer}}{{#defaultValue}}, defaultValue={{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{{defaultValue}}}{{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{/defaultValue}}{{/isContainer}}) @RequestPart(value="{{baseName}}"{{#required}}, required=true{{/required}}{{^required}}, required=false{{/required}}) {{{dataType}}} {{paramName}}{{/isFile}}{{#isFile}}@ApiParam(value = "{{{description}}}") {{#useBeanValidation}}@Valid{{/useBeanValidation}} @RequestPart(value = "{{baseName}}") {{#isListContainer}}List<{{/isListContainer}}MultipartFile{{#isListContainer}}>{{/isListContainer}} {{baseName}}{{/isFile}}{{/isFormParam}}
{{#isFormParam}}{{^isFile}}@Parameter(description = "{{{description}}}"{{#required}}, required=true{{/required}}{{#allowableValues}}{{#defaultValue}}, schema=@Schema(allowableValues="{{#values}}{{{.}}}{{^-last}}, {{/-last}}{{#-last}}{{/-last}}{{/values}}"{{^isContainer}}, defaultValue={{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{{defaultValue}}}{{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{/isContainer}}){{/defaultValue}}{{/allowableValues}}{{#allowableValues}}{{^defaultValue}}, schema=@Schema(allowableValues="{{#values}}{{{.}}}{{^-last}}, {{/-last}}{{#-last}}{{/-last}}{{/values}}"){{/defaultValue}}{{/allowableValues}}{{^allowableValues}}{{#defaultValue}}{{^isContainer}}, schema=@Schema(defaultValue={{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{{defaultValue}}}{{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}){{/isContainer}}{{/defaultValue}}{{/allowableValues}}) @RequestParam(value="{{baseName}}"{{#required}}, required=true{{/required}}{{^required}}, required=false{{/required}}) {{{dataType}}} {{paramName}}{{/isFile}}{{#isFile}}@Parameter(description = "{{{description}}}") {{#useBeanValidation}}@Valid{{/useBeanValidation}} @RequestPart("{{baseName}}") {{#isListContainer}}List<{{/isListContainer}}MultipartFile{{#isListContainer}}>{{/isListContainer}} {{baseName}}{{/isFile}}{{/isFormParam}}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{{#isHeaderParam}}@ApiParam(value = "{{{description}}}" {{#required}},required=true{{/required}}{{#allowableValues}}, allowableValues="{{#values}}{{{.}}}{{^-last}}, {{/-last}}{{#-last}}{{/-last}}{{/values}}"{{/allowableValues}}{{^isContainer}}{{#defaultValue}}, defaultValue={{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{{defaultValue}}}{{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{/defaultValue}}{{/isContainer}}) @RequestHeader(value="{{baseName}}", required={{#required}}true{{/required}}{{^required}}false{{/required}}) {{>optionalDataType}} {{paramName}}{{/isHeaderParam}}
{{#isHeaderParam}}@Parameter(description = "{{{description}}}", in=ParameterIn.HEADER {{#required}}, required=true{{/required}}{{#allowableValues}}{{#defaultValue}}, schema=@Schema(allowableValues="{{#values}}{{{.}}}{{^-last}}, {{/-last}}{{#-last}}{{/-last}}{{/values}}"{{^isContainer}}, defaultValue={{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{{defaultValue}}}{{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{/isContainer}}){{/defaultValue}}{{/allowableValues}}{{#allowableValues}}{{^defaultValue}}, schema=@Schema(allowableValues="{{#values}}{{{.}}}{{^-last}}, {{/-last}}{{#-last}}{{/-last}}{{/values}}"){{/defaultValue}}{{/allowableValues}}{{^allowableValues}}{{#defaultValue}}{{^isContainer}}, schema=@Schema(defaultValue={{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}{{{defaultValue}}}{{^isString}}"{{/isString}}{{#isString}}{{#isEnum}}"{{/isEnum}}{{/isString}}){{/isContainer}}{{/defaultValue}}{{/allowableValues}})@RequestHeader(value="{{baseName}}", required={{#required}}true{{/required}}{{^required}}false{{/required}}) {{>optionalDataType}} {{paramName}}{{/isHeaderParam}}
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
package {{configPackage}};

{{^useSpringfox}}
{{^useSpringDoc}}
import com.fasterxml.jackson.dataformat.yaml.YAMLMapper;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.core.io.Resource;
{{/useSpringfox}}
{{/useSpringDoc}}
import org.springframework.stereotype.Controller;
{{^useSpringfox}}
{{^useSpringDoc}}
import org.springframework.util.StreamUtils;
import org.springframework.web.bind.annotation.GetMapping;
{{/useSpringfox}}
{{/useSpringDoc}}
import org.springframework.web.bind.annotation.RequestMapping;
{{^useSpringfox}}
{{^useSpringDoc}}
import org.springframework.web.bind.annotation.ResponseBody;
{{/useSpringfox}}
{{/useSpringDoc}}
{{#reactive}}
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.ServerResponse;
{{/reactive}}

{{^useSpringfox}}
{{^useSpringDoc}}
import java.io.IOException;
import java.io.InputStream;
{{/useSpringfox}}
{{/useSpringDoc}}
{{#reactive}}
import java.net.URI;
{{/reactive}}
{{^useSpringfox}}
{{^useSpringDoc}}
import java.nio.charset.Charset;
{{/useSpringfox}}
{{/useSpringDoc}}
{{#reactive}}

import static org.springframework.web.reactive.function.server.RequestPredicates.GET;
Expand All @@ -42,7 +42,7 @@ import static org.springframework.web.reactive.function.server.RouterFunctions.r
@Controller
public class HomeController {

{{^useSpringfox}}
{{^useSpringDoc}}
private static YAMLMapper yamlMapper = new YAMLMapper();

@Value("classpath:/openapi.yaml")
Expand All @@ -67,20 +67,20 @@ public class HomeController {
return yamlMapper.readValue(openapiContent(), Object.class);
}

{{/useSpringfox}}
{{/useSpringDoc}}
{{#reactive}}
@Bean
RouterFunction<ServerResponse> index() {
return route(
GET("/"),
req -> ServerResponse.temporaryRedirect(URI.create("{{#useSpringfox}}swagger-ui.html{{/useSpringfox}}{{^useSpringfox}}swagger-ui/index.html?url=../openapi.json{{/useSpringfox}}")).build()
req -> ServerResponse.temporaryRedirect(URI.create("{{#useSpringDoc}}swagger-ui.html{{/useSpringDoc}}{{^useSpringDoc}}swagger-ui/index.html?url=../openapi.json{{/useSpringDoc}}")).build()
);
}
{{/reactive}}
{{^reactive}}
@RequestMapping("/")
public String index() {
return "redirect:{{#useSpringfox}}swagger-ui.html{{/useSpringfox}}{{^useSpringfox}}swagger-ui/index.html?url=../openapi.json{{/useSpringfox}}";
return "redirect:{{#useSpringDoc}}swagger-ui.html{{/useSpringDoc}}{{^useSpringDoc}}swagger-ui/index.html?url=../openapi.json{{/useSpringDoc}}";
}
{{/reactive}}

Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{{#isHeaderParam}}@ApiImplicitParam(name = "{{{paramName}}}", value = "{{{description}}}", {{#required}}required=true,{{/required}} dataType = "{{{dataType}}}", paramType = "header"){{#hasMore}},{{/hasMore}}{{/isHeaderParam}}
{{#isHeaderParam}}@Parameter(name = "{{{paramName}}}", description = "{{{description}}}", {{#required}}required=true,{{/required}} in=ParameterIn.HEADER, schema = @Schema(implementation={{{dataType}}}.class)){{#hasMore}},{{/hasMore}}{{/isHeaderParam}}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ This server was generated by the [OpenAPI Generator](https://openapi-generator.t
By using the [OpenAPI-Spec](https://openapis.org), you can easily generate a server stub.
This is an example of building a OpenAPI-enabled server in Java using the SpringBoot framework.

{{#useSpringfox}}
The underlying library integrating OpenAPI to SpringBoot is [springfox](https://github.com/springfox/springfox)
{{#useSpringDoc}}
The underlying library integrating OpenAPI to SpringBoot is [springdoc](https://github.com/springdoc/springdoc-openapi)

{{/useSpringfox}}
{{/useSpringDoc}}
Start your server as a simple java application

{{^reactive}}
Expand Down Expand Up @@ -57,4 +57,4 @@ http://localhost:80//virtualan-ui.html.

How to use guide available in the Virtualan wiki
https://github.com/elan-venture/virtualan/wiki
{{/virtualService}}
{{/virtualService}}
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
{{#useSpringfox}}
springfox.documentation.swagger.v2.path=/api-docs
{{/useSpringfox}}
server.port={{serverPort}}
spring.jackson.date-format={{basePackage}}.RFC3339DateFormat
spring.jackson.serialization.WRITE_DATES_AS_TIMESTAMPS=false
Expand All @@ -9,4 +6,4 @@ virtual.datasource.driver-class-name=org.hsqldb.jdbcDriver
virtual.datasource.jdbcurl=jdbc:hsqldb:mem:dataSource
virtual.datasource.username=sa
virtual.datasource.password=
{{/virtualService}}
{{/virtualService}}
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
{{^reactive}}
import org.springframework.web.servlet.config.annotation.CorsRegistry;
{{^useSpringfox}}
{{^useSpringDoc}}
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
{{/useSpringfox}}
{{/useSpringDoc}}
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
{{^java8}}
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
{{/java8}}
{{/reactive}}
{{#reactive}}
import org.springframework.web.reactive.config.CorsRegistry;
{{^useSpringfox}}
{{^useSpringDoc}}
import org.springframework.web.reactive.config.ResourceHandlerRegistry;
{{/useSpringfox}}
{{/useSpringDoc}}
import org.springframework.web.reactive.config.CorsRegistry;
import org.springframework.web.reactive.config.WebFluxConfigurer;
{{/reactive}}

Expand Down Expand Up @@ -61,13 +61,13 @@ public class OpenAPI2SpringBoot implements CommandLineRunner {
.allowedMethods("*")
.allowedHeaders("Content-Type");
}*/
{{^useSpringfox}}
{{^useSpringDoc}}

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/swagger-ui/**").addResourceLocations("classpath:/META-INF/resources/webjars/swagger-ui/3.14.2/");
}
{{/useSpringfox}}
{{/useSpringDoc}}
};
}

Expand Down
Loading