在IntelliJ中,当我尝试从构建菜单进行构建时,我收到此奇怪的错误消息:错误:java:不支持版本10
我不明白这一点,因为在项目结构中设置了以下设置:项目SDK:9.0项目语言级别:SDK默认模块语言级别:项目默认(两个模块)
在我的pom.xml文件中,两个模块中都设置了这些属性:
<maven.compiler.source>9</maven.compiler.source>
<maven.compiler.target>9</maven.compiler.target>
Run Code Online (Sandbox Code Playgroud)
我不知道为什么要尝试将JDK 10用于任何东西,但我仍然收到该消息。我很高兴使用JDK10,但是我的项目在该版本中不起作用,所以我回头看看它可以在哪个版本中使用。我安装了适用于1.4到10版本的SDK,我也尝试过使用JDK 1.8,但收到的错误消息略有不同:错误:java:目标发行版无效:10我发现可以使用JDK 9从命令行进行构建,但是我需要从IDE中进行构建。谁能告诉我如何使用JDK 1.9或1.8构建项目?谢谢。
我有一个简单的 Kotlin 界面:
@FunctionalInterface
interface ServiceMethod<T> {
fun doService(): T
}
Run Code Online (Sandbox Code Playgroud)
尽管名称如此,但这本质上与 Java 的供应商功能接口相同。唯一的区别是我可以实现Supplier,而不能实现自己的。
val supplier = Supplier<String> {
"Hello"
}
val serviceMethod = ServiceMethod<String> {
"Hello"
}
Run Code Online (Sandbox Code Playgroud)
ServiceMethod 实现给了我一个编译器错误,提示“接口 ServiceMethod 没有构造函数”。嗯?当然不是!这是一个功能界面。
我知道我可以把它写成一个匿名内部类:
val serviceMethod = object : ServiceMethod<String> {
override fun doService(): String {
return "Hello"
}
}
Run Code Online (Sandbox Code Playgroud)
但这要冗长得多。在这种情况下,我可以只使用供应商接口,但这不适用于其他接口。我不应该用 Java 编写接口,只是为了能够在 Kotlin 中使用 lambda。我宁愿为我所有的 Kotlin 接口使用 lambda,尤其是因为我将编写很多这样的接口。我错过了一些明显的东西吗?
我正在尝试运行 OpenAPI 生成器,但我不断收到一条没有意义的错误消息。
Failed to execute goal org.openapitools:openapi-generator-maven-plugin:5.0.0-SNAPSHOT:generate (default-cli) on project miguelmunoz.challenge: The parameters 'inputSpec' for goal org.openapitools:openapi-generator-maven-plugin:5.0.0-SNAPSHOT:generate are missing or invalid
问题是我的inputSpec
值指向有效的 .yaml 文件。该文件位于src/main/resources/yaml/pizzeria.yaml
,我使用复制和粘贴来确保该路径中没有拼写错误。您可以在https://github.com/SwingGuy1024/OpenAPI_inputSpec_Bug下载最小可重现测试用例。
这是我的插件规范:
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<!-- RELEASE_VERSION -->
<version>5.0.0-SNAPSHOT</version>
<!-- /RELEASE_VERSION -->
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<!-- General Configuration properties taken from -->
<!-- https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator-maven-plugin/README.md -->
<!--Changed to https://github.com/OpenAPITools/openapi-generator/tree/master/modules/openapi-generator-maven-plugin-->
<!-- Modifications from /sf/ask/4501283461/#64363872 -->
<ignoreFileOverride>${project.basedir}/my-springboot.ignores</ignoreFileOverride> <!--Added-->
<inputSpec>${project.basedir}/src/main/resources/yaml/pizzeria.yaml</inputSpec>
<!--the language tag was replaced by the generatorName tag:-->
<generatorName>spring</generatorName>
<!--<templateDirectory>${project.basedir}/src/gen/templates/</templateDirectory>--> …
Run Code Online (Sandbox Code Playgroud) Swagger 为 Spring 服务器生成的代码有一个名为 useBeanValidation 的选项,但我不知道如何使用它。我找不到任何文档告诉我它支持哪些验证,所以我决定自己尝试一下。OpenAPI 规范对架构对象属性的描述列出了这些属性:
title
multipleOf
maximum
exclusiveMaximum
minimum
exclusiveMinimum
maxLength
minLength
pattern
maxItems
minItems
uniqueItems
maxProperties
minProperties
required
enum
Run Code Online (Sandbox Code Playgroud)
所以我尝试将其中一些属性添加到我创建的对象的字段中。这是我的 .yaml 文件的相关部分:
components:
schemas:
Dummy:
type: object
properties:
iMinMax:
type: integer
format: int32
minimum: 0
maximum: 100
dMinMaxEx:
type: number
format: int32
minimum: 5.0
maximum: 10.0
exclusiveMinimum: false
exclusiveMaximum: true
dMinExMaxEx:
type: number
format: int32
minimum: 5.0
maximum: 10.0
exclusiveMinimum: true
exclusiveMaximum: true
dMinExMax:
type: number
format: int32
minimum: 5.0
maximum: 10.0
exclusiveMinimum: true
exclusiveMaximum: false …
Run Code Online (Sandbox Code Playgroud) 我正在编写一个带有 GET 的服务,它可以返回五种不同但密切相关的类型之一。由于用户想要同时搜索所有五种类型的选项,因此它必须是单个 get 调用。我返回 JSON,它可以轻松处理任何类型。
我正在尝试在 Swagger 中使用它们的多态性功能来做到这一点,这是我以前从未尝试过的。我所做的就像在示例中一样,除了在“定义”而不是“组件/模式”下。但我收到一条我无法理解的奇怪错误消息。swagger 文件如下。错误是这样说的:
定义 ['Event'] 处的架构错误。discriminator 应该是字符串
它在第 49 行给出了这个,上面写着discriminator:
所以,我的两个问题是:我该如何解决它?这还能满足我的需要吗?
swagger: '2.0'
info:
description: RESTful API to retrieve Titles Metadata
version: 1.0.0
title: Swagger Mystery
schemes:
- https
paths:
/event:
get:
operationId: getEvent
summary: searches names
description: |
Search by names, across all types, or by a specific type.
produces:
- application/json
parameters:
- in: query
name: title
description: name to search for
required: true
type: string
- in: query
name: …
Run Code Online (Sandbox Code Playgroud)