我在 spring 项目中使用 OpenAPI java 生成器 [1] 和 library:resttemplate, dateLibrary:java8 从规范生成客户端。
对于规范中的属性:
targetDate:
type: string
format: date
Run Code Online (Sandbox Code Playgroud)
生成以下代码:
public static final String JSON_PROPERTY_TARGET_DATE = "targetDate";
private LocalDate targetDate;
@javax.annotation.Nonnull
@JsonProperty(JSON_PROPERTY_TARGET_DATE)
@JsonInclude(value = JsonInclude.Include.ALWAYS)
public LocalDate getTargetDate() {
return targetDate;
}
@JsonProperty(JSON_PROPERTY_TARGET_DATE)
@JsonInclude(value = JsonInclude.Include.ALWAYS)
public void setTargetDate(LocalDate targetDate) {
this.targetDate = targetDate;
}
Run Code Online (Sandbox Code Playgroud)
我希望该字段能够序列化为完整日期,例如规范所承诺的“2023-01-01”:https: //spec.openapis.org/oas/v3.0.0#data-types。然而它实际上被序列化为一个数组:[2023,1,1]。
同样的另一个属性
otherDate:
type: string
format: date-time
Run Code Online (Sandbox Code Playgroud)
被序列化为自纪元以来的秒数,而不是全时。(我认为这是生成器中的错误)
由于生成了代码,我无法添加任何注释。我怎样才能确保日期正确序列化?
[1] openapi-generator-maven-plugin 6.3.0
java openapi jackson-databind openapi-generator openapi-generator-maven-plugin
我有一个 Spring Boot 应用程序,它从 2 个规范文件生成 2 个 API。我可以swagger-ui通过添加为其中之一生成一个页面
springdoc.swagger-ui.url=/firstAPI.yaml
Run Code Online (Sandbox Code Playgroud)
到application.properties。但是我怎样才能包含第二个 API 呢?
我试过:
springdoc.swagger-ui.urls=/firstAPI.yaml,/secondAPI.yaml
Run Code Online (Sandbox Code Playgroud)
这会创建一个组合http://localhost:8080/v3/api-docs/,但http://localhost:8080/v3/api-docs/尽管可以在顶部栏中的两个规格之间进行选择,但页面显示“无法加载 API 定义”。
我有一个带有 h2 数据库的 Spring Boot 项目。
我有一个实体类,从中生成架构:
@NoArgsConstructor
@Entity
@Table(name = "NAMES")
public class Name {
@Id
@GeneratedValue
public Long id;
@Column(nullable = false)
public String name;
public Name(String name) {
this.name = name;
}
}
Run Code Online (Sandbox Code Playgroud)
我有一个data.sql文件:
insert into names (id, name) values (1, 'Alex');
insert into names (id, name) values (2, 'Bob');
Run Code Online (Sandbox Code Playgroud)
我的 application.properties 是:
spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=password
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.jpa.defer-datasource-initialization=true
spring.jpa.show-sql=true
Run Code Online (Sandbox Code Playgroud)
应用程序启动得很好,我可以通过 localhost:8080/h2-console 确认数据已加载到数据库中。但我无法将新数据保存到表中
//public interface NameRepository extends CrudRepository<Name,Long> {}
@RestController
@Service
public class MyController { …Run Code Online (Sandbox Code Playgroud) 假设我有这段代码:
demo::Integer -> Integer
demo x = x*(x+1)/2
main = do print $ demo 8
Run Code Online (Sandbox Code Playgroud)
显然,结果是整数,因为x或其后继是偶数.
可以理解的是,编译器只关注/并说
[1 of 1] Compiling Main ( debug.hs, debug.o )
debug.hs:2:17:
No instance for (Fractional Integer) arising from a use of `/'
Possible fix: add an instance declaration for (Fractional Integer)
In the expression: x * (x + 1) / 2
In an equation for `demo': demo x = x * (x + 1) / 2
Run Code Online (Sandbox Code Playgroud)
但据我所知Integer,不是其中的一部分Fractional.如何保留签名Integer …
我正在四处玩groupby,以便对itertools有一个更好的感觉,因此我按照数字对元组列表进行了分组,并尝试获取结果组的列表.groupby然而,当我将结果转换为列表时,我得到一个奇怪的结果:除最后一组之外的所有组都是空的.这是为什么?我假设将迭代器转换为列表效率较低但从不改变行为.我猜这些列表是空的,因为遍历了内部迭代器但是何时/何地发生?
import itertools
l=list(zip([1,2,2,3,3,3],['a','b','c','d','e','f']))
#[(1, 'a'), (2, 'b'), (2, 'c'), (3, 'd'), (3, 'e'), (3, 'f')]
grouped_l = list(itertools.groupby(l, key=lambda x:x[0]))
#[(1, <itertools._grouper at ...>), (2, <itertools._grouper at ...>), (3, <itertools._grouper at ...>)]
[list(x[1]) for x in grouped_l]
[[], [], [(3, 'f')]]
grouped_i = itertools.groupby(l, key=lambda x:x[0])
#<itertools.groupby at ...>
[list(x[1]) for x in grouped_i]
[[(1, 'a')], [(2, 'b'), (2, 'c')], [(3, 'd'), (3, 'e'), (3, 'f')]]
Run Code Online (Sandbox Code Playgroud) java ×2
openapi ×2
spring-boot ×2
grouping ×1
haskell ×1
hibernate ×1
iterator ×1
openapi-generator-maven-plugin ×1
python ×1
springdoc ×1
swagger-ui ×1