-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Andriy Redko <andriy.redko@aiven.io>
- Loading branch information
Showing
8 changed files
with
545 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
plugins { | ||
id 'java' | ||
id 'org.openapi.generator' version "6.2.1" | ||
} | ||
|
||
openApiGenerate { | ||
generatorName = "java" | ||
library = "native" | ||
inputSpec = "$projectDir/specs/opensearch-openapi-20190104230353-snippet.json" | ||
templateDir = "$projectDir/src/main/resources/templates" | ||
outputDir = "$buildDir/generated" | ||
modelPackage = "org.opensearch.client" | ||
apiPackage = "org.opensearch.client" | ||
generateModelTests = false | ||
generateModelDocumentation = false | ||
generateApiTests = false | ||
generateApiDocumentation = false | ||
globalProperties = [ | ||
apis: "", | ||
invokers: "false", | ||
models: "" | ||
] | ||
configOptions = [ | ||
dateLibrary: "java8" | ||
] | ||
} |
238 changes: 238 additions & 0 deletions
238
java-client-generator/specs/opensearch-openapi-20190104230353-snippet.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,238 @@ | ||
{ | ||
"openapi": "3.0.3", | ||
"info": { | ||
"title": "OpenSearch", | ||
"description": "OpenSearch API docs", | ||
"contact": { | ||
"name": "OpenSearch Project", | ||
"url": "https://opensearch.org" | ||
}, | ||
"license": { | ||
"name": "Apache 2.0", | ||
"url": "http://www.apache.org/licenses/LICENSE-2.0.html" | ||
}, | ||
"version": "3.0.0-SNAPSHOT" | ||
}, | ||
"servers": [], | ||
"paths": { | ||
"/_cluster/health": { | ||
"get": { | ||
"tags": [], | ||
"operationId": "health", | ||
"parameters": [ | ||
{ | ||
"name": "params", | ||
"in": "query", | ||
"required": true, | ||
"schema": { | ||
"$ref": "#/components/schemas/HealthRequest" | ||
} | ||
} | ||
], | ||
"responses": { | ||
"200": { | ||
"description": "OK", | ||
"content": { | ||
"application/json": { | ||
"schema": { | ||
"$ref": "#/components/schemas/HealthResponse" | ||
} | ||
} | ||
} | ||
}, | ||
"404": { | ||
"description": "Not Found.", | ||
"content": {} | ||
}, | ||
"500": { | ||
"description": "Technical error.", | ||
"content": {} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"components": { | ||
"schemas": { | ||
"HealthRequest": { | ||
"x-request-for": "health", | ||
"type": "object", | ||
"properties": { | ||
"level": { | ||
"description": "Specify the level of detail for returned information", | ||
"type": "string", | ||
"default": "cluster" | ||
}, | ||
"local": { | ||
"description": "Return local information, do not retrieve the state from master node (default: false)", | ||
"type": "boolean" | ||
}, | ||
"master_timeout": { | ||
"description": "Explicit operation timeout for connection to master node", | ||
"type": "string" | ||
}, | ||
"timeout": { | ||
"description": "Explicit operation timeout", | ||
"type": "string" | ||
}, | ||
"wait_for_active_shards": { | ||
"description": "Wait until the specified number of shards is active", | ||
"type": "string" | ||
}, | ||
"wait_for_nodes": { | ||
"description": "Wait until the specified number of nodes is available", | ||
"type": "string" | ||
}, | ||
"wait_for_events": { | ||
"description": "Wait until all currently queued events with the given priority are processed", | ||
"type": "string" | ||
}, | ||
"wait_for_no_relocating_shards": { | ||
"description": "Whether to wait until there are no relocating shards in the cluster", | ||
"type": "boolean" | ||
}, | ||
"wait_for_no_initializing_shards": { | ||
"description": "Whether to wait until there are no initializing shards in the cluster", | ||
"type": "boolean" | ||
}, | ||
"wait_for_status": { | ||
"description": "Wait until cluster is in a specific state", | ||
"type": "string" | ||
}, | ||
"pretty": { | ||
"description": "Pretty format the returned JSON response.", | ||
"type": "boolean", | ||
"default": false | ||
}, | ||
"human": { | ||
"description": "Return human readable values for statistics.", | ||
"type": "boolean", | ||
"default": true | ||
}, | ||
"error_trace": { | ||
"description": "Include the stack trace of returned errors.", | ||
"type": "boolean", | ||
"default": false | ||
}, | ||
"index": { | ||
"description": "A comma-separated list of filters used to reduce the response.", | ||
"type": "array", | ||
"items": { | ||
"type": "string" | ||
} | ||
} | ||
} | ||
}, | ||
"HealthStatus": { | ||
"type": "string", | ||
"enum": [ "GREEN", "YELLOW", "RED" ] | ||
}, | ||
"IndexHealthStats": { | ||
"type": "object", | ||
"properties": { | ||
"activePrimaryShards": { | ||
"type": "integer" | ||
}, | ||
"activeShards": { | ||
"type": "integer" | ||
}, | ||
"initializingShards": { | ||
"type": "integer" | ||
}, | ||
"numberOfReplicas": { | ||
"type": "integer" | ||
}, | ||
"numberOfShards": { | ||
"type": "integer" | ||
}, | ||
"relocatingShards": { | ||
"type": "integer" | ||
}, | ||
"unassignedShards": { | ||
"type": "integer" | ||
}, | ||
"status": { | ||
"$ref": "#/components/schemas/HealthStatus" | ||
} | ||
}, | ||
"required": [ | ||
"unassignedShards", | ||
"relocatingShards", | ||
"unassignedShards", | ||
"activePrimaryShards", | ||
"activeShards", | ||
"numberOfShards", | ||
"initializingShards" | ||
] | ||
}, | ||
"HealthResponse": { | ||
"type": "object", | ||
"properties": { | ||
"timedOut": { | ||
"type": "boolean" | ||
}, | ||
"activePrimaryShards": { | ||
"type": "integer" | ||
}, | ||
"activeShards": { | ||
"type": "integer" | ||
}, | ||
"activeShardsPercentAsNumber": { | ||
"type": "string" | ||
}, | ||
"clusterName": { | ||
"type": "string" | ||
}, | ||
"delayedUnassignedShards": { | ||
"type": "integer" | ||
}, | ||
"initializingShards": { | ||
"type": "integer" | ||
}, | ||
"numberOfDataNodes": { | ||
"type": "integer" | ||
}, | ||
"numberOfInFlightFetch": { | ||
"type": "integer" | ||
}, | ||
"numberOfNodes": { | ||
"type": "integer" | ||
}, | ||
"numberOfPendingTasks": { | ||
"type": "integer" | ||
}, | ||
"relocatingShards": { | ||
"type": "integer" | ||
}, | ||
"taskMaxWaitingInQueueMillis": { | ||
"type": "string" | ||
}, | ||
"unassignedShards": { | ||
"type": "integer" | ||
}, | ||
"status": { | ||
"$ref": "#/components/schemas/HealthStatus" | ||
}, | ||
"indices": { | ||
"type": "object", | ||
"additionalProperties": { | ||
"$ref": "#/components/schemas/IndexHealthStats" | ||
} | ||
} | ||
}, | ||
"required": [ | ||
"unassignedShards", | ||
"relocatingShards", | ||
"numberOfPendingTasks", | ||
"numberOfNodes", | ||
"numberOfInFlightFetch", | ||
"numberOfDataNodes", | ||
"initializingShards", | ||
"delayedUnassignedShards", | ||
"activePrimaryShards", | ||
"activeShards" | ||
] | ||
} | ||
} | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
java-client-generator/src/main/resources/templates/api.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
{{>licenseInfo}} | ||
package {{package}}; | ||
|
||
import org.opensearch.client.opensearch._types.ErrorResponse; | ||
import org.opensearch.client.transport.Endpoint; | ||
import org.opensearch.client.transport.endpoints.SimpleEndpoint; | ||
|
||
import java.util.Map; | ||
import java.util.HashMap; | ||
|
||
{{>generatedAnnotation}} | ||
{{#operations}} | ||
{{#operation}} | ||
class {{classname}} { | ||
static class {{#lambda.titlecase}}{{operationId}}{{/lambda.titlecase}} { | ||
public static final Endpoint<{{#lambda.titlecase}}{{operationId}}{{/lambda.titlecase}}Request, {{#lambda.titlecase}}{{operationId}}{{/lambda.titlecase}}Response, ErrorResponse> _ENDPOINT = new SimpleEndpoint<>( | ||
// Request method | ||
request -> { | ||
return "{{httpMethod}}"; | ||
}, | ||
|
||
// Request path | ||
request -> { | ||
return "{{{path}}}"; | ||
}, | ||
|
||
// Request query parameters | ||
{{#lambda.titlecase}}{{operationId}}{{/lambda.titlecase}}Request._QUERY, | ||
|
||
// Request headers | ||
request -> { | ||
final Map<String, String> headers = new HashMap<>(); | ||
{{#headerParams}} | ||
if (request.{{paramName}}() != null) | ||
headers.put("{{baseName}}", request.{{paramName}}()); | ||
} | ||
{{/headerParams}} | ||
return headers; | ||
}, | ||
|
||
{{#bodyParam}}true{{/bodyParam}}{{^bodyParam}}false{{/bodyParam}}, | ||
{{#lambda.titlecase}}{{operationId}}{{/lambda.titlecase}}Response._DESERIALIZER | ||
); | ||
} | ||
{{/operation}} | ||
} | ||
{{/operations}} |
39 changes: 39 additions & 0 deletions
39
java-client-generator/src/main/resources/templates/model-enum.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import org.opensearch.client.json.JsonEnum; | ||
import org.opensearch.client.json.JsonpDeserializable; | ||
|
||
{{>generatedAnnotation}} | ||
@JsonpDeserializable | ||
{{>additionalEnumTypeAnnotations}}public enum {{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} implements JsonEnum { | ||
{{#allowableValues}}{{#enumVars}} | ||
{{#enumDescription}} | ||
/** | ||
* {{.}} | ||
*/ | ||
{{/enumDescription}} | ||
{{#lambda.titlecase}}{{#lambda.lowercase}}{{{name}}}{{/lambda.lowercase}}{{/lambda.titlecase}}({{#lambda.lowercase}}{{{value}}}{{/lambda.lowercase}}, {{{value}}}){{^-last}}, | ||
{{/-last}}{{#-last}};{{/-last}}{{/enumVars}}{{/allowableValues}} | ||
|
||
private {{{dataType}}} value; | ||
private final {{{dataType}}}[] aliases; | ||
|
||
{{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}({{{dataType}}} value, {{{dataType}}} ... aliases) { | ||
this.value = value; | ||
this.aliases = aliases; | ||
} | ||
|
||
public {{{dataType}}} getValue() { | ||
return value; | ||
} | ||
|
||
public String[] aliases() { | ||
return this.aliases; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return String.valueOf(value); | ||
} | ||
|
||
public static final JsonEnum.Deserializer<{{{classname}}}> _DESERIALIZER = new JsonEnum.Deserializer<>( | ||
{{{classname}}}.values()); | ||
} |
Oops, something went wrong.