forked from loafle/openapi-generator-original
Merge remote-tracking branch 'origin/master' into 2.3.0
This commit is contained in:
commit
f4d78079de
2
.gitignore
vendored
2
.gitignore
vendored
@ -5,7 +5,7 @@ out/
|
||||
*.iws
|
||||
classpath.txt
|
||||
version.properties
|
||||
!modules/swagger-codegen-cli/src/main/resources/version.properties
|
||||
!modules/swagger-codegen/src/main/resources/version.properties
|
||||
.project
|
||||
.classpath
|
||||
lib/*
|
||||
|
@ -18,7 +18,6 @@
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
<excludes>
|
||||
<exclude>logback.xml</exclude>
|
||||
</excludes>
|
||||
@ -79,17 +78,6 @@
|
||||
<artifactId>swagger-codegen</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<!--https://github.com/airlift/airline-->
|
||||
<dependency>
|
||||
<groupId>io.airlift</groupId>
|
||||
<artifactId>airline</artifactId>
|
||||
<version>0.7</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.googlecode.lambdaj</groupId>
|
||||
<artifactId>lambdaj</artifactId>
|
||||
<version>2.3.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-simple</artifactId>
|
||||
|
@ -1 +0,0 @@
|
||||
version = ${project.version}
|
@ -16,6 +16,7 @@
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
<excludes>
|
||||
<exclude>logback.xml</exclude>
|
||||
</excludes>
|
||||
@ -249,6 +250,16 @@
|
||||
<artifactId>commons-cli</artifactId>
|
||||
<version>${commons-cli-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.airlift</groupId>
|
||||
<artifactId>airline</artifactId>
|
||||
<version>0.7</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.googlecode.lambdaj</groupId>
|
||||
<artifactId>lambdaj</artifactId>
|
||||
<version>2.3.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.testng</groupId>
|
||||
<artifactId>testng</artifactId>
|
||||
|
@ -2,6 +2,7 @@ package io.swagger.codegen;
|
||||
|
||||
import com.samskivert.mustache.Mustache;
|
||||
import com.samskivert.mustache.Template;
|
||||
import io.swagger.codegen.cmd.Version;
|
||||
import io.swagger.codegen.ignore.CodegenIgnoreProcessor;
|
||||
import io.swagger.models.*;
|
||||
import io.swagger.models.auth.OAuth2Definition;
|
||||
@ -10,6 +11,7 @@ import io.swagger.models.parameters.Parameter;
|
||||
import io.swagger.util.Json;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.joda.time.DateTime;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -17,8 +19,6 @@ import org.slf4j.LoggerFactory;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
protected final Logger LOGGER = LoggerFactory.getLogger(DefaultGenerator.class);
|
||||
protected CodegenConfig config;
|
||||
@ -127,8 +127,8 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
config.processOpts();
|
||||
config.preprocessSwagger(swagger);
|
||||
// TODO need to obtain version from a file instead of hardcoding it
|
||||
config.additionalProperties().put("generatorVersion", "2.2.3-SNAPSHOT");
|
||||
config.additionalProperties().put("generatedDate", DateTime.now().toString());
|
||||
config.additionalProperties().put("generatorVersion", Version.readVersionFromResources());
|
||||
config.additionalProperties().put("generatorClass", config.getClass().getName());
|
||||
config.additionalProperties().put("inputSpec", config.getInputSpec());
|
||||
if (swagger.getVendorExtensions() != null) {
|
||||
|
@ -13,7 +13,6 @@ import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
||||
public class SpringCodegen extends AbstractJavaCodegen implements BeanValidationFeatures {
|
||||
|
@ -1,3 +1,9 @@
|
||||
/**
|
||||
* NOTE: This class is auto generated by the swagger code generator program ({{{generatorVersion}}}).
|
||||
* https://github.com/swagger-api/swagger-codegen
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
package {{package}};
|
||||
|
||||
{{#imports}}import {{import}};
|
||||
|
@ -32,6 +32,12 @@ import javax.validation.Valid;
|
||||
@Controller
|
||||
{{#operations}}
|
||||
public class {{classname}}Controller implements {{classname}} {
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
public {{classname}}Controller(ObjectMapper objectMapper) {
|
||||
this.objectMapper = objectMapper;
|
||||
}
|
||||
|
||||
{{#isDelegate}}
|
||||
private final {{classname}}Delegate delegate;
|
||||
|
||||
@ -49,11 +55,7 @@ public class {{classname}}Controller implements {{classname}} {
|
||||
{{^isDelegate}}
|
||||
{{^async}}
|
||||
{{#examples}}
|
||||
{{#-first}}
|
||||
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
{{/-first}}
|
||||
if (accept != null && accept.contains("{{{contentType}}}")) {
|
||||
return new ResponseEntity<{{>returnTypes}}>(objectMapper.readValue("{{#lambdaRemoveLineBreak}}{{#lambdaEscapeDoubleQuote}}{{{example}}}{{/lambdaEscapeDoubleQuote}}{{/lambdaRemoveLineBreak}}", {{>exampleReturnTypes}}.class), HttpStatus.OK);
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
|
||||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||
@ -66,21 +67,23 @@ public class SwaggerUiConfiguration extends WebMvcConfigurerAdapter {
|
||||
}
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Jackson2ObjectMapperBuilder builder() {
|
||||
Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder()
|
||||
.indentOutput(true)
|
||||
.featuresToDisable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
|
||||
.dateFormat(new RFC3339DateFormat());
|
||||
return builder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
|
||||
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json()
|
||||
.featuresToDisable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
|
||||
.dateFormat(new RFC3339DateFormat())
|
||||
.build();
|
||||
{{#threetenbp}}
|
||||
ThreeTenModule module = new ThreeTenModule();
|
||||
module.addDeserializer(Instant.class, CustomInstantDeserializer.INSTANT);
|
||||
module.addDeserializer(OffsetDateTime.class, CustomInstantDeserializer.OFFSET_DATE_TIME);
|
||||
module.addDeserializer(ZonedDateTime.class, CustomInstantDeserializer.ZONED_DATE_TIME);
|
||||
objectMapper.registerModule(module);
|
||||
{{/threetenbp}}
|
||||
converters.add(new MappingJackson2HttpMessageConverter(objectMapper));
|
||||
converters.add(new MappingJackson2HttpMessageConverter(objectMapper()));
|
||||
super.configureMessageConverters(converters);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ObjectMapper objectMapper(){
|
||||
return builder().build();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1 @@
|
||||
version = ${project.version}
|
@ -9,8 +9,8 @@ buildscript {
|
||||
jcenter()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:1.5.+'
|
||||
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
|
||||
classpath 'com.android.tools.build:gradle:2.3.+'
|
||||
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
|
||||
}
|
||||
}
|
||||
|
||||
@ -25,11 +25,11 @@ if(hasProperty('target') && target == 'android') {
|
||||
apply plugin: 'com.github.dcendents.android-maven'
|
||||
|
||||
android {
|
||||
compileSdkVersion 23
|
||||
buildToolsVersion '23.0.2'
|
||||
compileSdkVersion 25
|
||||
buildToolsVersion '25.0.2'
|
||||
defaultConfig {
|
||||
minSdkVersion 14
|
||||
targetSdkVersion 23
|
||||
targetSdkVersion 25
|
||||
}
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_7
|
||||
|
@ -1,3 +1,9 @@
|
||||
/**
|
||||
* NOTE: This class is auto generated by the swagger code generator program (2.3.0-SNAPSHOT).
|
||||
* https://github.com/swagger-api/swagger-codegen
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
package io.swagger.api;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
@ -7,4 +7,10 @@ import javax.validation.Valid;
|
||||
|
||||
@Controller
|
||||
public class FakeApiController implements FakeApi {
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
public FakeApiController(ObjectMapper objectMapper) {
|
||||
this.objectMapper = objectMapper;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,3 +1,9 @@
|
||||
/**
|
||||
* NOTE: This class is auto generated by the swagger code generator program (2.3.0-SNAPSHOT).
|
||||
* https://github.com/swagger-api/swagger-codegen
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
package io.swagger.api;
|
||||
|
||||
import io.swagger.model.Client;
|
||||
|
@ -7,4 +7,10 @@ import javax.validation.Valid;
|
||||
|
||||
@Controller
|
||||
public class FakeClassnameTestApiController implements FakeClassnameTestApi {
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
public FakeClassnameTestApiController(ObjectMapper objectMapper) {
|
||||
this.objectMapper = objectMapper;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,3 +1,9 @@
|
||||
/**
|
||||
* NOTE: This class is auto generated by the swagger code generator program (2.3.0-SNAPSHOT).
|
||||
* https://github.com/swagger-api/swagger-codegen
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
package io.swagger.api;
|
||||
|
||||
import io.swagger.model.ModelApiResponse;
|
||||
|
@ -7,4 +7,10 @@ import javax.validation.Valid;
|
||||
|
||||
@Controller
|
||||
public class PetApiController implements PetApi {
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
public PetApiController(ObjectMapper objectMapper) {
|
||||
this.objectMapper = objectMapper;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,3 +1,9 @@
|
||||
/**
|
||||
* NOTE: This class is auto generated by the swagger code generator program (2.3.0-SNAPSHOT).
|
||||
* https://github.com/swagger-api/swagger-codegen
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
package io.swagger.api;
|
||||
|
||||
import java.util.Map;
|
||||
|
@ -7,4 +7,10 @@ import javax.validation.Valid;
|
||||
|
||||
@Controller
|
||||
public class StoreApiController implements StoreApi {
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
public StoreApiController(ObjectMapper objectMapper) {
|
||||
this.objectMapper = objectMapper;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,3 +1,9 @@
|
||||
/**
|
||||
* NOTE: This class is auto generated by the swagger code generator program (2.3.0-SNAPSHOT).
|
||||
* https://github.com/swagger-api/swagger-codegen
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
package io.swagger.api;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -7,4 +7,10 @@ import javax.validation.Valid;
|
||||
|
||||
@Controller
|
||||
public class UserApiController implements UserApi {
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
public UserApiController(ObjectMapper objectMapper) {
|
||||
this.objectMapper = objectMapper;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
|
||||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||
@ -58,14 +59,23 @@ public class SwaggerUiConfiguration extends WebMvcConfigurerAdapter {
|
||||
}
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Jackson2ObjectMapperBuilder builder() {
|
||||
Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder()
|
||||
.indentOutput(true)
|
||||
.featuresToDisable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
|
||||
.dateFormat(new RFC3339DateFormat());
|
||||
return builder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
|
||||
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json()
|
||||
.featuresToDisable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
|
||||
.dateFormat(new RFC3339DateFormat())
|
||||
.build();
|
||||
converters.add(new MappingJackson2HttpMessageConverter(objectMapper));
|
||||
converters.add(new MappingJackson2HttpMessageConverter(objectMapper()));
|
||||
super.configureMessageConverters(converters);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ObjectMapper objectMapper(){
|
||||
return builder().build();
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,9 @@
|
||||
/**
|
||||
* NOTE: This class is auto generated by the swagger code generator program (2.3.0-SNAPSHOT).
|
||||
* https://github.com/swagger-api/swagger-codegen
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
package io.swagger.api;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
@ -26,11 +26,15 @@ import javax.validation.Valid;
|
||||
|
||||
@Controller
|
||||
public class FakeApiController implements FakeApi {
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
public FakeApiController(ObjectMapper objectMapper) {
|
||||
this.objectMapper = objectMapper;
|
||||
}
|
||||
|
||||
public ResponseEntity<Client> testClientModel(@ApiParam(value = "client model" ,required=true ) @Valid @RequestBody Client body,
|
||||
@RequestHeader("Accept") String accept) throws IOException {
|
||||
// do some magic!
|
||||
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
if (accept != null && accept.contains("application/json")) {
|
||||
return new ResponseEntity<Client>(objectMapper.readValue("{ \"client\" : \"aeiou\"}", Client.class), HttpStatus.OK);
|
||||
|
@ -1,3 +1,9 @@
|
||||
/**
|
||||
* NOTE: This class is auto generated by the swagger code generator program (2.3.0-SNAPSHOT).
|
||||
* https://github.com/swagger-api/swagger-codegen
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
package io.swagger.api;
|
||||
|
||||
import io.swagger.model.Client;
|
||||
|
@ -23,11 +23,15 @@ import javax.validation.Valid;
|
||||
|
||||
@Controller
|
||||
public class FakeClassnameTestApiController implements FakeClassnameTestApi {
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
public FakeClassnameTestApiController(ObjectMapper objectMapper) {
|
||||
this.objectMapper = objectMapper;
|
||||
}
|
||||
|
||||
public ResponseEntity<Client> testClassname(@ApiParam(value = "client model" ,required=true ) @Valid @RequestBody Client body,
|
||||
@RequestHeader("Accept") String accept) throws IOException {
|
||||
// do some magic!
|
||||
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
if (accept != null && accept.contains("application/json")) {
|
||||
return new ResponseEntity<Client>(objectMapper.readValue("{ \"client\" : \"aeiou\"}", Client.class), HttpStatus.OK);
|
||||
|
@ -1,3 +1,9 @@
|
||||
/**
|
||||
* NOTE: This class is auto generated by the swagger code generator program (2.3.0-SNAPSHOT).
|
||||
* https://github.com/swagger-api/swagger-codegen
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
package io.swagger.api;
|
||||
|
||||
import io.swagger.model.ModelApiResponse;
|
||||
|
@ -25,6 +25,12 @@ import javax.validation.Valid;
|
||||
|
||||
@Controller
|
||||
public class PetApiController implements PetApi {
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
public PetApiController(ObjectMapper objectMapper) {
|
||||
this.objectMapper = objectMapper;
|
||||
}
|
||||
|
||||
public ResponseEntity<Void> addPet(@ApiParam(value = "Pet object that needs to be added to the store" ,required=true ) @Valid @RequestBody Pet body,
|
||||
@RequestHeader("Accept") String accept) {
|
||||
// do some magic!
|
||||
@ -41,13 +47,12 @@ public class PetApiController implements PetApi {
|
||||
public ResponseEntity<List<Pet>> findPetsByStatus( @NotNull@ApiParam(value = "Status values that need to be considered for filter", required = true, allowableValues = "available, pending, sold") @RequestParam(value = "status", required = true) List<String> status,
|
||||
@RequestHeader("Accept") String accept) throws IOException {
|
||||
// do some magic!
|
||||
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
if (accept != null && accept.contains("application/xml")) {
|
||||
return new ResponseEntity<List<Pet>>(objectMapper.readValue("<Pet> <id>123456789</id> <name>doggie</name> <photoUrls> <photoUrls>aeiou</photoUrls> </photoUrls> <tags> </tags> <status>aeiou</status></Pet>", List.class), HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
if (accept != null && accept.contains("application/json")) {
|
||||
return new ResponseEntity<List<Pet>>(objectMapper.readValue("[ { \"photoUrls\" : [ \"aeiou\" ], \"name\" : \"doggie\", \"id\" : 0, \"category\" : { \"name\" : \"aeiou\", \"id\" : 6 }, \"tags\" : [ { \"name\" : \"aeiou\", \"id\" : 1 } ], \"status\" : \"available\"} ]", List.class), HttpStatus.OK);
|
||||
}
|
||||
@ -58,13 +63,12 @@ public class PetApiController implements PetApi {
|
||||
public ResponseEntity<List<Pet>> findPetsByTags( @NotNull@ApiParam(value = "Tags to filter by", required = true) @RequestParam(value = "tags", required = true) List<String> tags,
|
||||
@RequestHeader("Accept") String accept) throws IOException {
|
||||
// do some magic!
|
||||
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
if (accept != null && accept.contains("application/xml")) {
|
||||
return new ResponseEntity<List<Pet>>(objectMapper.readValue("<Pet> <id>123456789</id> <name>doggie</name> <photoUrls> <photoUrls>aeiou</photoUrls> </photoUrls> <tags> </tags> <status>aeiou</status></Pet>", List.class), HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
if (accept != null && accept.contains("application/json")) {
|
||||
return new ResponseEntity<List<Pet>>(objectMapper.readValue("[ { \"photoUrls\" : [ \"aeiou\" ], \"name\" : \"doggie\", \"id\" : 0, \"category\" : { \"name\" : \"aeiou\", \"id\" : 6 }, \"tags\" : [ { \"name\" : \"aeiou\", \"id\" : 1 } ], \"status\" : \"available\"} ]", List.class), HttpStatus.OK);
|
||||
}
|
||||
@ -75,13 +79,12 @@ public class PetApiController implements PetApi {
|
||||
public ResponseEntity<Pet> getPetById(@ApiParam(value = "ID of pet to return",required=true ) @PathVariable("petId") Long petId,
|
||||
@RequestHeader("Accept") String accept) throws IOException {
|
||||
// do some magic!
|
||||
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
if (accept != null && accept.contains("application/xml")) {
|
||||
return new ResponseEntity<Pet>(objectMapper.readValue("<Pet> <id>123456789</id> <name>doggie</name> <photoUrls> <photoUrls>aeiou</photoUrls> </photoUrls> <tags> </tags> <status>aeiou</status></Pet>", Pet.class), HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
if (accept != null && accept.contains("application/json")) {
|
||||
return new ResponseEntity<Pet>(objectMapper.readValue("{ \"photoUrls\" : [ \"aeiou\" ], \"name\" : \"doggie\", \"id\" : 0, \"category\" : { \"name\" : \"aeiou\", \"id\" : 6 }, \"tags\" : [ { \"name\" : \"aeiou\", \"id\" : 1 } ], \"status\" : \"available\"}", Pet.class), HttpStatus.OK);
|
||||
}
|
||||
@ -108,8 +111,6 @@ public class PetApiController implements PetApi {
|
||||
@ApiParam(value = "file detail") @RequestPart("file") MultipartFile file,
|
||||
@RequestHeader("Accept") String accept) throws IOException {
|
||||
// do some magic!
|
||||
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
if (accept != null && accept.contains("application/json")) {
|
||||
return new ResponseEntity<ModelApiResponse>(objectMapper.readValue("{ \"code\" : 0, \"type\" : \"aeiou\", \"message\" : \"aeiou\"}", ModelApiResponse.class), HttpStatus.OK);
|
||||
|
@ -1,3 +1,9 @@
|
||||
/**
|
||||
* NOTE: This class is auto generated by the swagger code generator program (2.3.0-SNAPSHOT).
|
||||
* https://github.com/swagger-api/swagger-codegen
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
package io.swagger.api;
|
||||
|
||||
import java.util.Map;
|
||||
|
@ -24,6 +24,12 @@ import javax.validation.Valid;
|
||||
|
||||
@Controller
|
||||
public class StoreApiController implements StoreApi {
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
public StoreApiController(ObjectMapper objectMapper) {
|
||||
this.objectMapper = objectMapper;
|
||||
}
|
||||
|
||||
public ResponseEntity<Void> deleteOrder(@ApiParam(value = "ID of the order that needs to be deleted",required=true ) @PathVariable("order_id") String orderId,
|
||||
@RequestHeader("Accept") String accept) {
|
||||
// do some magic!
|
||||
@ -32,8 +38,6 @@ public class StoreApiController implements StoreApi {
|
||||
|
||||
public ResponseEntity<Map<String, Integer>> getInventory(@RequestHeader("Accept") String accept) throws IOException {
|
||||
// do some magic!
|
||||
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
if (accept != null && accept.contains("application/json")) {
|
||||
return new ResponseEntity<Map<String, Integer>>(objectMapper.readValue("{ \"key\" : 0}", Map.class), HttpStatus.OK);
|
||||
@ -45,13 +49,12 @@ public class StoreApiController implements StoreApi {
|
||||
public ResponseEntity<Order> getOrderById( @Min(1) @Max(5)@ApiParam(value = "ID of pet that needs to be fetched",required=true ) @PathVariable("order_id") Long orderId,
|
||||
@RequestHeader("Accept") String accept) throws IOException {
|
||||
// do some magic!
|
||||
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
if (accept != null && accept.contains("application/xml")) {
|
||||
return new ResponseEntity<Order>(objectMapper.readValue("<Order> <id>123456789</id> <petId>123456789</petId> <quantity>123</quantity> <shipDate>2000-01-23T04:56:07.000Z</shipDate> <status>aeiou</status> <complete>true</complete></Order>", Order.class), HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
if (accept != null && accept.contains("application/json")) {
|
||||
return new ResponseEntity<Order>(objectMapper.readValue("{ \"petId\" : 6, \"quantity\" : 1, \"id\" : 0, \"shipDate\" : \"2000-01-23T04:56:07.000+00:00\", \"complete\" : false, \"status\" : \"placed\"}", Order.class), HttpStatus.OK);
|
||||
}
|
||||
@ -62,13 +65,12 @@ public class StoreApiController implements StoreApi {
|
||||
public ResponseEntity<Order> placeOrder(@ApiParam(value = "order placed for purchasing the pet" ,required=true ) @Valid @RequestBody Order body,
|
||||
@RequestHeader("Accept") String accept) throws IOException {
|
||||
// do some magic!
|
||||
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
if (accept != null && accept.contains("application/xml")) {
|
||||
return new ResponseEntity<Order>(objectMapper.readValue("<Order> <id>123456789</id> <petId>123456789</petId> <quantity>123</quantity> <shipDate>2000-01-23T04:56:07.000Z</shipDate> <status>aeiou</status> <complete>true</complete></Order>", Order.class), HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
if (accept != null && accept.contains("application/json")) {
|
||||
return new ResponseEntity<Order>(objectMapper.readValue("{ \"petId\" : 6, \"quantity\" : 1, \"id\" : 0, \"shipDate\" : \"2000-01-23T04:56:07.000+00:00\", \"complete\" : false, \"status\" : \"placed\"}", Order.class), HttpStatus.OK);
|
||||
}
|
||||
|
@ -1,3 +1,9 @@
|
||||
/**
|
||||
* NOTE: This class is auto generated by the swagger code generator program (2.3.0-SNAPSHOT).
|
||||
* https://github.com/swagger-api/swagger-codegen
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
package io.swagger.api;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -24,6 +24,12 @@ import javax.validation.Valid;
|
||||
|
||||
@Controller
|
||||
public class UserApiController implements UserApi {
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
public UserApiController(ObjectMapper objectMapper) {
|
||||
this.objectMapper = objectMapper;
|
||||
}
|
||||
|
||||
public ResponseEntity<Void> createUser(@ApiParam(value = "Created user object" ,required=true ) @Valid @RequestBody User body,
|
||||
@RequestHeader("Accept") String accept) {
|
||||
// do some magic!
|
||||
@ -51,13 +57,12 @@ public class UserApiController implements UserApi {
|
||||
public ResponseEntity<User> getUserByName(@ApiParam(value = "The name that needs to be fetched. Use user1 for testing. ",required=true ) @PathVariable("username") String username,
|
||||
@RequestHeader("Accept") String accept) throws IOException {
|
||||
// do some magic!
|
||||
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
if (accept != null && accept.contains("application/xml")) {
|
||||
return new ResponseEntity<User>(objectMapper.readValue("<User> <id>123456789</id> <username>aeiou</username> <firstName>aeiou</firstName> <lastName>aeiou</lastName> <email>aeiou</email> <password>aeiou</password> <phone>aeiou</phone> <userStatus>123</userStatus></User>", User.class), HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
if (accept != null && accept.contains("application/json")) {
|
||||
return new ResponseEntity<User>(objectMapper.readValue("{ \"firstName\" : \"aeiou\", \"lastName\" : \"aeiou\", \"password\" : \"aeiou\", \"userStatus\" : 6, \"phone\" : \"aeiou\", \"id\" : 0, \"email\" : \"aeiou\", \"username\" : \"aeiou\"}", User.class), HttpStatus.OK);
|
||||
}
|
||||
@ -69,13 +74,12 @@ public class UserApiController implements UserApi {
|
||||
@NotNull@ApiParam(value = "The password for login in clear text", required = true) @RequestParam(value = "password", required = true) String password,
|
||||
@RequestHeader("Accept") String accept) throws IOException {
|
||||
// do some magic!
|
||||
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
if (accept != null && accept.contains("application/xml")) {
|
||||
return new ResponseEntity<String>(objectMapper.readValue("aeiou", String.class), HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
if (accept != null && accept.contains("application/json")) {
|
||||
return new ResponseEntity<String>(objectMapper.readValue("\"aeiou\"", String.class), HttpStatus.OK);
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
|
||||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||
@ -62,19 +63,23 @@ public class SwaggerUiConfiguration extends WebMvcConfigurerAdapter {
|
||||
}
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Jackson2ObjectMapperBuilder builder() {
|
||||
Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder()
|
||||
.indentOutput(true)
|
||||
.featuresToDisable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
|
||||
.dateFormat(new RFC3339DateFormat());
|
||||
return builder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
|
||||
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json()
|
||||
.featuresToDisable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS)
|
||||
.dateFormat(new RFC3339DateFormat())
|
||||
.build();
|
||||
ThreeTenModule module = new ThreeTenModule();
|
||||
module.addDeserializer(Instant.class, CustomInstantDeserializer.INSTANT);
|
||||
module.addDeserializer(OffsetDateTime.class, CustomInstantDeserializer.OFFSET_DATE_TIME);
|
||||
module.addDeserializer(ZonedDateTime.class, CustomInstantDeserializer.ZONED_DATE_TIME);
|
||||
objectMapper.registerModule(module);
|
||||
converters.add(new MappingJackson2HttpMessageConverter(objectMapper));
|
||||
converters.add(new MappingJackson2HttpMessageConverter(objectMapper()));
|
||||
super.configureMessageConverters(converters);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ObjectMapper objectMapper(){
|
||||
return builder().build();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user