added java jax rs client
parent
01249f5b54
commit
7ae3b6ea8c
|
@ -0,0 +1,29 @@
|
|||
/**
|
||||
* Auto-generated from apibuilder.io service specification.
|
||||
* apidoc-version :
|
||||
* organisation :
|
||||
* service-version :
|
||||
*
|
||||
* Documentation at:
|
||||
* <a href="https://app.apibuilder.io///">https://app.apibuilder.io///</a>
|
||||
*
|
||||
**/
|
||||
package de.nclazz.users.v0;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
import javax.ws.rs.client.Client;
|
||||
import javax.ws.rs.client.ClientBuilder;
|
||||
|
||||
@Builder(toBuilder = true)
|
||||
@With
|
||||
@Getter
|
||||
@EqualsAndHashCode
|
||||
public class UsersApiClientConfig {
|
||||
|
||||
@NonNull
|
||||
private final String baseUrl;
|
||||
@Builder.Default
|
||||
private final Client client = ClientBuilder.newClient();
|
||||
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
/**
|
||||
* Auto-generated from apibuilder.io service spec.
|
||||
* apidoc-version : 0.15.4
|
||||
* organisation : nclazz
|
||||
* service-version : 0.0.0-dev-30-gbd50cdf-bd9390b2-staging
|
||||
*
|
||||
* Documentation at:
|
||||
* <a href="https://app.apibuilder.io/nclazz/users/0.0.0-dev-30-gbd50cdf-bd9390b2-staging">https://app.apibuilder.io/nclazz/users/0.0.0-dev-30-gbd50cdf-bd9390b2-staging</a>
|
||||
*
|
||||
**/
|
||||
package de.nclazz.users.v0.client;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
/**
|
||||
* Client for API resource de.nclazz.users.v0.HealthchecksClient
|
||||
* version 0.0.0-dev-30-gbd50cdf-bd9390b2-staging
|
||||
*
|
||||
* Simple healthcheck resource for monitoring purposes.
|
||||
**/
|
||||
public class HealthchecksClient {
|
||||
|
||||
/**
|
||||
* Simple healthcheck endpoint to test the status of the service.
|
||||
**/
|
||||
@Builder
|
||||
public static class Get {
|
||||
|
||||
private UsersApiClientConfig config;
|
||||
|
||||
public GetResponse request() {
|
||||
final URI uri = UriBuilder.fromUri(this.config.getBaseUrl())
|
||||
.path("/_internal_/healthcheck/healthcheck")
|
||||
.build();
|
||||
|
||||
WebTarget target = config.getClient().target(uri);
|
||||
Response response = target.request(MediaType.APPLICATION_JSON)
|
||||
.method("GET");
|
||||
int status = response.getStatus();
|
||||
switch(status) {
|
||||
case 200:
|
||||
Healthcheck result = response.readEntity("");
|
||||
return GetResponse.builder()
|
||||
.status(status)
|
||||
.headers(response.getHeaders())
|
||||
.healthcheck200(result)
|
||||
.build();
|
||||
default:
|
||||
return GetResponse.builder()
|
||||
.status(status)
|
||||
.unexpected(response.readEntity(String.class))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
public static GetBuilder builder(@NonNull UsersApiClientConfig config) {
|
||||
return new GetBuilder().config(config);
|
||||
}
|
||||
|
||||
@Builder
|
||||
@Data
|
||||
public static class GetResponse {
|
||||
private Healthcheck healthcheck200;
|
||||
|
||||
private final int status;
|
||||
private final MultivaluedMap<String, Object> headers;
|
||||
private final String unexpectedResult;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,317 @@
|
|||
/**
|
||||
* Auto-generated from apibuilder.io service spec.
|
||||
* apidoc-version : 0.15.4
|
||||
* organisation : nclazz
|
||||
* service-version : 0.0.0-dev-30-gbd50cdf-bd9390b2-staging
|
||||
*
|
||||
* Documentation at:
|
||||
* <a href="https://app.apibuilder.io/nclazz/users/0.0.0-dev-30-gbd50cdf-bd9390b2-staging">https://app.apibuilder.io/nclazz/users/0.0.0-dev-30-gbd50cdf-bd9390b2-staging</a>
|
||||
*
|
||||
**/
|
||||
package de.nclazz.users.v0.client;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
/**
|
||||
* Client for API resource de.nclazz.users.v0.RolesClient
|
||||
* version 0.0.0-dev-30-gbd50cdf-bd9390b2-staging
|
||||
*
|
||||
* Managing user roles.
|
||||
**/
|
||||
public class RolesClient {
|
||||
|
||||
/**
|
||||
* Get all defined user roles.
|
||||
**/
|
||||
@Builder
|
||||
public static class Get {
|
||||
|
||||
private UsersApiClientConfig config;
|
||||
|
||||
public GetResponse request() {
|
||||
final URI uri = UriBuilder.fromUri(this.config.getBaseUrl())
|
||||
.path("/roles/")
|
||||
.build();
|
||||
|
||||
WebTarget target = config.getClient().target(uri);
|
||||
Response response = target.request(MediaType.APPLICATION_JSON)
|
||||
.method("GET");
|
||||
int status = response.getStatus();
|
||||
switch(status) {
|
||||
case 200:
|
||||
Role result = response.readEntity("");
|
||||
return GetResponse.builder()
|
||||
.status(status)
|
||||
.headers(response.getHeaders())
|
||||
.role200(result)
|
||||
.build();
|
||||
case 401:
|
||||
return GetResponse.builder()
|
||||
.status(status)
|
||||
.headers(response.getHeaders())
|
||||
.build();
|
||||
default:
|
||||
return GetResponse.builder()
|
||||
.status(status)
|
||||
.unexpected(response.readEntity(String.class))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
public static GetBuilder builder(@NonNull UsersApiClientConfig config) {
|
||||
return new GetBuilder().config(config);
|
||||
}
|
||||
|
||||
@Builder
|
||||
@Data
|
||||
public static class GetResponse {
|
||||
private List<Role> role200;
|
||||
|
||||
private final int status;
|
||||
private final MultivaluedMap<String, Object> headers;
|
||||
private final String unexpectedResult;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a user role for id.
|
||||
**/
|
||||
@Builder
|
||||
public static class GetByIdAndOther {
|
||||
|
||||
private UsersApiClientConfig config;
|
||||
|
||||
public GetByIdAndOtherResponse request(@NonNull UUID id, @NonNull String other) {
|
||||
final URI uri = UriBuilder.fromUri(this.config.getBaseUrl())
|
||||
.path("/roles/:id/:other")
|
||||
.build();
|
||||
|
||||
WebTarget target = config.getClient().target(uri);
|
||||
Response response = target.request(MediaType.APPLICATION_JSON)
|
||||
.method("GET");
|
||||
int status = response.getStatus();
|
||||
switch(status) {
|
||||
case 200:
|
||||
Role result = response.readEntity("");
|
||||
return GetByIdAndOtherResponse.builder()
|
||||
.status(status)
|
||||
.headers(response.getHeaders())
|
||||
.role200(result)
|
||||
.build();
|
||||
case 401:
|
||||
return GetByIdAndOtherResponse.builder()
|
||||
.status(status)
|
||||
.headers(response.getHeaders())
|
||||
.build();
|
||||
case 404:
|
||||
return GetByIdAndOtherResponse.builder()
|
||||
.status(status)
|
||||
.headers(response.getHeaders())
|
||||
.build();
|
||||
default:
|
||||
return GetByIdAndOtherResponse.builder()
|
||||
.status(status)
|
||||
.unexpected(response.readEntity(String.class))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
public static GetByIdAndOtherBuilder builder(@NonNull UsersApiClientConfig config) {
|
||||
return new GetByIdAndOtherBuilder().config(config);
|
||||
}
|
||||
|
||||
@Builder
|
||||
@Data
|
||||
public static class GetByIdAndOtherResponse {
|
||||
private Role role200;
|
||||
|
||||
private final int status;
|
||||
private final MultivaluedMap<String, Object> headers;
|
||||
private final String unexpectedResult;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new user role.
|
||||
**/
|
||||
@Builder
|
||||
public static class PostRoleForm {
|
||||
|
||||
private UsersApiClientConfig config;
|
||||
|
||||
public PostRoleFormResponse request(@NonNull RoleForm roleForm) {
|
||||
final URI uri = UriBuilder.fromUri(this.config.getBaseUrl())
|
||||
.path("/roles/")
|
||||
.build();
|
||||
|
||||
WebTarget target = config.getClient().target(uri);
|
||||
Response response = target.request(MediaType.APPLICATION_JSON)
|
||||
.method("POST", roleForm);
|
||||
int status = response.getStatus();
|
||||
switch(status) {
|
||||
case 201:
|
||||
Role result = response.readEntity("");
|
||||
return PostRoleFormResponse.builder()
|
||||
.status(status)
|
||||
.headers(response.getHeaders())
|
||||
.user201(result)
|
||||
.build();
|
||||
case 400:
|
||||
Role result = response.readEntity("");
|
||||
return PostRoleFormResponse.builder()
|
||||
.status(status)
|
||||
.headers(response.getHeaders())
|
||||
.genericError400(result)
|
||||
.build();
|
||||
case 401:
|
||||
return PostRoleFormResponse.builder()
|
||||
.status(status)
|
||||
.headers(response.getHeaders())
|
||||
.build();
|
||||
default:
|
||||
return PostRoleFormResponse.builder()
|
||||
.status(status)
|
||||
.unexpected(response.readEntity(String.class))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
public static PostRoleFormBuilder builder(@NonNull UsersApiClientConfig config) {
|
||||
return new PostRoleFormBuilder().config(config);
|
||||
}
|
||||
|
||||
@Builder
|
||||
@Data
|
||||
public static class PostRoleFormResponse {
|
||||
private User user201;
|
||||
private List<GenericError> genericError400;
|
||||
|
||||
private final int status;
|
||||
private final MultivaluedMap<String, Object> headers;
|
||||
private final String unexpectedResult;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the status of a user role.
|
||||
**/
|
||||
@Builder
|
||||
public static class PutUserStatusFormById {
|
||||
|
||||
private UsersApiClientConfig config;
|
||||
|
||||
public PutUserStatusFormByIdResponse request(@NonNull UUID id, @NonNull UserStatusForm userStatusForm) {
|
||||
final URI uri = UriBuilder.fromUri(this.config.getBaseUrl())
|
||||
.path("/roles/:id/status")
|
||||
.build();
|
||||
|
||||
WebTarget target = config.getClient().target(uri);
|
||||
Response response = target.request(MediaType.APPLICATION_JSON)
|
||||
.method("PUT", userStatusForm);
|
||||
int status = response.getStatus();
|
||||
switch(status) {
|
||||
case 200:
|
||||
Role result = response.readEntity("");
|
||||
return PutUserStatusFormByIdResponse.builder()
|
||||
.status(status)
|
||||
.headers(response.getHeaders())
|
||||
.userStatus200(result)
|
||||
.build();
|
||||
case 400:
|
||||
Role result = response.readEntity("");
|
||||
return PutUserStatusFormByIdResponse.builder()
|
||||
.status(status)
|
||||
.headers(response.getHeaders())
|
||||
.genericError400(result)
|
||||
.build();
|
||||
case 401:
|
||||
return PutUserStatusFormByIdResponse.builder()
|
||||
.status(status)
|
||||
.headers(response.getHeaders())
|
||||
.build();
|
||||
case 404:
|
||||
return PutUserStatusFormByIdResponse.builder()
|
||||
.status(status)
|
||||
.headers(response.getHeaders())
|
||||
.build();
|
||||
default:
|
||||
return PutUserStatusFormByIdResponse.builder()
|
||||
.status(status)
|
||||
.unexpected(response.readEntity(String.class))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
public static PutUserStatusFormByIdBuilder builder(@NonNull UsersApiClientConfig config) {
|
||||
return new PutUserStatusFormByIdBuilder().config(config);
|
||||
}
|
||||
|
||||
@Builder
|
||||
@Data
|
||||
public static class PutUserStatusFormByIdResponse {
|
||||
private UserStatus userStatus200;
|
||||
private List<GenericError> genericError400;
|
||||
|
||||
private final int status;
|
||||
private final MultivaluedMap<String, Object> headers;
|
||||
private final String unexpectedResult;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark a user role as deleted. The user role cannot be accessed by the api, but will stay in the db for a while, before completely removed.
|
||||
**/
|
||||
@Builder
|
||||
public static class DeleteById {
|
||||
|
||||
private UsersApiClientConfig config;
|
||||
|
||||
public DeleteByIdResponse request(@NonNull UUID id) {
|
||||
final URI uri = UriBuilder.fromUri(this.config.getBaseUrl())
|
||||
.path("/roles/:id")
|
||||
.build();
|
||||
|
||||
WebTarget target = config.getClient().target(uri);
|
||||
Response response = target.request(MediaType.APPLICATION_JSON)
|
||||
.method("DELETE");
|
||||
int status = response.getStatus();
|
||||
switch(status) {
|
||||
case 200:
|
||||
return DeleteByIdResponse.builder()
|
||||
.status(status)
|
||||
.headers(response.getHeaders())
|
||||
.build();
|
||||
case 401:
|
||||
return DeleteByIdResponse.builder()
|
||||
.status(status)
|
||||
.headers(response.getHeaders())
|
||||
.build();
|
||||
case 404:
|
||||
return DeleteByIdResponse.builder()
|
||||
.status(status)
|
||||
.headers(response.getHeaders())
|
||||
.build();
|
||||
default:
|
||||
return DeleteByIdResponse.builder()
|
||||
.status(status)
|
||||
.unexpected(response.readEntity(String.class))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
public static DeleteByIdBuilder builder(@NonNull UsersApiClientConfig config) {
|
||||
return new DeleteByIdBuilder().config(config);
|
||||
}
|
||||
|
||||
@Builder
|
||||
@Data
|
||||
public static class DeleteByIdResponse {
|
||||
|
||||
private final int status;
|
||||
private final MultivaluedMap<String, Object> headers;
|
||||
private final String unexpectedResult;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,77 @@
|
|||
/**
|
||||
* Auto-generated from apibuilder.io service spec.
|
||||
* apidoc-version : 0.15.4
|
||||
* organisation : nclazz
|
||||
* service-version : 0.0.0-dev-30-gbd50cdf-bd9390b2-staging
|
||||
*
|
||||
* Documentation at:
|
||||
* <a href="https://app.apibuilder.io/nclazz/users/0.0.0-dev-30-gbd50cdf-bd9390b2-staging">https://app.apibuilder.io/nclazz/users/0.0.0-dev-30-gbd50cdf-bd9390b2-staging</a>
|
||||
*
|
||||
**/
|
||||
package de.nclazz.users.v0.client;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
/**
|
||||
* Client for API resource de.nclazz.users.v0.UserLoginsClient
|
||||
* version 0.0.0-dev-30-gbd50cdf-bd9390b2-staging
|
||||
*
|
||||
* Resource for authenticating users.
|
||||
**/
|
||||
public class UserLoginsClient {
|
||||
|
||||
/**
|
||||
* Login user with username + password.
|
||||
**/
|
||||
@Builder
|
||||
public static class PostUserLoginForm {
|
||||
|
||||
private UsersApiClientConfig config;
|
||||
|
||||
public PostUserLoginFormResponse request(@NonNull UserLoginForm userLoginForm) {
|
||||
final URI uri = UriBuilder.fromUri(this.config.getBaseUrl())
|
||||
.path("/login/")
|
||||
.build();
|
||||
|
||||
WebTarget target = config.getClient().target(uri);
|
||||
Response response = target.request(MediaType.APPLICATION_JSON)
|
||||
.method("POST", userLoginForm);
|
||||
int status = response.getStatus();
|
||||
switch(status) {
|
||||
case 200:
|
||||
UserLogin result = response.readEntity("");
|
||||
return PostUserLoginFormResponse.builder()
|
||||
.status(status)
|
||||
.headers(response.getHeaders())
|
||||
.userLogin200(result)
|
||||
.build();
|
||||
case 401:
|
||||
return PostUserLoginFormResponse.builder()
|
||||
.status(status)
|
||||
.headers(response.getHeaders())
|
||||
.build();
|
||||
default:
|
||||
return PostUserLoginFormResponse.builder()
|
||||
.status(status)
|
||||
.unexpected(response.readEntity(String.class))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
public static PostUserLoginFormBuilder builder(@NonNull UsersApiClientConfig config) {
|
||||
return new PostUserLoginFormBuilder().config(config);
|
||||
}
|
||||
|
||||
@Builder
|
||||
@Data
|
||||
public static class PostUserLoginFormResponse {
|
||||
private UserLogin userLogin200;
|
||||
|
||||
private final int status;
|
||||
private final MultivaluedMap<String, Object> headers;
|
||||
private final String unexpectedResult;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,386 @@
|
|||
/**
|
||||
* Auto-generated from apibuilder.io service spec.
|
||||
* apidoc-version : 0.15.4
|
||||
* organisation : nclazz
|
||||
* service-version : 0.0.0-dev-30-gbd50cdf-bd9390b2-staging
|
||||
*
|
||||
* Documentation at:
|
||||
* <a href="https://app.apibuilder.io/nclazz/users/0.0.0-dev-30-gbd50cdf-bd9390b2-staging">https://app.apibuilder.io/nclazz/users/0.0.0-dev-30-gbd50cdf-bd9390b2-staging</a>
|
||||
*
|
||||
**/
|
||||
package de.nclazz.users.v0.client;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
/**
|
||||
* Client for API resource de.nclazz.users.v0.UsersClient
|
||||
* version 0.0.0-dev-30-gbd50cdf-bd9390b2-staging
|
||||
*
|
||||
* Access to the user management.
|
||||
**/
|
||||
public class UsersClient {
|
||||
|
||||
/**
|
||||
* Get all users.
|
||||
**/
|
||||
@Builder
|
||||
public static class Get {
|
||||
|
||||
private UsersApiClientConfig config;
|
||||
@NonNull private String xAuthorization_header ;
|
||||
private String xAgent_header ;
|
||||
@Builder.Default private Integer limit_query = 200;
|
||||
|
||||
public GetResponse request() {
|
||||
final URI uri = UriBuilder.fromUri(this.config.getBaseUrl())
|
||||
.path("/users/")
|
||||
.build();
|
||||
|
||||
WebTarget target = config.getClient().target(uri);
|
||||
Response response = target.request(MediaType.APPLICATION_JSON)
|
||||
.method("GET");
|
||||
int status = response.getStatus();
|
||||
switch(status) {
|
||||
case 200:
|
||||
User result = response.readEntity("");
|
||||
return GetResponse.builder()
|
||||
.status(status)
|
||||
.headers(response.getHeaders())
|
||||
.user200(result)
|
||||
.build();
|
||||
case 401:
|
||||
return GetResponse.builder()
|
||||
.status(status)
|
||||
.headers(response.getHeaders())
|
||||
.build();
|
||||
default:
|
||||
return GetResponse.builder()
|
||||
.status(status)
|
||||
.unexpected(response.readEntity(String.class))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
public static GetBuilder builder(@NonNull UsersApiClientConfig config) {
|
||||
return new GetBuilder().config(config);
|
||||
}
|
||||
|
||||
@Builder
|
||||
@Data
|
||||
public static class GetResponse {
|
||||
private List<User> user200;
|
||||
|
||||
private final int status;
|
||||
private final MultivaluedMap<String, Object> headers;
|
||||
private final String unexpectedResult;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a user for given id.
|
||||
**/
|
||||
@Builder
|
||||
public static class GetById {
|
||||
|
||||
private UsersApiClientConfig config;
|
||||
|
||||
public GetByIdResponse request(@NonNull String id) {
|
||||
final URI uri = UriBuilder.fromUri(this.config.getBaseUrl())
|
||||
.path("/users/:id")
|
||||
.build();
|
||||
|
||||
WebTarget target = config.getClient().target(uri);
|
||||
Response response = target.request(MediaType.APPLICATION_JSON)
|
||||
.method("GET");
|
||||
int status = response.getStatus();
|
||||
switch(status) {
|
||||
case 200:
|
||||
User result = response.readEntity("");
|
||||
return GetByIdResponse.builder()
|
||||
.status(status)
|
||||
.headers(response.getHeaders())
|
||||
.user200(result)
|
||||
.build();
|
||||
case 404:
|
||||
return GetByIdResponse.builder()
|
||||
.status(status)
|
||||
.headers(response.getHeaders())
|
||||
.build();
|
||||
case 401:
|
||||
return GetByIdResponse.builder()
|
||||
.status(status)
|
||||
.headers(response.getHeaders())
|
||||
.build();
|
||||
default:
|
||||
return GetByIdResponse.builder()
|
||||
.status(status)
|
||||
.unexpected(response.readEntity(String.class))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
public static GetByIdBuilder builder(@NonNull UsersApiClientConfig config) {
|
||||
return new GetByIdBuilder().config(config);
|
||||
}
|
||||
|
||||
@Builder
|
||||
@Data
|
||||
public static class GetByIdResponse {
|
||||
private User user200;
|
||||
|
||||
private final int status;
|
||||
private final MultivaluedMap<String, Object> headers;
|
||||
private final String unexpectedResult;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new user.
|
||||
**/
|
||||
@Builder
|
||||
public static class PostUserForm {
|
||||
|
||||
private UsersApiClientConfig config;
|
||||
|
||||
public PostUserFormResponse request(@NonNull UserForm userForm) {
|
||||
final URI uri = UriBuilder.fromUri(this.config.getBaseUrl())
|
||||
.path("/users/")
|
||||
.build();
|
||||
|
||||
WebTarget target = config.getClient().target(uri);
|
||||
Response response = target.request(MediaType.APPLICATION_JSON)
|
||||
.method("POST", userForm);
|
||||
int status = response.getStatus();
|
||||
switch(status) {
|
||||
case 201:
|
||||
User result = response.readEntity("");
|
||||
return PostUserFormResponse.builder()
|
||||
.status(status)
|
||||
.headers(response.getHeaders())
|
||||
.user201(result)
|
||||
.build();
|
||||
case 400:
|
||||
User result = response.readEntity("");
|
||||
return PostUserFormResponse.builder()
|
||||
.status(status)
|
||||
.headers(response.getHeaders())
|
||||
.genericError400(result)
|
||||
.build();
|
||||
case 401:
|
||||
return PostUserFormResponse.builder()
|
||||
.status(status)
|
||||
.headers(response.getHeaders())
|
||||
.build();
|
||||
default:
|
||||
return PostUserFormResponse.builder()
|
||||
.status(status)
|
||||
.unexpected(response.readEntity(String.class))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
public static PostUserFormBuilder builder(@NonNull UsersApiClientConfig config) {
|
||||
return new PostUserFormBuilder().config(config);
|
||||
}
|
||||
|
||||
@Builder
|
||||
@Data
|
||||
public static class PostUserFormResponse {
|
||||
private User user201;
|
||||
private List<GenericError> genericError400;
|
||||
|
||||
private final int status;
|
||||
private final MultivaluedMap<String, Object> headers;
|
||||
private final String unexpectedResult;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update user data.
|
||||
**/
|
||||
@Builder
|
||||
public static class PutUserFormById {
|
||||
|
||||
private UsersApiClientConfig config;
|
||||
|
||||
public PutUserFormByIdResponse request(@NonNull String id, @NonNull UserForm userForm) {
|
||||
final URI uri = UriBuilder.fromUri(this.config.getBaseUrl())
|
||||
.path("/users/:id")
|
||||
.build();
|
||||
|
||||
WebTarget target = config.getClient().target(uri);
|
||||
Response response = target.request(MediaType.APPLICATION_JSON)
|
||||
.method("PUT", userForm);
|
||||
int status = response.getStatus();
|
||||
switch(status) {
|
||||
case 200:
|
||||
User result = response.readEntity("");
|
||||
return PutUserFormByIdResponse.builder()
|
||||
.status(status)
|
||||
.headers(response.getHeaders())
|
||||
.user200(result)
|
||||
.build();
|
||||
case 400:
|
||||
User result = response.readEntity("");
|
||||
return PutUserFormByIdResponse.builder()
|
||||
.status(status)
|
||||
.headers(response.getHeaders())
|
||||
.genericError400(result)
|
||||
.build();
|
||||
case 401:
|
||||
return PutUserFormByIdResponse.builder()
|
||||
.status(status)
|
||||
.headers(response.getHeaders())
|
||||
.build();
|
||||
case 404:
|
||||
return PutUserFormByIdResponse.builder()
|
||||
.status(status)
|
||||
.headers(response.getHeaders())
|
||||
.build();
|
||||
default:
|
||||
return PutUserFormByIdResponse.builder()
|
||||
.status(status)
|
||||
.unexpected(response.readEntity(String.class))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
public static PutUserFormByIdBuilder builder(@NonNull UsersApiClientConfig config) {
|
||||
return new PutUserFormByIdBuilder().config(config);
|
||||
}
|
||||
|
||||
@Builder
|
||||
@Data
|
||||
public static class PutUserFormByIdResponse {
|
||||
private User user200;
|
||||
private List<GenericError> genericError400;
|
||||
|
||||
private final int status;
|
||||
private final MultivaluedMap<String, Object> headers;
|
||||
private final String unexpectedResult;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the status of the user.
|
||||
**/
|
||||
@Builder
|
||||
public static class PutUserStatusFormById {
|
||||
|
||||
private UsersApiClientConfig config;
|
||||
|
||||
public PutUserStatusFormByIdResponse request(@NonNull String id, @NonNull UserStatusForm userStatusForm) {
|
||||
final URI uri = UriBuilder.fromUri(this.config.getBaseUrl())
|
||||
.path("/users/:id/status")
|
||||
.build();
|
||||
|
||||
WebTarget target = config.getClient().target(uri);
|
||||
Response response = target.request(MediaType.APPLICATION_JSON)
|
||||
.method("PUT", userStatusForm);
|
||||
int status = response.getStatus();
|
||||
switch(status) {
|
||||
case 200:
|
||||
User result = response.readEntity("");
|
||||
return PutUserStatusFormByIdResponse.builder()
|
||||
.status(status)
|
||||
.headers(response.getHeaders())
|
||||
.userStatus200(result)
|
||||
.build();
|
||||
case 400:
|
||||
User result = response.readEntity("");
|
||||
return PutUserStatusFormByIdResponse.builder()
|
||||
.status(status)
|
||||
.headers(response.getHeaders())
|
||||
.genericError400(result)
|
||||
.build();
|
||||
case 401:
|
||||
return PutUserStatusFormByIdResponse.builder()
|
||||
.status(status)
|
||||
.headers(response.getHeaders())
|
||||
.build();
|
||||
case 404:
|
||||
return PutUserStatusFormByIdResponse.builder()
|
||||
.status(status)
|
||||
.headers(response.getHeaders())
|
||||
.build();
|
||||
default:
|
||||
return PutUserStatusFormByIdResponse.builder()
|
||||
.status(status)
|
||||
.unexpected(response.readEntity(String.class))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
public static PutUserStatusFormByIdBuilder builder(@NonNull UsersApiClientConfig config) {
|
||||
return new PutUserStatusFormByIdBuilder().config(config);
|
||||
}
|
||||
|
||||
@Builder
|
||||
@Data
|
||||
public static class PutUserStatusFormByIdResponse {
|
||||
private UserStatus userStatus200;
|
||||
private List<GenericError> genericError400;
|
||||
|
||||
private final int status;
|
||||
private final MultivaluedMap<String, Object> headers;
|
||||
private final String unexpectedResult;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark a user as deleted. The user cannot be accessed by the api, but will stay in the db for a while, before completely removed.
|
||||
**/
|
||||
@Builder
|
||||
public static class DeleteById {
|
||||
|
||||
private UsersApiClientConfig config;
|
||||
|
||||
public DeleteByIdResponse request(@NonNull String id) {
|
||||
final URI uri = UriBuilder.fromUri(this.config.getBaseUrl())
|
||||
.path("/users/:id")
|
||||
.build();
|
||||
|
||||
WebTarget target = config.getClient().target(uri);
|
||||
Response response = target.request(MediaType.APPLICATION_JSON)
|
||||
.method("DELETE");
|
||||
int status = response.getStatus();
|
||||
switch(status) {
|
||||
case 200:
|
||||
return DeleteByIdResponse.builder()
|
||||
.status(status)
|
||||
.headers(response.getHeaders())
|
||||
.build();
|
||||
case 401:
|
||||
return DeleteByIdResponse.builder()
|
||||
.status(status)
|
||||
.headers(response.getHeaders())
|
||||
.build();
|
||||
case 404:
|
||||
return DeleteByIdResponse.builder()
|
||||
.status(status)
|
||||
.headers(response.getHeaders())
|
||||
.build();
|
||||
default:
|
||||
return DeleteByIdResponse.builder()
|
||||
.status(status)
|
||||
.unexpected(response.readEntity(String.class))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
public static DeleteByIdBuilder builder(@NonNull UsersApiClientConfig config) {
|
||||
return new DeleteByIdBuilder().config(config);
|
||||
}
|
||||
|
||||
@Builder
|
||||
@Data
|
||||
public static class DeleteByIdResponse {
|
||||
|
||||
private final int status;
|
||||
private final MultivaluedMap<String, Object> headers;
|
||||
private final String unexpectedResult;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -8,7 +8,7 @@
|
|||
* <a href="https://app.apibuilder.io/nclazz/users/0.0.0-dev-30-gbd50cdf-bd9390b2-staging">https://app.apibuilder.io/nclazz/users/0.0.0-dev-30-gbd50cdf-bd9390b2-staging</a>
|
||||
*
|
||||
**/
|
||||
package ;
|
||||
package de.nclazz.users.v0.models;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.With;
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
* <a href="https://app.apibuilder.io/nclazz/users/0.0.0-dev-30-gbd50cdf-bd9390b2-staging">https://app.apibuilder.io/nclazz/users/0.0.0-dev-30-gbd50cdf-bd9390b2-staging</a>
|
||||
*
|
||||
**/
|
||||
package ;
|
||||
package de.nclazz.users.v0.models;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.With;
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
* <a href="https://app.apibuilder.io/nclazz/users/0.0.0-dev-30-gbd50cdf-bd9390b2-staging">https://app.apibuilder.io/nclazz/users/0.0.0-dev-30-gbd50cdf-bd9390b2-staging</a>
|
||||
*
|
||||
**/
|
||||
package ;
|
||||
package de.nclazz.users.v0.models;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.With;
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
* <a href="https://app.apibuilder.io/nclazz/users/0.0.0-dev-30-gbd50cdf-bd9390b2-staging">https://app.apibuilder.io/nclazz/users/0.0.0-dev-30-gbd50cdf-bd9390b2-staging</a>
|
||||
*
|
||||
**/
|
||||
package ;
|
||||
package de.nclazz.users.v0.models;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.With;
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
* <a href="https://app.apibuilder.io/nclazz/users/0.0.0-dev-30-gbd50cdf-bd9390b2-staging">https://app.apibuilder.io/nclazz/users/0.0.0-dev-30-gbd50cdf-bd9390b2-staging</a>
|
||||
*
|
||||
**/
|
||||
package ;
|
||||
package de.nclazz.users.v0.models;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.With;
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
* <a href="https://app.apibuilder.io/nclazz/users/0.0.0-dev-30-gbd50cdf-bd9390b2-staging">https://app.apibuilder.io/nclazz/users/0.0.0-dev-30-gbd50cdf-bd9390b2-staging</a>
|
||||
*
|
||||
**/
|
||||
package ;
|
||||
package de.nclazz.users.v0.models;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.With;
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
* Auto-generated from apibuilder.io service spec.
|
||||
* apidoc-version : 0.15.4
|
||||
* organisation : nclazz
|
||||
* service-version : 0.0.0-dev-30-gbd50cdf-bd9390b2-staging
|
||||
*
|
||||
* Documentation at:
|
||||
* <a href="https://app.apibuilder.io/nclazz/users/0.0.0-dev-30-gbd50cdf-bd9390b2-staging">https://app.apibuilder.io/nclazz/users/0.0.0-dev-30-gbd50cdf-bd9390b2-staging</a>
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
* <a href="https://app.apibuilder.io/nclazz/users/0.0.0-dev-30-gbd50cdf-bd9390b2-staging">https://app.apibuilder.io/nclazz/users/0.0.0-dev-30-gbd50cdf-bd9390b2-staging</a>
|
||||
*
|
||||
**/
|
||||
package ;
|
||||
package de.nclazz.users.v0.models;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.With;
|
||||
|
|
|
@ -604,7 +604,27 @@
|
|||
{
|
||||
"method": "GET",
|
||||
"path": "/users/",
|
||||
"parameters": [],
|
||||
"parameters": [
|
||||
{
|
||||
"name": "x-authorization",
|
||||
"type": "string",
|
||||
"location": "Header",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"name": "x-agent",
|
||||
"type": "string",
|
||||
"location": "Header",
|
||||
"required": false
|
||||
},
|
||||
{
|
||||
"name": "limit",
|
||||
"type": "integer",
|
||||
"location": "Query",
|
||||
"required": false,
|
||||
"default": 200
|
||||
}
|
||||
],
|
||||
"responses": [
|
||||
{
|
||||
"code": {
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
const javaClient = require('../java-client')
|
||||
const Mustache = require('Mustache')
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const utils = require('../utils')
|
||||
|
||||
const templateApiConfig = fs.readFileSync(path.resolve(path.join('templates', 'jax-rs-config.java.mustache')), 'utf-8')
|
||||
const templateApi = fs.readFileSync(path.resolve(path.join('templates', 'jax-rs-api.java.mustache')), 'utf-8')
|
||||
const templateResource = fs.readFileSync(path.resolve(path.join('templates', 'jax-rs-resource.java.mustache')), 'utf-8')
|
||||
|
||||
|
||||
module.exports = (service) => {
|
||||
|
||||
service.pascalcase = utils.pascalcase(service.name)
|
||||
service.configName = `${utils.pascalcase(service.name)}ApiClientConfig`
|
||||
service.package = service.namespace
|
||||
const resources = javaClient.mapResources(service.resources, service.namespace)
|
||||
|
||||
const files = resources.map(resource => {
|
||||
return {
|
||||
name: `${resource.name}Resource.java`,
|
||||
dir: resource.dir,
|
||||
contents: Mustache.render(templateResource, { service, ...resource })
|
||||
}
|
||||
})
|
||||
|
||||
return [
|
||||
...files,
|
||||
{
|
||||
name: `${service.configName}.java`,
|
||||
dir: service.namespace.replace(/\./g, '/'),
|
||||
contents: Mustache.render(templateApiConfig, service)
|
||||
},
|
||||
{
|
||||
name: `${service.pascalcase}ServiceClient.java`,
|
||||
dir: service.namespace.replace(/\./g, '/'),
|
||||
contents: Mustache.render(templateApi, service)
|
||||
}
|
||||
]
|
||||
|
||||
}
|
|
@ -3,8 +3,6 @@ const Mustache = require('Mustache')
|
|||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
|
||||
|
||||
|
||||
const templateModel = fs.readFileSync(path.resolve(path.join('templates', 'lombok-model.java.mustache')), 'utf-8')
|
||||
const templateEnum = fs.readFileSync(path.resolve(path.join('templates', 'lombok-enum.java.mustache')), 'utf-8')
|
||||
|
||||
|
|
13
src/index.js
13
src/index.js
|
@ -2,18 +2,25 @@ const util = require('util')
|
|||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const modelGen = require('./generators/java-models-generator')
|
||||
|
||||
const resGen = require('./generators/java-client-generator')
|
||||
|
||||
|
||||
const service = require('../examples/example.json')
|
||||
const models = modelGen(service)
|
||||
const resources = resGen(service)
|
||||
|
||||
// console.log(util.inspect(models, { depth: 8 }))
|
||||
|
||||
const out = 'examples'
|
||||
const files = [
|
||||
...models,
|
||||
...resources
|
||||
]
|
||||
|
||||
models.forEach(file => {
|
||||
const out = 'D:\\nclazz.de\\sandbox\\apibuilder-source\\src\\main\\java'
|
||||
|
||||
files.forEach(file => {
|
||||
let outPath = path.join(out, file.dir)
|
||||
console.log('write', outPath)
|
||||
if(!fs.existsSync(outPath)) {
|
||||
fs.mkdirSync(outPath, { recursive: true })
|
||||
}
|
||||
|
|
|
@ -1,36 +1,79 @@
|
|||
const utils = require('./utils')
|
||||
const javaType = require('./java-type')
|
||||
|
||||
function mapParameter(parameter, namespace) {
|
||||
function formatOperationName(operation) {
|
||||
let name = operation.method.toLowerCase()
|
||||
const parameters = operation.parameters
|
||||
|
||||
if(operation.body) {
|
||||
name += utils.pascalcase(operation.body.type)
|
||||
}
|
||||
|
||||
if(operation.parameters.length) {
|
||||
name += `By${parameters.filter(p => p.location === 'Path')
|
||||
.map(p => utils.pascalcase(p.name)).join('And')}`
|
||||
}
|
||||
|
||||
return utils.pascalcase(name)
|
||||
|
||||
}
|
||||
|
||||
function mapParameter(parameter, namespace, operation) {
|
||||
parameter.label = utils.camelcase(parameter.name)
|
||||
parameter.type = javaType.mapJavaType(parameter.type, namespace)
|
||||
parameter.op = operation
|
||||
return parameter
|
||||
}
|
||||
|
||||
function mapOperation(operation, namespace) {
|
||||
operation.headers = operation.parameters
|
||||
.filter(param => param.location === 'Header')
|
||||
.map(param => mapParameter(param, namespace))
|
||||
.map(param => mapParameter(param, namespace, operation))
|
||||
|
||||
operation.query = operation.parameters
|
||||
.filter(param => param.location === 'Query')
|
||||
.map(param => mapParameter(param, namespace))
|
||||
.map(param => mapParameter(param, namespace, operation))
|
||||
|
||||
operation.parameters = operation.parameters
|
||||
.filter(param => param.location === 'Path')
|
||||
.map(param => mapParameter(param, namespace))
|
||||
.map(param => mapParameter(param, namespace, operation))
|
||||
|
||||
operation.name = formatOperationName(operation)
|
||||
operation.camelcase = utils.camelcase(operation.name)
|
||||
|
||||
operation.responseTypes = operation.responses.filter(resp => resp.type !== 'unit').map(resp => {
|
||||
let type = javaType.mapJavaType(resp.type, namespace)
|
||||
return {
|
||||
type,
|
||||
name: `${utils.camelcase(type.baseType)}${resp.code.integer.value}`
|
||||
}
|
||||
})
|
||||
operation.responses = operation.responses.map(resp => {
|
||||
let type = javaType.mapJavaType(resp.type, namespace)
|
||||
if(resp.type !== 'unit') {
|
||||
resp.label = `${utils.camelcase(type.baseType)}${resp.code.integer.value}`
|
||||
}
|
||||
resp.type = type
|
||||
return resp
|
||||
})
|
||||
|
||||
if(operation.body) {
|
||||
let bodyName = utils.camelcase(operation.body.type)
|
||||
operation.parameters = [
|
||||
...operation.parameters,
|
||||
{
|
||||
name: utils.camelcase(operation.body.type),
|
||||
label: bodyName,
|
||||
required: true,
|
||||
location: 'Body',
|
||||
type: javaType.mapJavaType(operation.body.type, namespace)
|
||||
}
|
||||
]
|
||||
operation.body.name = bodyName
|
||||
}
|
||||
|
||||
if(operation.parameters.length) {
|
||||
operation['parameters'][ operation['parameters'].length - 1 ].last = true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -41,9 +84,26 @@ module.exports = {
|
|||
mapResources: (resources, namespace) => {
|
||||
return resources.map(resource => {
|
||||
resource.type = javaType.mapJavaType(resource.type, namespace)
|
||||
resource.name = utils.pascalcase(resource.plural)
|
||||
resource.name = `${utils.pascalcase(resource.plural)}Client`
|
||||
resource.operations = resource.operations.map(op => mapOperation(op, namespace))
|
||||
resource.package = `${namespace}.client`
|
||||
resource.dir = resource.package.replace(/\./g, '/')
|
||||
|
||||
let imports = []
|
||||
resource.operations.forEach(op => op.parameters.forEach(p => {
|
||||
imports = [
|
||||
...imports,
|
||||
...p.type.imports
|
||||
]
|
||||
}))
|
||||
resource.operations.forEach(op => op.responses.forEach(p => {
|
||||
imports = [
|
||||
...imports,
|
||||
...p.type.imports
|
||||
]
|
||||
}))
|
||||
|
||||
resource.imports = [... new Set(imports)]
|
||||
return resource
|
||||
})
|
||||
}
|
||||
|
|
|
@ -60,6 +60,7 @@ function getCustomType(type, namespace) {
|
|||
|
||||
return {
|
||||
name,
|
||||
baseType: name,
|
||||
imports: [ importstatement ]
|
||||
}
|
||||
}
|
||||
|
@ -68,7 +69,9 @@ function mapCollection(type) {
|
|||
let baseType = type.name
|
||||
return {
|
||||
name: `List<${baseType}>`,
|
||||
baseType,
|
||||
imports: [ ...(type.imports || []), 'java.util.List' ],
|
||||
isCollection: true
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -85,7 +88,8 @@ module.exports = {
|
|||
|
||||
return {
|
||||
...javaType,
|
||||
raw: type
|
||||
raw: type,
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
/**
|
||||
* Auto-generated from apibuilder.io service spec.
|
||||
* apidoc-version : {{service.apidoc.version}}
|
||||
* organisation : {{service.organization.key}}
|
||||
* service-version : {{service.version}}
|
||||
*
|
||||
* Documentation at:
|
||||
* <a href="https://app.apibuilder.io/{{service.organization.key}}/{{service.name}}/{{service.version}}">https://app.apibuilder.io/{{service.organization.key}}/{{service.name}}/{{service.version}}</a>
|
||||
*
|
||||
**/
|
||||
package {{package}};
|
||||
|
||||
import lombok.*;
|
||||
|
||||
import {{namespace}}.client.*;
|
||||
|
||||
/**
|
||||
* Client Lib for {{namespace}}.{{name}} API service spec.
|
||||
*
|
||||
* {{description}}
|
||||
**/
|
||||
public class {{pascalcase}}ServiceClient {
|
||||
|
||||
private final {{configName}} config;
|
||||
|
||||
public {{pascalcase}}ServiceClient(@NonNull final {{configName}} config) {
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
{{#resources}}
|
||||
public {{name}} {{plural}}() {
|
||||
return new {{name}}(this.config);
|
||||
}
|
||||
{{/resources}}
|
||||
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
/**
|
||||
* Auto-generated from apibuilder.io service specification.
|
||||
* apidoc-version : {{service.apidoc.version}}
|
||||
* organisation : {{service.organization.key}}
|
||||
* service-version : {{service.version}}
|
||||
*
|
||||
* Documentation at:
|
||||
* <a href="https://app.apibuilder.io/{{service.organization.key}}/{{service.name}}/{{service.version}}">https://app.apibuilder.io/{{service.organization.key}}/{{service.name}}/{{service.version}}</a>
|
||||
*
|
||||
**/
|
||||
package {{namespace}};
|
||||
|
||||
import lombok.*;
|
||||
|
||||
import javax.ws.rs.client.Client;
|
||||
import javax.ws.rs.client.ClientBuilder;
|
||||
|
||||
@Builder(toBuilder = true)
|
||||
@With
|
||||
@Getter
|
||||
@EqualsAndHashCode
|
||||
public class {{configName}} {
|
||||
|
||||
@NonNull
|
||||
private final String baseUrl;
|
||||
@Builder.Default
|
||||
private final Client client = ClientBuilder.newClient();
|
||||
|
||||
}
|
|
@ -0,0 +1,118 @@
|
|||
/**
|
||||
* Auto-generated from apibuilder.io service spec.
|
||||
* apidoc-version : {{service.apidoc.version}}
|
||||
* organisation : {{service.organization.key}}
|
||||
* service-version : {{service.version}}
|
||||
*
|
||||
* Documentation at:
|
||||
* <a href="https://app.apibuilder.io/{{service.organization.key}}/{{service.name}}/{{service.version}}">https://app.apibuilder.io/{{service.organization.key}}/{{service.name}}/{{service.version}}</a>
|
||||
*
|
||||
**/
|
||||
package {{package}};
|
||||
|
||||
import {{service.namespace}}.{{service.configName}};
|
||||
{{#imports}}
|
||||
import {{.}};
|
||||
{{/imports}}
|
||||
|
||||
import lombok.*;
|
||||
|
||||
import javax.ws.rs.client.Entity;
|
||||
import javax.ws.rs.client.WebTarget;
|
||||
import javax.ws.rs.core.*;
|
||||
import java.net.URI;
|
||||
|
||||
|
||||
/**
|
||||
* Client for API resource {{service.namespace}}.{{name}}
|
||||
* version {{service.version}}
|
||||
*
|
||||
* {{description}}
|
||||
**/
|
||||
@RequiredArgsConstructor
|
||||
public class {{name}} {
|
||||
|
||||
private final {{service.configName}} config;
|
||||
|
||||
{{#operations}}
|
||||
/** {{description}} **/
|
||||
public {{name}} {{camelcase}} {{label}}() {
|
||||
return new {{name}}(this.config);
|
||||
}
|
||||
{{/operations}}
|
||||
|
||||
{{#operations}}
|
||||
/**
|
||||
* {{description}}
|
||||
**/
|
||||
public static class {{name}} {
|
||||
|
||||
private final {{service.configName}} config;
|
||||
{{#headers}}
|
||||
{{#default}}@Builder.Default {{/default}}{{#required}}@NonNull {{/required}}private {{{type.name}}} {{label}}_header {{#default}}= {{.}}{{/default}};
|
||||
{{/headers}}
|
||||
{{#query}}
|
||||
{{#default}}@Builder.Default {{/default}}{{#required}}@NonNull {{/required}}private {{{type.name}}} {{label}}_query {{#default}}= {{.}}{{/default}};
|
||||
{{/query}}
|
||||
|
||||
public {{name}}(@NonNull final {{service.configName}} config) {
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
public {{name}}Response request({{#parameters}}@NonNull {{{type.name}}} {{label}}{{^last}}, {{/last}}{{/parameters}}) {
|
||||
final URI uri = UriBuilder.fromUri(this.config.getBaseUrl())
|
||||
.path("{{{path}}}")
|
||||
.build();
|
||||
|
||||
WebTarget target = config.getClient().target(uri);
|
||||
Response response = target.request(MediaType.APPLICATION_JSON)
|
||||
.method("{{method}}"{{#body}}, Entity.json({{name}}){{/body}});
|
||||
int status = response.getStatus();
|
||||
switch(status) {
|
||||
{{#responses}}
|
||||
case {{code.integer.value}}:{{#label}}
|
||||
{{#type.isCollection}}{{{type.name}}} {{label}}Resp = response.readEntity(new GenericType<{{{type.name}}}>() {});{{/type.isCollection}}
|
||||
{{^type.isCollection}}{{{type.name}}} {{label}}Resp = response.readEntity({{{type.name}}}.class);{{/type.isCollection}}{{/label}}
|
||||
return {{name}}Response.builder()
|
||||
.status(status)
|
||||
.headers(response.getHeaders()){{#label}}
|
||||
.{{.}}({{.}}Resp){{/label}}
|
||||
.build();
|
||||
{{/responses}}
|
||||
default:
|
||||
return {{name}}Response.builder()
|
||||
.status(status)
|
||||
.unexpected(response.readEntity(String.class))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
{{#headers}}
|
||||
public {{op.name}} {{label}}({{{type.name}}} {{label}}) {
|
||||
this.{{label}}_header = {{label}};
|
||||
return this;
|
||||
}
|
||||
{{/headers}}
|
||||
{{#query}}
|
||||
public {{op.name}} {{label}}({{{type.name}}} {{label}}) {
|
||||
this.{{label}}_query = {{label}};
|
||||
return this;
|
||||
}
|
||||
{{/query}}
|
||||
|
||||
@Builder
|
||||
@Data
|
||||
public static class {{name}}Response {
|
||||
{{#responseTypes}}
|
||||
private {{{type.name}}} {{name}};
|
||||
{{/responseTypes}}
|
||||
|
||||
private final int status;
|
||||
private final MultivaluedMap<String, Object> headers;
|
||||
private final String unexpected;
|
||||
}
|
||||
}
|
||||
|
||||
{{/operations}}
|
||||
|
||||
}
|
|
@ -2,6 +2,7 @@
|
|||
* Auto-generated from apibuilder.io service spec.
|
||||
* apidoc-version : {{service.apidoc.version}}
|
||||
* organisation : {{service.organization.key}}
|
||||
* service-version : {{service.version}}
|
||||
*
|
||||
* Documentation at:
|
||||
* <a href="https://app.apibuilder.io/{{service.organization.key}}/{{service.name}}/{{service.version}}">https://app.apibuilder.io/{{service.organization.key}}/{{service.name}}/{{service.version}}</a>
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
* <a href="https://app.apibuilder.io/{{service.organization.key}}/{{service.name}}/{{service.version}}">https://app.apibuilder.io/{{service.organization.key}}/{{service.name}}/{{service.version}}</a>
|
||||
*
|
||||
**/
|
||||
package {{model.package}};
|
||||
package {{package}};
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.With;
|
||||
|
|
Loading…
Reference in New Issue