121 lines
4.4 KiB
Plaintext
121 lines
4.4 KiB
Plaintext
/**
|
|
* 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}}.client.{{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}}) {
|
|
// {{{path}}}
|
|
final URI uri = UriBuilder.fromUri(this.config.getBaseUrl()){{#pathElements}}
|
|
.path({{{name}}}){{/pathElements}}{{#query}}
|
|
.queryParam("{{name}}", this.{{label}}_query){{/query}}
|
|
.build();
|
|
|
|
WebTarget target = config.getClient().target(uri);
|
|
Response response = target.request(MediaType.APPLICATION_JSON){{#headers}}
|
|
.header("{{name}}", this.{{label}}_header){{/headers}}
|
|
.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}}
|
|
|
|
} |