Skip to content

Commit

Permalink
Test using names
Browse files Browse the repository at this point in the history
  • Loading branch information
Alberto committed Jan 6, 2025
1 parent 5286cc2 commit 1d01453
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public GeneratedClientOptions generateFile() {
String.class,
platformHeadersPutString)
.addStatement("this.$L = $L", HEADER_SUPPLIERS_FIELD.name, HEADER_SUPPLIERS_FIELD.name)
.addStatement("this.$L = $L", OKHTTP_CLIENT_FIELD.name, OKHTTP_CLIENT_FIELD.name);
.addStatement("this.$L = $L", OKHTTP_CLIENT_FIELD.name, OKHTTP_CLIENT_FIELD.name)
.addStatement("this.$L = $L", TIMEOUT_FIELD.name, TIMEOUT_FIELD.name);

if (clientGeneratorContext.getIr().getApiVersion().isPresent()) {
Expand All @@ -159,14 +159,14 @@ public GeneratedClientOptions generateFile() {
apiVersionScheme.visit(new ApiVersionScheme.Visitor<Void>() {
@Override
public Void visitHeader(HeaderApiVersionScheme headerApiVersionScheme) {
contructorBuilder.addParameter(ParameterSpec.builder(
constructorBuilder.addParameter(ParameterSpec.builder(
ParameterizedTypeName.get(
ClassName.get(Optional.class), ClassName.get(String.class)),
API_VERSIONS_FIELD.name)
.build());

if (headerApiVersionScheme.getValue().getDefault().isPresent()) {
contructorBuilder.addStatement(
constructorBuilder.addStatement(
"this.$L = $L.orElse($S)",
API_VERSIONS_FIELD.name,
API_VERSIONS_FIELD.name,
Expand All @@ -177,11 +177,11 @@ public Void visitHeader(HeaderApiVersionScheme headerApiVersionScheme) {
.getName()
.getWireValue());
} else {
contructorBuilder.addStatement(
constructorBuilder.addStatement(
"this.$L = $L", API_VERSIONS_FIELD.name, API_VERSIONS_FIELD.name);
}

contructorBuilder.addStatement(
constructorBuilder.addStatement(
"this.$L.put($S,$L)",
HEADERS_FIELD.name,
headerApiVersionScheme.getHeader().getName().getWireValue(),
Expand All @@ -195,7 +195,7 @@ public Void _visitUnknown(Object _o) {
throw new IllegalArgumentException("Received unknown API versioning schema type in IR.");
}
});
>>>>>>> main
}

variableFields
.values()
Expand Down Expand Up @@ -291,7 +291,6 @@ public Void _visitUnknown(Object _o) {
.httpClientWithTimeout(httpClientWithTimeoutGetter)
.builderClassName(builderClassName)
.putAllVariableGetters(variableGetters)
.version(versionsGetter)
.build();
}

Expand Down Expand Up @@ -355,9 +354,6 @@ private TypeSpec createBuilder(ClientGeneratorContext context, Map<VariableId, F
.addStatement("this.$L = $L", TIMEOUT_FIELD.name, TIMEOUT_FIELD.name)
.addStatement("return this")
.build())
.addMethods(getVariableBuilders(variableFields))
.addMethod(getBuildMethod(variableFields))
.build();
.addMethods(getVariableBuilders(variableFields));

if (context.getIr().getApiVersion().isPresent()) {
Expand Down Expand Up @@ -395,23 +391,23 @@ private MethodSpec getHeaderBuilder() {
.build();
}

private MethodSpec getHeaderSupplierBuilder() {
return MethodSpec.methodBuilder("addHeader")
private MethodSpec getVersionBuilder() {
return MethodSpec.methodBuilder(API_VERSIONS_FIELD.name)
.addModifiers(Modifier.PUBLIC)
.returns(builderClassName)
.addParameter(String.class, "key")
.addParameter(ParameterizedTypeName.get(Supplier.class, String.class), "value")
.addStatement("this.$L.put($L, $L)", HEADER_SUPPLIERS_FIELD.name, "key", "value")
.addParameter(String.class, API_VERSIONS_FIELD.name)
.addStatement("this.$L = $T.of($L)", API_VERSIONS_FIELD.name, Optional.class, API_VERSIONS_FIELD.name)
.addStatement("return this")
.build();
}

private MethodSpec getVersionBuilder() {
return MethodSpec.methodBuilder(API_VERSIONS_FIELD.name)
private MethodSpec getHeaderSupplierBuilder() {
return MethodSpec.methodBuilder("addHeader")
.addModifiers(Modifier.PUBLIC)
.returns(builderClassName)
.addParameter(String.class, API_VERSIONS_FIELD.name)
.addStatement("this.$L = $T.of($L)", API_VERSIONS_FIELD.name, Optional.class, API_VERSIONS_FIELD.name)
.addParameter(String.class, "key")
.addParameter(ParameterizedTypeName.get(Supplier.class, String.class), "value")
.addStatement("this.$L.put($L, $L)", HEADER_SUPPLIERS_FIELD.name, "key", "value")
.addStatement("return this")
.build();
}
Expand Down Expand Up @@ -470,11 +466,11 @@ private MethodSpec getBuildMethod(ClientGeneratorContext context, Map<VariableId
argsBuilder.add(
className, environmentField.name, HEADERS_FIELD.name, HEADER_SUPPLIERS_FIELD.name, "okhttpClient");

String returnString = "return new $T($L, $L, $L, $L";
String returnString = "return new $T($L, $L, $L, $L, this.timeout";

if (context.getIr().getApiVersion().isPresent()) {
argsBuilder.add(API_VERSIONS_FIELD.name);
returnString = "return new $T($L, $L, $L, $L, $L";
returnString = "return new $T($L, $L, $L, $L, this.timeout, $L";
}

Object[] args = argsBuilder.build().toArray();
Expand Down
6 changes: 4 additions & 2 deletions seed/java-sdk/version/.mock/definition/api.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1d01453

Please sign in to comment.