Create a default implementation of delegate if none could be autowired (#92)

This commit is contained in:
Christophe Bornet 2018-05-24 14:50:05 +00:00 committed by William Cheng
parent 00f176ad95
commit a3aabd3908
20 changed files with 78 additions and 52 deletions

View File

@ -63,7 +63,10 @@ public interface {{classname}} {
{{/reactive}} {{/reactive}}
{{/isDelegate}} {{/isDelegate}}
{{#isDelegate}} {{#isDelegate}}
{{classname}}Delegate getDelegate();
default {{classname}}Delegate getDelegate() {
return new {{classname}}Delegate() {};
}
{{/isDelegate}} {{/isDelegate}}
{{/jdk8}} {{/jdk8}}
{{#operation}} {{#operation}}

View File

@ -27,14 +27,9 @@ import javax.validation.constraints.*;
import javax.validation.Valid; import javax.validation.Valid;
{{/useBeanValidation}} {{/useBeanValidation}}
{{/jdk8}} {{/jdk8}}
{{#jdk8-no-delegate}} {{#jdk8}}
import java.util.Optional; import java.util.Optional;
{{/jdk8-no-delegate}} {{/jdk8}}
{{^jdk8-no-delegate}}
{{#useOptional}}
import java.util.Optional;
{{/useOptional}}
{{/jdk8-no-delegate}}
{{^jdk8}} {{^jdk8}}
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -46,24 +41,28 @@ import java.util.concurrent.Callable;
@Controller @Controller
{{#operations}} {{#operations}}
public class {{classname}}Controller implements {{classname}} { public class {{classname}}Controller implements {{classname}} {
{{#isDelegate}} {{#isDelegate}}
private final {{classname}}Delegate delegate; private final {{classname}}Delegate delegate;
@org.springframework.beans.factory.annotation.Autowired public {{classname}}Controller(@org.springframework.beans.factory.annotation.Autowired(required = false) {{classname}}Delegate delegate) {
public {{classname}}Controller({{classname}}Delegate delegate) {
this.delegate = delegate;
}
{{#jdk8}} {{#jdk8}}
this.delegate = Optional.ofNullable(delegate).orElse(new {{classname}}Delegate() {});
}
@Override @Override
public {{classname}}Delegate getDelegate() { public {{classname}}Delegate getDelegate() {
return delegate; return delegate;
} }
{{/jdk8}} {{/jdk8}}
{{^jdk8}}
this.delegate = delegate;
}
{{/jdk8}}
{{/isDelegate}} {{/isDelegate}}
{{^isDelegate}} {{^isDelegate}}
{{^reactive}} {{^reactive}}
private final NativeWebRequest request; private final NativeWebRequest request;
@org.springframework.beans.factory.annotation.Autowired @org.springframework.beans.factory.annotation.Autowired
@ -77,9 +76,9 @@ public class {{classname}}Controller implements {{classname}} {
return Optional.ofNullable(request); return Optional.ofNullable(request);
} }
{{/jdk8}} {{/jdk8}}
{{/reactive}} {{/reactive}}
{{/isDelegate}} {{/isDelegate}}
{{^jdk8}} {{^jdk8}}
{{#operation}} {{#operation}}
public {{#responseWrapper}}{{.}}<{{/responseWrapper}}ResponseEntity<{{>returnTypes}}>{{#responseWrapper}}>{{/responseWrapper}} {{operationId}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{#hasMore}},{{/hasMore}}{{/allParams}}) { public {{#responseWrapper}}{{.}}<{{/responseWrapper}}ResponseEntity<{{>returnTypes}}>{{#responseWrapper}}>{{/responseWrapper}} {{operationId}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{#hasMore}},{{/hasMore}}{{/allParams}}) {

View File

@ -24,7 +24,10 @@ import java.util.Map;
@Api(value = "another-fake", description = "the another-fake API") @Api(value = "another-fake", description = "the another-fake API")
public interface AnotherFakeApi { public interface AnotherFakeApi {
AnotherFakeApiDelegate getDelegate();
default AnotherFakeApiDelegate getDelegate() {
return new AnotherFakeApiDelegate() {};
}
@ApiOperation(value = "To test special tags", nickname = "testSpecialTags", notes = "To test special tags", response = Client.class, tags={ "$another-fake?", }) @ApiOperation(value = "To test special tags", nickname = "testSpecialTags", notes = "To test special tags", response = Client.class, tags={ "$another-fake?", })
@ApiResponses(value = { @ApiResponses(value = {

View File

@ -1,19 +1,20 @@
package org.openapitools.api; package org.openapitools.api;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import java.util.Optional;
@Controller @Controller
public class AnotherFakeApiController implements AnotherFakeApi { public class AnotherFakeApiController implements AnotherFakeApi {
private final AnotherFakeApiDelegate delegate; private final AnotherFakeApiDelegate delegate;
@org.springframework.beans.factory.annotation.Autowired public AnotherFakeApiController(@org.springframework.beans.factory.annotation.Autowired(required = false) AnotherFakeApiDelegate delegate) {
public AnotherFakeApiController(AnotherFakeApiDelegate delegate) { this.delegate = Optional.ofNullable(delegate).orElse(new AnotherFakeApiDelegate() {});
this.delegate = delegate;
} }
@Override @Override
public AnotherFakeApiDelegate getDelegate() { public AnotherFakeApiDelegate getDelegate() {
return delegate; return delegate;
} }
} }

View File

@ -31,7 +31,10 @@ import java.util.Map;
@Api(value = "fake", description = "the fake API") @Api(value = "fake", description = "the fake API")
public interface FakeApi { public interface FakeApi {
FakeApiDelegate getDelegate();
default FakeApiDelegate getDelegate() {
return new FakeApiDelegate() {};
}
@ApiOperation(value = "", nickname = "fakeOuterBooleanSerialize", notes = "Test serialization of outer boolean types", response = Boolean.class, tags={ "fake", }) @ApiOperation(value = "", nickname = "fakeOuterBooleanSerialize", notes = "Test serialization of outer boolean types", response = Boolean.class, tags={ "fake", })
@ApiResponses(value = { @ApiResponses(value = {

View File

@ -1,19 +1,20 @@
package org.openapitools.api; package org.openapitools.api;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import java.util.Optional;
@Controller @Controller
public class FakeApiController implements FakeApi { public class FakeApiController implements FakeApi {
private final FakeApiDelegate delegate; private final FakeApiDelegate delegate;
@org.springframework.beans.factory.annotation.Autowired public FakeApiController(@org.springframework.beans.factory.annotation.Autowired(required = false) FakeApiDelegate delegate) {
public FakeApiController(FakeApiDelegate delegate) { this.delegate = Optional.ofNullable(delegate).orElse(new FakeApiDelegate() {});
this.delegate = delegate;
} }
@Override @Override
public FakeApiDelegate getDelegate() { public FakeApiDelegate getDelegate() {
return delegate; return delegate;
} }
} }

View File

@ -24,7 +24,10 @@ import java.util.Map;
@Api(value = "fake_classname_test", description = "the fake_classname_test API") @Api(value = "fake_classname_test", description = "the fake_classname_test API")
public interface FakeClassnameTestApi { public interface FakeClassnameTestApi {
FakeClassnameTestApiDelegate getDelegate();
default FakeClassnameTestApiDelegate getDelegate() {
return new FakeClassnameTestApiDelegate() {};
}
@ApiOperation(value = "To test class name in snake case", nickname = "testClassname", notes = "To test class name in snake case", response = Client.class, authorizations = { @ApiOperation(value = "To test class name in snake case", nickname = "testClassname", notes = "To test class name in snake case", response = Client.class, authorizations = {
@Authorization(value = "api_key_query") @Authorization(value = "api_key_query")

View File

@ -1,19 +1,20 @@
package org.openapitools.api; package org.openapitools.api;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import java.util.Optional;
@Controller @Controller
public class FakeClassnameTestApiController implements FakeClassnameTestApi { public class FakeClassnameTestApiController implements FakeClassnameTestApi {
private final FakeClassnameTestApiDelegate delegate; private final FakeClassnameTestApiDelegate delegate;
@org.springframework.beans.factory.annotation.Autowired public FakeClassnameTestApiController(@org.springframework.beans.factory.annotation.Autowired(required = false) FakeClassnameTestApiDelegate delegate) {
public FakeClassnameTestApiController(FakeClassnameTestApiDelegate delegate) { this.delegate = Optional.ofNullable(delegate).orElse(new FakeClassnameTestApiDelegate() {});
this.delegate = delegate;
} }
@Override @Override
public FakeClassnameTestApiDelegate getDelegate() { public FakeClassnameTestApiDelegate getDelegate() {
return delegate; return delegate;
} }
} }

View File

@ -26,7 +26,10 @@ import java.util.Map;
@Api(value = "pet", description = "the pet API") @Api(value = "pet", description = "the pet API")
public interface PetApi { public interface PetApi {
PetApiDelegate getDelegate();
default PetApiDelegate getDelegate() {
return new PetApiDelegate() {};
}
@ApiOperation(value = "Add a new pet to the store", nickname = "addPet", notes = "", authorizations = { @ApiOperation(value = "Add a new pet to the store", nickname = "addPet", notes = "", authorizations = {
@Authorization(value = "petstore_auth", scopes = { @Authorization(value = "petstore_auth", scopes = {

View File

@ -1,19 +1,20 @@
package org.openapitools.api; package org.openapitools.api;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import java.util.Optional;
@Controller @Controller
public class PetApiController implements PetApi { public class PetApiController implements PetApi {
private final PetApiDelegate delegate; private final PetApiDelegate delegate;
@org.springframework.beans.factory.annotation.Autowired public PetApiController(@org.springframework.beans.factory.annotation.Autowired(required = false) PetApiDelegate delegate) {
public PetApiController(PetApiDelegate delegate) { this.delegate = Optional.ofNullable(delegate).orElse(new PetApiDelegate() {});
this.delegate = delegate;
} }
@Override @Override
public PetApiDelegate getDelegate() { public PetApiDelegate getDelegate() {
return delegate; return delegate;
} }
} }

View File

@ -25,7 +25,10 @@ import java.util.Map;
@Api(value = "store", description = "the store API") @Api(value = "store", description = "the store API")
public interface StoreApi { public interface StoreApi {
StoreApiDelegate getDelegate();
default StoreApiDelegate getDelegate() {
return new StoreApiDelegate() {};
}
@ApiOperation(value = "Delete purchase order by ID", nickname = "deleteOrder", notes = "For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors", tags={ "store", }) @ApiOperation(value = "Delete purchase order by ID", nickname = "deleteOrder", notes = "For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors", tags={ "store", })
@ApiResponses(value = { @ApiResponses(value = {

View File

@ -1,19 +1,20 @@
package org.openapitools.api; package org.openapitools.api;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import java.util.Optional;
@Controller @Controller
public class StoreApiController implements StoreApi { public class StoreApiController implements StoreApi {
private final StoreApiDelegate delegate; private final StoreApiDelegate delegate;
@org.springframework.beans.factory.annotation.Autowired public StoreApiController(@org.springframework.beans.factory.annotation.Autowired(required = false) StoreApiDelegate delegate) {
public StoreApiController(StoreApiDelegate delegate) { this.delegate = Optional.ofNullable(delegate).orElse(new StoreApiDelegate() {});
this.delegate = delegate;
} }
@Override @Override
public StoreApiDelegate getDelegate() { public StoreApiDelegate getDelegate() {
return delegate; return delegate;
} }
} }

View File

@ -25,7 +25,10 @@ import java.util.Map;
@Api(value = "user", description = "the user API") @Api(value = "user", description = "the user API")
public interface UserApi { public interface UserApi {
UserApiDelegate getDelegate();
default UserApiDelegate getDelegate() {
return new UserApiDelegate() {};
}
@ApiOperation(value = "Create user", nickname = "createUser", notes = "This can only be done by the logged in user.", tags={ "user", }) @ApiOperation(value = "Create user", nickname = "createUser", notes = "This can only be done by the logged in user.", tags={ "user", })
@ApiResponses(value = { @ApiResponses(value = {

View File

@ -1,19 +1,20 @@
package org.openapitools.api; package org.openapitools.api;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import java.util.Optional;
@Controller @Controller
public class UserApiController implements UserApi { public class UserApiController implements UserApi {
private final UserApiDelegate delegate; private final UserApiDelegate delegate;
@org.springframework.beans.factory.annotation.Autowired public UserApiController(@org.springframework.beans.factory.annotation.Autowired(required = false) UserApiDelegate delegate) {
public UserApiController(UserApiDelegate delegate) { this.delegate = Optional.ofNullable(delegate).orElse(new UserApiDelegate() {});
this.delegate = delegate;
} }
@Override @Override
public UserApiDelegate getDelegate() { public UserApiDelegate getDelegate() {
return delegate; return delegate;
} }
} }

View File

@ -23,10 +23,10 @@ public class AnotherFakeApiController implements AnotherFakeApi {
private final AnotherFakeApiDelegate delegate; private final AnotherFakeApiDelegate delegate;
@org.springframework.beans.factory.annotation.Autowired public AnotherFakeApiController(@org.springframework.beans.factory.annotation.Autowired(required = false) AnotherFakeApiDelegate delegate) {
public AnotherFakeApiController(AnotherFakeApiDelegate delegate) {
this.delegate = delegate; this.delegate = delegate;
} }
public ResponseEntity<Client> testSpecialTags(@ApiParam(value = "client model" ,required=true ) @Valid @RequestBody Client client) { public ResponseEntity<Client> testSpecialTags(@ApiParam(value = "client model" ,required=true ) @Valid @RequestBody Client client) {
return delegate.testSpecialTags(client); return delegate.testSpecialTags(client);
} }

View File

@ -30,10 +30,10 @@ public class FakeApiController implements FakeApi {
private final FakeApiDelegate delegate; private final FakeApiDelegate delegate;
@org.springframework.beans.factory.annotation.Autowired public FakeApiController(@org.springframework.beans.factory.annotation.Autowired(required = false) FakeApiDelegate delegate) {
public FakeApiController(FakeApiDelegate delegate) {
this.delegate = delegate; this.delegate = delegate;
} }
public ResponseEntity<Boolean> fakeOuterBooleanSerialize(@ApiParam(value = "Input boolean as post body" ) @Valid @RequestBody Boolean body) { public ResponseEntity<Boolean> fakeOuterBooleanSerialize(@ApiParam(value = "Input boolean as post body" ) @Valid @RequestBody Boolean body) {
return delegate.fakeOuterBooleanSerialize(body); return delegate.fakeOuterBooleanSerialize(body);
} }

View File

@ -23,10 +23,10 @@ public class FakeClassnameTestApiController implements FakeClassnameTestApi {
private final FakeClassnameTestApiDelegate delegate; private final FakeClassnameTestApiDelegate delegate;
@org.springframework.beans.factory.annotation.Autowired public FakeClassnameTestApiController(@org.springframework.beans.factory.annotation.Autowired(required = false) FakeClassnameTestApiDelegate delegate) {
public FakeClassnameTestApiController(FakeClassnameTestApiDelegate delegate) {
this.delegate = delegate; this.delegate = delegate;
} }
public ResponseEntity<Client> testClassname(@ApiParam(value = "client model" ,required=true ) @Valid @RequestBody Client client) { public ResponseEntity<Client> testClassname(@ApiParam(value = "client model" ,required=true ) @Valid @RequestBody Client client) {
return delegate.testClassname(client); return delegate.testClassname(client);
} }

View File

@ -25,10 +25,10 @@ public class PetApiController implements PetApi {
private final PetApiDelegate delegate; private final PetApiDelegate delegate;
@org.springframework.beans.factory.annotation.Autowired public PetApiController(@org.springframework.beans.factory.annotation.Autowired(required = false) PetApiDelegate delegate) {
public PetApiController(PetApiDelegate delegate) {
this.delegate = delegate; this.delegate = delegate;
} }
public ResponseEntity<Void> addPet(@ApiParam(value = "Pet object that needs to be added to the store" ,required=true ) @Valid @RequestBody Pet pet) { public ResponseEntity<Void> addPet(@ApiParam(value = "Pet object that needs to be added to the store" ,required=true ) @Valid @RequestBody Pet pet) {
return delegate.addPet(pet); return delegate.addPet(pet);
} }

View File

@ -24,10 +24,10 @@ public class StoreApiController implements StoreApi {
private final StoreApiDelegate delegate; private final StoreApiDelegate delegate;
@org.springframework.beans.factory.annotation.Autowired public StoreApiController(@org.springframework.beans.factory.annotation.Autowired(required = false) StoreApiDelegate delegate) {
public StoreApiController(StoreApiDelegate delegate) {
this.delegate = delegate; this.delegate = delegate;
} }
public ResponseEntity<Void> deleteOrder(@ApiParam(value = "ID of the order that needs to be deleted",required=true) @PathVariable("order_id") String orderId) { public ResponseEntity<Void> deleteOrder(@ApiParam(value = "ID of the order that needs to be deleted",required=true) @PathVariable("order_id") String orderId) {
return delegate.deleteOrder(orderId); return delegate.deleteOrder(orderId);
} }

View File

@ -24,10 +24,10 @@ public class UserApiController implements UserApi {
private final UserApiDelegate delegate; private final UserApiDelegate delegate;
@org.springframework.beans.factory.annotation.Autowired public UserApiController(@org.springframework.beans.factory.annotation.Autowired(required = false) UserApiDelegate delegate) {
public UserApiController(UserApiDelegate delegate) {
this.delegate = delegate; this.delegate = delegate;
} }
public ResponseEntity<Void> createUser(@ApiParam(value = "Created user object" ,required=true ) @Valid @RequestBody User user) { public ResponseEntity<Void> createUser(@ApiParam(value = "Created user object" ,required=true ) @Valid @RequestBody User user) {
return delegate.createUser(user); return delegate.createUser(user);
} }