Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何为Kotlin数据类中的属性设置OpenAPI类型/模式_Kotlin_Openapi_Quarkus_Microprofile - Fatal编程技术网

如何为Kotlin数据类中的属性设置OpenAPI类型/模式

如何为Kotlin数据类中的属性设置OpenAPI类型/模式,kotlin,openapi,quarkus,microprofile,Kotlin,Openapi,Quarkus,Microprofile,在使用Kotlin的Microprofile/Quarkus项目中,有一个带有Instant类型变量的数据类 @Schema(name=“Vehicle”,description=“表示特定时间的车辆的POJO”) 数据类车辆( 变量时间:Instant=Instant.EPOCH ) 问题是生成的openapi模式并不表示Instant的值实际上是如何传输的 模式如下所示,而它只是表示为这样的字符串:2015-06-02T21:34:33.616Z. 即时: 类型:对象 特性: 纳米: 格式

在使用Kotlin的Microprofile/Quarkus项目中,有一个带有Instant类型变量的数据类

@Schema(name=“Vehicle”,description=“表示特定时间的车辆的POJO”)
数据类车辆(
变量时间:Instant=Instant.EPOCH
)
问题是生成的openapi模式并不表示Instant的值实际上是如何传输的

模式如下所示,而它只是表示为这样的字符串:
2015-06-02T21:34:33.616Z.

即时:
类型:对象
特性:
纳米:
格式:int32
类型:整数
秒数:
格式:int64
类型:整数
第二个时代:
格式:int64
类型:整数
纳米技术:
格式:int32
类型:整数
我已经尝试注释数据类以使用实现字符串和类型字符串,但它没有改变任何东西

@Schema(name=“Vehicle”,description=“表示特定时间的车辆的POJO”)
数据类车辆(
@模式(实现=字符串::类,类型=SchemaType.String)
变量时间:Instant=Instant.EPOCH
)

问题是数据类受到了一些特殊处理,并且您的注释被放置在构造函数参数上

您可以在数据类生成的字节码中看到这一点。相关片段:

@Schema(
   name = "Vehicle",
   description = "POJO that represents a vehicle at a specific time."
)
@Metadata(...)
public final class VehicleDTO {
   @NotNull
   private Instant time;

   @NotNull
   public final Instant getTime() {
      return this.time;
   }

   public final void setTime(@NotNull Instant var1) {
      Intrinsics.checkParameterIsNotNull(var1, "<set-?>");
      this.time = var1;
   }

   public VehicleDTO(@Schema(implementation = String.class,type = SchemaType.STRING) @NotNull Instant time) {
      Intrinsics.checkParameterIsNotNull(time, "time");
      super();
      this.time = time;
   }

   // ...
}
相关字节码:

@Schema(
   name = "Vehicle",
   description = "POJO that represents a vehicle at a specific time."
)
@Metadata(...)
public final class VehicleDTO {
   @Schema(
      implementation = String.class,
      type = SchemaType.STRING
   )
   @NotNull
   private Instant time;

   @NotNull
   public final Instant getTime() {
      return this.time;
   }

   public final void setTime(@NotNull Instant var1) {
      Intrinsics.checkParameterIsNotNull(var1, "<set-?>");
      this.time = var1;
   }

   public VehicleDTO(@NotNull Instant time) {
      Intrinsics.checkParameterIsNotNull(time, "time");
      super();
      this.time = time;
   }

   // ...
}
@Schema(
name=“车辆”,
description=“表示特定时间车辆的POJO。”
)
@元数据(…)
公共末级车辆{
@模式(
实现=String.class,
type=SchemaType.STRING
)
@NotNull
私人即时时间;
@NotNull
公共最终即时获取时间(){
这次回来;
}
公共最终无效设置时间(@NotNull Instant var1){
Intrinsics.checkParametersNotNull(var1,“”);
this.time=var1;
}
公共车辆到达(@NotNull即时时间){
本质。检查参数完整(时间,“时间”);
超级();
这个时间=时间;
}
// ...
}

问题,如果使用Java而不是Kotlin,这是否有效?
@Schema(
   name = "Vehicle",
   description = "POJO that represents a vehicle at a specific time."
)
@Metadata(...)
public final class VehicleDTO {
   @Schema(
      implementation = String.class,
      type = SchemaType.STRING
   )
   @NotNull
   private Instant time;

   @NotNull
   public final Instant getTime() {
      return this.time;
   }

   public final void setTime(@NotNull Instant var1) {
      Intrinsics.checkParameterIsNotNull(var1, "<set-?>");
      this.time = var1;
   }

   public VehicleDTO(@NotNull Instant time) {
      Intrinsics.checkParameterIsNotNull(time, "time");
      super();
      this.time = time;
   }

   // ...
}