Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Alias schema for "date-time" generates java file that does not compile #3954

Open
alansartorio opened this issue Jun 30, 2024 · 0 comments
Assignees
Labels
java Java models, clients, and server interfaces

Comments

@alansartorio
Copy link

Describe the Bug

Alias schema for format: date-time causes compilation error in generated java code.

Information to Reproduce

CLI Version

0.31.7

Generator Version

fernapi/fern-java-spring
0.9.0

API Definition

OpenAPI specification required to reproduce the bug:

openapi: 3.1.0
info:
  version: 1.0.0
  title: Example
servers:
  - url: http://api.example.xyz/v1

paths:
components:
  schemas:
    Timestamp:
      type: string
      format: date-time
      description: ISO representation of a Timestamp
      example: 20-10-2020T23:59:59

Actual SDK

The buggy SDK that is produced:

/**
 * This file was auto-generated by Fern from our API Definition.
 */

package types;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import java.lang.Object;
import java.lang.String;
import java.time.OffsetDateTime;

public final class Timestamp {
  private final OffsetDateTime value;

  private Timestamp(OffsetDateTime value) {
    this.value = value;
  }

  ...

  @JsonCreator(
      mode = JsonCreator.Mode.DELEGATING
  )
  public static Timestamp of(OffsetDateTime value) {
    return new Timestamp(value);
  }

  public static Timestamp valueOf(String value) {
    return of(value);
  }
}

Notice the method valueOf calling of(...) with a string argument.

Expected SDK

The expected SDK

 ...

  public static Timestamp valueOf(String value) {
    return of(OffsetDateTime.parse(value));
  }
}

I think this bug comes from here:

return CodeBlock.builder().addStatement("return of(value)").build();

@alansartorio alansartorio added the java Java models, clients, and server interfaces label Jun 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
java Java models, clients, and server interfaces
Development

No branches or pull requests

2 participants