英文:
Unexpected token error using Swagger annotations
问题
以下是翻译好的内容:
我正在使用我从Swagger-core的GitHub上复制的代码来测试Swagger注解。
我正在测试的代码摘录来自这里的静态类SimpleOperations(第446行)。
在我的代码中,它看起来像这样:
(...)
@Controller("/")
class IntegratorWebController {
def convoyWebService
@Operation(
operationId = "subscribe",
description = "subscribes a client to updates relevant to the requestor's account, as identified by the input token. The supplied url will be used as the delivery address for response payloads",
parameters = {
@Parameter(in = ParameterIn.PATH, name = "subscriptionId", required = true,
schema = @Schema(implementation = Convoy.class),
style = ParameterStyle.SIMPLE, example = "example",
examples = {
@ExampleObject(name = "subscriptionId_1", value = "12345",
summary = "Subscription number 12345", externalValue = "Subscription external value 1"),
@ExampleObject(name = "subscriptionId_2", value = "54321",
summary = "Subscription number 54321", externalValue = "Subscription external value 2")
})
},
responses = {
@ApiResponse(
description = "test description",
content = @Content(
mediaType = "*/*",
schema = @Schema(
type = "string",
format = "uuid",
description = "the generated UUID",
accessMode = Schema.AccessMode.READ_ONLY,
example = "Schema example"
),
examples = {
@ExampleObject(name = "Default Response", value = "SubscriptionResponse",
summary = "Subscription Response Example", externalValue = "Subscription Response value 1")
}
))
})
def saveOrUpdateActivity(){
def result = [error:[]]
def status = OK
(...)
唯一的区别是我用我的代码中存在的一个类替换了ExamplesTest.SubscriptionResponse.class。
我正在使用:
- io.swagger.core.v3,swagger-annotations版本2.1.2
- Java 11
- Grails 4.0.2
我遇到了以下问题:
IntegratorWebController.groovy: 28: unexpected token: @ @ line 28, column 2.
@Operation(
^
在IDE中,它看起来是这样的:
(图片已省略)
Javadoc表示@Parameter可以独立地在Operation中使用,也可以在方法级别上使用,以向操作添加参数,即使未绑定到任何方法参数。所以例子是正确的。
有什么问题吗?
谢谢!
英文:
I am testing Swagger annotations using a code I copied from the Swagger-core Github.
The code excerpt I am testing comes from the static class SimpleOperations from here (line 446)
In my code, it looks like this:
(...)
@Controller("/")
class IntegratorWebController {
def convoyWebService
@Operation(
operationId = "subscribe",
description = "subscribes a client to updates relevant to the requestor's account, as identified by the input token. The supplied url will be used as the delivery address for response payloads",
parameters = {
@Parameter(in = ParameterIn.PATH, name = "subscriptionId", required = true,
schema = @Schema(implementation = Convoy.class),
style = ParameterStyle.SIMPLE, example = "example",
examples = {
@ExampleObject(name = "subscriptionId_1", value = "12345",
summary = "Subscription number 12345", externalValue = "Subscription external value 1"),
@ExampleObject(name = "subscriptionId_2", value = "54321",
summary = "Subscription number 54321", externalValue = "Subscription external value 2")
})
},
responses = {
@ApiResponse(
description = "test description",
content = @Content(
mediaType = "*/*",
schema = @Schema(
type = "string",
format = "uuid",
description = "the generated UUID",
accessMode = Schema.AccessMode.READ_ONLY,
example = "Schema example"
),
examples = {
@ExampleObject(name = "Default Response", value = "SubscriptionResponse",
summary = "Subscription Response Example", externalValue = "Subscription Response value 1")
}
))
})
def saveOrUpdateActivity(){
def result = [error:[]]
def status = OK
(...)
The only difference is that I replaced ExamplesTest.SubscriptionResponse.class to a class that exists on my code.
I am using
- io.swagger.core.v3, swagger-annotations version 2.1.2
- Java 11
- Grails 4.0.2
I am getting:
IntegratorWebController.groovy: 28: unexpected token: @ @ line 28, column 2.
@Operation(
^
At the IDE it looks like this:
Javadoc says that @Parameter can be used independently in Operation or at method level to add a parameter to the operation, even if not bound to any method parameter. So the example is sound.
What is wrong?
Tks!
答案1
得分: 1
因为我正在使用Groovy进行编码,所以在@Parameters和@ExampleObject的数组部分,我必须使用[]而不是{}。
正确的代码如下:
@Post(uri="/saveOrUpdateActivity", produces = MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@Operation(
operationId = "subscribe",
description = "subscribes a client to updates relevant to the requestor's account, as identified by the input token. The supplied url will be used as the delivery address for response payloads",
parameters = [
@Parameter(in = ParameterIn.PATH, name = "subscriptionId", required = true,
schema = @Schema(implementation = Convoy.class),
style = ParameterStyle.SIMPLE, example = "example",
examples = [
@ExampleObject(name = "subscriptionId_1", value = "12345",
summary = "Subscription number 12345", externalValue = "Subscription external value 1"),
@ExampleObject(name = "subscriptionId_2", value = "54321",
summary = "Subscription number 54321", externalValue = "Subscription external value 2")
])
],
responses = [
@ApiResponse(
description = "test description",
content = @Content(
mediaType = "*/*",
schema = @Schema(
type = "string",
format = "uuid",
description = "the generated UUID",
accessMode = Schema.AccessMode.READ_ONLY,
example = "Schema example"
),
examples = [
@ExampleObject(name = "Default Response", value = "SubscriptionResponse",
summary = "Subscription Response Example", externalValue = "Subscription Response value 1")
]
))
])
英文:
Because I am coding in Groovy, I have to use [] instead of {} for the array of @Parameters and @ExampleObject.
The correct code looks like this:
@Post(uri="/saveOrUpdateActivity", produces = MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@Operation(
operationId = "subscribe",
description = "subscribes a client to updates relevant to the requestor's account, as identified by the input token. The supplied url will be used as the delivery address for response payloads",
parameters = [
@Parameter(in = ParameterIn.PATH, name = "subscriptionId", required = true,
schema = @Schema(implementation = Convoy.class),
style = ParameterStyle.SIMPLE, example = "example",
examples = [
@ExampleObject(name = "subscriptionId_1", value = "12345",
summary = "Subscription number 12345", externalValue = "Subscription external value 1"),
@ExampleObject(name = "subscriptionId_2", value = "54321",
summary = "Subscription number 54321", externalValue = "Subscription external value 2")
])
],
responses = [
@ApiResponse(
description = "test description",
content = @Content(
mediaType = "*/*",
schema = @Schema(
type = "string",
format = "uuid",
description = "the generated UUID",
accessMode = Schema.AccessMode.READ_ONLY,
example = "Schema example"
),
examples = [
@ExampleObject(name = "Default Response", value = "SubscriptionResponse",
summary = "Subscription Response Example", externalValue = "Subscription Response value 1")
]
))
])
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论