fern-api / fern

Input OpenAPI. Output SDKs and Docs.
https://buildwithfern.com
Apache License 2.0
2.6k stars 139 forks source link

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

Open alansartorio opened 3 months ago

alansartorio commented 3 months ago

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: https://github.com/fern-api/fern/blob/d8575c97610b96e58a2858dc386ad61b8af55d9d/generators/java/generator-utils/src/main/java/com/fern/java/generators/AliasGenerator.java#L168