-
-
Notifications
You must be signed in to change notification settings - Fork 576
Description
Purpose: some method involve more than one resource. How can I provide a few responses in swagger specification ( for example, for 404 return Resource1NotFound and Resource2NotFound )
I would provide several example of response on error status code, e.g. smth like:
"404":
description: Not Found response.
content:
application/json:
schema:
oneOf:
- $ref: '#/components/schemas/CustomErrorType1'
- $ref: '#/components/schemas/CustomErrorType2'
examples:
resource1NotFound:
summary: Resource1 not found
value:
message: Reiciendis quod omnis tempora.
name: Quo repellendus porro facilis assumenda.
subresource1NotFound:
summary: Subresource1 not found
value:
message: Nam et sit ea ex.
name: Distinctio autem architecto saepe est.
I thought that something like this will give me desired behavior :
var _ = Service("example", func() {
Method("exampleMethod", func() {
Error("CustomError1", CustomErrorType1)
Error("CustomError2", CustomErrorType2)
HTTP(func() {
POST("/example")
Response("CustomError1", StatusNotFound)
Response("CustomError2", StatusNotFound)
})
})
})
var CustomErrorType1 = Type("CustomErrorType1", func() {
Attribute("attr11", String)
Attribute("attr12", String)
Required("attr11", "attr12")
})
var CustomErrorType2 = Type("CustomErrorType2", func() {
Attribute("attr21", String)
Attribute("attr22", String)
Required("attr21", "attr22")
})
But unfortunately it generates:
"404":
description: Not Found response.
schema:
$ref: '#/definitions/CustomErrorType2'
required:
- attr21
- attr22
Can someone give me advice how can I archive my goal?
P.s.
I can’t use the common type for CustomErrorType1 and CustomErrorType2 (because all refactoring will be very expensive). Also, if I’m not mistaken, we can’t define types using the Type() function at the API level and deeper, which is why we can’t create types in place, so I want to avoid defining types for each such situation if possible