Java – how to override object array attribute types in RAML 1.0
•
Java
I have a common Java type, as follows:
class Response<D> {
List<D> data;
}
And want to create something similar to RAML 1.0 (I'm a novice)
My first way is
types:
Response:
type: object
properties:
data: object[]
When using it
body:
type: Response
properties:
data: MyDataType[]
From API workbench, I always get an "illegal override of attribute data inherited from response"
Another idea is to use repetition:
types:
Response:
type: object
properties:
data: object
repeat: true
And separately
body:
type: Response
properties:
data: MyDataType
repeat: true
Now the illegal override has disappeared, but in the API console, I now get an "uncapped typeerror"
How? Or do you need a completely different approach? Any ideas?
Solution
It is understood that response abstracts different types of data, but the format is similar One method is to use resources types to abstract the similarity in the response and define specific data in the type
#%rAML 1.0
title: New API
version: v1
baseUri: http://api.samplehost.com
mediaType: application/json
types:
User:
usage: A user in the system
properties:
firstname:
required: true
lastname:
required: true
ArticleId:
usage: An id of any article in the system
type: number
Article:
usage: Pattern for any article in the system
properties:
id:
type: ArticleId
required: true
created:
type: date
required: true
#######################################
# the following captures the similarity:
#######################################
resourceTypes:
collection:
get:
responses:
200:
body:
properties:
data: <<typename>>[]
###############
# API:
###############
/user:
description: All the users
type:
collection:
typename: User
/article:
description: All the articles
type:
collection:
typename: Article
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码
