Skip to content

Commit

Permalink
Improve code generation (#1219)
Browse files Browse the repository at this point in the history
- Render descriptions using markdown
- Support generating "DictionaryResponse" types
- Support discriminated unions

Signed-off-by: Thomas Farr <[email protected]>
  • Loading branch information
Xtansia authored Oct 3, 2024
1 parent 897cc9b commit d045d86
Show file tree
Hide file tree
Showing 74 changed files with 1,498 additions and 455 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,12 @@ public class BulkByScrollTaskStatusOrException
implements
TaggedUnion<BulkByScrollTaskStatusOrException.Kind, Object>,
PlainJsonSerializable {
/**
* {@link BulkByScrollTaskStatusOrException} variant kinds.
*/
public enum Kind {
Status,
Exception
Exception,
Status
}

private final Kind _kind;
Expand Down Expand Up @@ -95,35 +98,35 @@ public static BulkByScrollTaskStatusOrException of(
}

/**
* Is this variant instance of kind {@code status}?
* Is this variant instance of kind {@code exception}?
*/
public boolean isStatus() {
return _kind == Kind.Status;
public boolean isException() {
return _kind == Kind.Exception;
}

/**
* Get the {@code status} variant value.
* Get the {@code exception} variant value.
*
* @throws IllegalStateException if the current variant is not the {@code status} kind.
* @throws IllegalStateException if the current variant is not the {@code exception} kind.
*/
public BulkByScrollTaskStatus status() {
return TaggedUnionUtils.get(this, Kind.Status);
public ErrorCause exception() {
return TaggedUnionUtils.get(this, Kind.Exception);
}

/**
* Is this variant instance of kind {@code exception}?
* Is this variant instance of kind {@code status}?
*/
public boolean isException() {
return _kind == Kind.Exception;
public boolean isStatus() {
return _kind == Kind.Status;
}

/**
* Get the {@code exception} variant value.
* Get the {@code status} variant value.
*
* @throws IllegalStateException if the current variant is not the {@code exception} kind.
* @throws IllegalStateException if the current variant is not the {@code status} kind.
*/
public ErrorCause exception() {
return TaggedUnionUtils.get(this, Kind.Exception);
public BulkByScrollTaskStatus status() {
return TaggedUnionUtils.get(this, Kind.Status);
}

@Override
Expand All @@ -137,26 +140,26 @@ public static class Builder extends ObjectBuilderBase implements ObjectBuilder<B
private Kind _kind;
private Object _value;

public ObjectBuilder<BulkByScrollTaskStatusOrException> status(BulkByScrollTaskStatus v) {
this._kind = Kind.Status;
public ObjectBuilder<BulkByScrollTaskStatusOrException> exception(ErrorCause v) {
this._kind = Kind.Exception;
this._value = v;
return this;
}

public ObjectBuilder<BulkByScrollTaskStatusOrException> status(
Function<BulkByScrollTaskStatus.Builder, ObjectBuilder<BulkByScrollTaskStatus>> fn
) {
return this.status(fn.apply(new BulkByScrollTaskStatus.Builder()).build());
public ObjectBuilder<BulkByScrollTaskStatusOrException> exception(Function<ErrorCause.Builder, ObjectBuilder<ErrorCause>> fn) {
return this.exception(fn.apply(new ErrorCause.Builder()).build());
}

public ObjectBuilder<BulkByScrollTaskStatusOrException> exception(ErrorCause v) {
this._kind = Kind.Exception;
public ObjectBuilder<BulkByScrollTaskStatusOrException> status(BulkByScrollTaskStatus v) {
this._kind = Kind.Status;
this._value = v;
return this;
}

public ObjectBuilder<BulkByScrollTaskStatusOrException> exception(Function<ErrorCause.Builder, ObjectBuilder<ErrorCause>> fn) {
return this.exception(fn.apply(new ErrorCause.Builder()).build());
public ObjectBuilder<BulkByScrollTaskStatusOrException> status(
Function<BulkByScrollTaskStatus.Builder, ObjectBuilder<BulkByScrollTaskStatus>> fn
) {
return this.status(fn.apply(new BulkByScrollTaskStatus.Builder()).build());
}

@Override
Expand All @@ -168,8 +171,8 @@ public BulkByScrollTaskStatusOrException build() {

private static JsonpDeserializer<BulkByScrollTaskStatusOrException> buildBulkByScrollTaskStatusOrExceptionDeserializer() {
return new UnionDeserializer.Builder<BulkByScrollTaskStatusOrException, Kind, Object>(BulkByScrollTaskStatusOrException::new, false)
.addMember(Kind.Status, BulkByScrollTaskStatus._DESERIALIZER)
.addMember(Kind.Exception, ErrorCause._DESERIALIZER)
.addMember(Kind.Status, BulkByScrollTaskStatus._DESERIALIZER)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

/*
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/

//----------------------------------------------------
// THIS CODE IS GENERATED. MANUAL EDITS WILL BE LOST.
//----------------------------------------------------

package org.opensearch.client.opensearch._types;

import javax.annotation.Generated;

/**
* Builders for {@link BulkByScrollTaskStatusOrException} variants.
*/
@Generated("org.opensearch.client.codegen.CodeGenerator")
public class BulkByScrollTaskStatusOrExceptionBuilders {
private BulkByScrollTaskStatusOrExceptionBuilders() {}

/**
* Creates a builder for the {@link ErrorCause exception} {@code BulkByScrollTaskStatusOrException} variant.
*/
public static ErrorCause.Builder exception() {
return new ErrorCause.Builder();
}

/**
* Creates a builder for the {@link BulkByScrollTaskStatus status} {@code BulkByScrollTaskStatusOrException} variant.
*/
public static BulkByScrollTaskStatus.Builder status() {
return new BulkByScrollTaskStatus.Builder();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public final List<ErrorCause> rootCause() {
}

/**
* The server stack trace. Present only if the `error_trace=true` parameter was sent with the request.
* The server stack trace. Present only if the <code>error_trace=true</code> parameter was sent with the request.
* <p>
* API name: {@code stack_trace}
* </p>
Expand Down Expand Up @@ -298,7 +298,7 @@ public final Builder rootCause(Function<ErrorCause.Builder, ObjectBuilder<ErrorC
}

/**
* The server stack trace. Present only if the `error_trace=true` parameter was sent with the request.
* The server stack trace. Present only if the <code>error_trace=true</code> parameter was sent with the request.
* <p>
* API name: {@code stack_trace}
* </p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public static DeleteDanglingIndexResponse of(
public static class Builder extends AcknowledgedResponseBase.AbstractBuilder<Builder>
implements
ObjectBuilder<DeleteDanglingIndexResponse> {

@Override
protected Builder self() {
return this;
Expand Down Expand Up @@ -99,7 +100,7 @@ public DeleteDanglingIndexResponse build() {
);

protected static void setupDeleteDanglingIndexResponseDeserializer(ObjectDeserializer<DeleteDanglingIndexResponse.Builder> op) {
AcknowledgedResponseBase.setupAcknowledgedResponseBaseDeserializer(op);
setupAcknowledgedResponseBaseDeserializer(op);
}

public int hashCode() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public static ImportDanglingIndexResponse of(
public static class Builder extends AcknowledgedResponseBase.AbstractBuilder<Builder>
implements
ObjectBuilder<ImportDanglingIndexResponse> {

@Override
protected Builder self() {
return this;
Expand Down Expand Up @@ -99,7 +100,7 @@ public ImportDanglingIndexResponse build() {
);

protected static void setupImportDanglingIndexResponseDeserializer(ObjectDeserializer<ImportDanglingIndexResponse.Builder> op) {
AcknowledgedResponseBase.setupAcknowledgedResponseBaseDeserializer(op);
setupAcknowledgedResponseBaseDeserializer(op);
}

public int hashCode() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public static DeleteAgentResponse of(Function<DeleteAgentResponse.Builder, Objec
* Builder for {@link DeleteAgentResponse}.
*/
public static class Builder extends WriteResponseBase.AbstractBuilder<Builder> implements ObjectBuilder<DeleteAgentResponse> {

@Override
protected Builder self() {
return this;
Expand Down Expand Up @@ -71,7 +72,7 @@ public DeleteAgentResponse build() {
);

protected static void setupDeleteAgentResponseDeserializer(ObjectDeserializer<DeleteAgentResponse.Builder> op) {
WriteResponseBase.setupWriteResponseBaseDeserializer(op);
setupWriteResponseBaseDeserializer(op);
}

public int hashCode() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public static DeleteConnectorResponse of(Function<DeleteConnectorResponse.Builde
* Builder for {@link DeleteConnectorResponse}.
*/
public static class Builder extends WriteResponseBase.AbstractBuilder<Builder> implements ObjectBuilder<DeleteConnectorResponse> {

@Override
protected Builder self() {
return this;
Expand Down Expand Up @@ -71,7 +72,7 @@ public DeleteConnectorResponse build() {
);

protected static void setupDeleteConnectorResponseDeserializer(ObjectDeserializer<DeleteConnectorResponse.Builder> op) {
WriteResponseBase.setupWriteResponseBaseDeserializer(op);
setupWriteResponseBaseDeserializer(op);
}

public int hashCode() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public static DeleteModelGroupResponse of(Function<DeleteModelGroupResponse.Buil
* Builder for {@link DeleteModelGroupResponse}.
*/
public static class Builder extends WriteResponseBase.AbstractBuilder<Builder> implements ObjectBuilder<DeleteModelGroupResponse> {

@Override
protected Builder self() {
return this;
Expand Down Expand Up @@ -71,7 +72,7 @@ public DeleteModelGroupResponse build() {
);

protected static void setupDeleteModelGroupResponseDeserializer(ObjectDeserializer<DeleteModelGroupResponse.Builder> op) {
WriteResponseBase.setupWriteResponseBaseDeserializer(op);
setupWriteResponseBaseDeserializer(op);
}

public int hashCode() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public static DeleteModelResponse of(Function<DeleteModelResponse.Builder, Objec
* Builder for {@link DeleteModelResponse}.
*/
public static class Builder extends WriteResponseBase.AbstractBuilder<Builder> implements ObjectBuilder<DeleteModelResponse> {

@Override
protected Builder self() {
return this;
Expand Down Expand Up @@ -71,7 +72,7 @@ public DeleteModelResponse build() {
);

protected static void setupDeleteModelResponseDeserializer(ObjectDeserializer<DeleteModelResponse.Builder> op) {
WriteResponseBase.setupWriteResponseBaseDeserializer(op);
setupWriteResponseBaseDeserializer(op);
}

public int hashCode() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public static DeleteTaskResponse of(Function<DeleteTaskResponse.Builder, ObjectB
* Builder for {@link DeleteTaskResponse}.
*/
public static class Builder extends WriteResponseBase.AbstractBuilder<Builder> implements ObjectBuilder<DeleteTaskResponse> {

@Override
protected Builder self() {
return this;
Expand Down Expand Up @@ -71,7 +72,7 @@ public DeleteTaskResponse build() {
);

protected static void setupDeleteTaskResponseDeserializer(ObjectDeserializer<DeleteTaskResponse.Builder> op) {
WriteResponseBase.setupWriteResponseBaseDeserializer(op);
setupWriteResponseBaseDeserializer(op);
}

public int hashCode() {
Expand Down
Loading

0 comments on commit d045d86

Please sign in to comment.