Skip to content

Commit

Permalink
OpenAPIv3 Generator Experiment
Browse files Browse the repository at this point in the history
Signed-off-by: Andriy Redko <andriy.redko@aiven.io>
  • Loading branch information
reta committed Jan 19, 2023
1 parent 6096034 commit 5a97da5
Show file tree
Hide file tree
Showing 7 changed files with 438 additions and 0 deletions.
20 changes: 20 additions & 0 deletions java-client-generator/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
plugins {
id "org.openapi.generator" version "6.2.1"
}

openApiGenerate {
generatorName = "java"
library = "native"
inputSpec = "$projectDir/specs/opensearch-openapi-20190104230353-snippet.json"
templateDir = "$projectDir/src/java/resources/templates"
outputDir = "$buildDir/generated"
modelPackage = "org.opensearch.client"
globalProperties = [
apis: "false",
invokers: "false",
models: ""
]
configOptions = [
dateLibrary: "java8"
]
}
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": "health2",
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/HealthRequest"
}
}
},
"required": true
},
"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": true,
"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"
]
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import org.opensearch.client.json.JsonEnum;
import org.opensearch.client.json.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;
}

@Override
public String toString() {
return String.valueOf(value);
}

public static final JsonEnum.Deserializer<{{{datatypeWithEnum}}}> _DESERIALIZER = new JsonEnum.Deserializer<>(
{{{classname}}}.values());
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
public class {{classname}} extends RequestBase {
{{#vars}}
private final {{{datatypeWithEnum}}} {{name}};
{{/vars}}


private {{classname}}(Builder builder) {
{{#vars}}
this.{{name}} = builder.{{name}};
{{/vars}}
}

public static {{classname}} of(Function<Builder, ObjectBuilder<{{classname}}>> fn) {
return fn.apply(new Builder()).build();
}

{{#vars}}
public {{{datatypeWithEnum}}} {{getter}}() {
return this.{{name}};
}
{{/vars}}

public static class Builder extends ObjectBuilderBase implements ObjectBuilder<{{classname}}> {
{{#vars}}
private {{{datatypeWithEnum}}} {{name}};
{{/vars}}

{{#vars}}
public Builder {{name}}({{{datatypeWithEnum}}} value) {
this.{{name}} = value;
return this;
}
{{/vars}}

public {{classname}} build() {
_checkSingleUse();
return new {{classname}}(this);
}
}
}
Loading

0 comments on commit 5a97da5

Please sign in to comment.