Skip to content

Commit

Permalink
fix(java): Fix usage of cursor pagination causing endpoint return typ…
Browse files Browse the repository at this point in the history
…e to be void (#5708)

* fix(java): Fix usage of cursor pagination causing endpoint return type to be void

* Add test case

* Run seed against new test case

* Allow objects with nonempty path to be used for cursor pagination

* run seed

* Add a utility to find the property type of the desired property within the request body

* Add new test case just for deep cursor path

* run new fixture

* run the fixture

* Refactor next page number offset pagination for easier overriding

* Fix fixture

* Add more test cases

* Add test case as expected failure

* test udpate

* Handle different zero value possibilities for next snippet

* Fix nits

* Change test definition

* Delete pagination gens

* delete long snapshots

* Delete all complex

* Rerun pagination tests

---------

Co-authored-by: Alberto <[email protected]>
Co-authored-by: fern-support <115122769+fern-api[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Jan 29, 2025
1 parent ba4f306 commit 8b2b96e
Show file tree
Hide file tree
Showing 111 changed files with 12,034 additions and 93 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.fern.java.client.generators.endpoint;

import com.squareup.javapoet.CodeBlock;
import com.squareup.javapoet.TypeName;
import java.util.Optional;
import org.immutables.value.Value;

// TODO(ajgateno): This will be necessary until the required IR changes include more information about the path
@Value.Immutable
public interface EnrichedCursorPathGetter {

EnrichedCursorPathItem pathItem();

CodeBlock getter();

TypeName typeName();

Optional<EnrichedCursorPathGetter> previous();

@Value.Default
default boolean optional() {
return false;
}

default String propertyName() {
return pathItem().name().getCamelCase().getSafeName();
}

static ImmutableEnrichedCursorPathGetter.Builder builder() {
return ImmutableEnrichedCursorPathGetter.builder();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.fern.java.client.generators.endpoint;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fern.ir.model.commons.Name;
import org.immutables.value.Value;

// TODO(ajgateno): This will be necessary until the required IR changes include more information about the path
@Value.Immutable
@JsonSerialize(as = ImmutableEnrichedCursorPathItem.class)
@JsonDeserialize(as = ImmutableEnrichedCursorPathItem.class)
public interface EnrichedCursorPathItem {

@JsonProperty("name")
Name name();

@Value.Default
@JsonProperty("optional")
default boolean optional() {
return false;
}

// TODO(ajgateno): Check for wrapped aliases and add a .value to getter if necessary
@Value.Default
@JsonProperty("alias")
default boolean alias() {
return false;
}

static ImmutableEnrichedCursorPathItem.Builder builder() {
return ImmutableEnrichedCursorPathItem.builder();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.fern.java.client.generators.endpoint;

import com.squareup.javapoet.CodeBlock;
import org.immutables.value.Value;

// TODO(ajgateno): This will be necessary until the required IR changes include more information about the path
@Value.Immutable
public interface EnrichedCursorPathSetter {

EnrichedCursorPathGetter getter();

CodeBlock setter();

static ImmutableEnrichedCursorPathSetter.Builder builder() {
return ImmutableEnrichedCursorPathSetter.builder();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,9 @@ public CodeBlock getInitializeRequestCodeBlock(
@Override
public Void visitTypeReference(HttpRequestBodyReference typeReference) {
builder.add(".addHeader($S, $S)\n", AbstractEndpointWriter.CONTENT_TYPE_HEADER, contentType);
AbstractEndpointWriter.responseContentType(httpEndpoint.getResponse())
.ifPresent(responseContentType -> builder.add(
".addHeader($S, $S)\n", AbstractEndpointWriter.ACCEPT_HEADER, contentType));
return null;
}

Expand Down
Loading

0 comments on commit 8b2b96e

Please sign in to comment.