Closed basickarl closed 7 years ago
Maybe you are searching for array[string]
?
+ Response 401 (application/vnd.api+json)
Something back.
+ Attributes (object)
+ errors (array[string])
You can also add the two sample values, for example:
+ Response 401 (application/vnd.api+json)
+ Attributes (object)
+ errors (array)
+ `My var value here!`
+ `My second var value here!`
I'd like to reopen the issue.
yes, it is possible to specify the "example values" in this way, but the schema is generated without item type:
+ Response 422 (application/json)
+ Attributes
+ `errors` (array, required) - List of Validation Errors
+ `password couldn't be empty` (string)
+ `email must be a valid email` (string)
The Body Example:
{
"errors": [
"password couldn't be empty",
"email must be a valid email"
]
}
The json-schema:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"errors": {
"type": "array",
"description": "List of Validation Errors"
}
},
"required": [
"errors"
]
}
So, the schema must be fixed.
@DScheglov What type of schema are you looking for, could you provide an example please?
Hey, @kylef
The full sample is bellow:
FORMAT: 1A
# User Management
## Sign Up [POST /sign-up]
Creates a new user
+ Request (application/json)
+ Attributes (object)
+ `email`: `example@not-email.server.com` (string, required) - User E-Mail
+ `password`: `SomeRandomPa55word!` (string, required) - User Password
+ Response 200 (application/json)
+ Attributes
+ One Of
+ data (object, fixed-type)
+ `id`: `79d3d4a4-491f-4f07-b971-a4891d6e0208` (string, required) - Id of User Account
+ `email`: `example@not-email.server.com` (string, required) - User E-Mail
+ `token`: `<some-jwt>` (string, required) - Access Token
+ `refreshToken`: `<some-jwt>` (string, required) - Refresh Token
+ error (object, fixed-type)
+ code: `EPASSWORD_TOO_SHORT` (enum, required) - The Error Code
+ `EPASSWORD_TOO_SHORT`
+ `EPASSWORD_TOO_SIMPLE`
+ `EPASSWORD_TOO_WIDELY_USED`
+ `EUSER_IS_ALREADY_REGISTERED`
+ message: `Password is too short` (string, required) - The Error Message
+ Response 400
Bad Request
+ Response 404
Not Found
+ Response 422 (application/json)
+ Attributes
+ `errors` (array[string], required) - List of Validation Errors
+ `password couldn't be empty` (string)
+ `email must be a valid email` (string)
+ Response 500
Internal Error
The screenshot from the Apiary Editor
and what JSON Schema are you looking for? I'm asking for the schema as its not clear what you are trying to achieve.
@kylef oh, my bad ...
The expected schema is:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"errors": {
"type": "array",
"items": {
"type": "string"
},
"description": "List of Validation Errors"
}
},
"required": [
"errors"
]
}
The items
is described here: https://json-schema.org/understanding-json-schema/reference/array.html#items
Oh, actually it seems it is another bug, doesn't related the sampling for string arrays, because the items
is not generated even if samples are not specified.
Sorry for that.
If you use the fixed-type
keyword on the array definition an items fixing the type to string should end up in the schema:
## Errors (object)
+ `errors` (array[string], fixed-type, required) - List of Validation Errors
+ `password couldn't be empty` (string)
+ `email must be a valid email` (string)
The documentation for this part can be found in: https://apiblueprint.org/documentation/mson/cheatsheet.html#arrays
I will note that there will be two differences between the generated schema and your example:
anyOf
. There's an optimisation to remove this in https://github.com/apiaryio/drafter/pull/789 which hasn't yet been deployed to Apiary.@kylef ,
Thank you for fast answer.
But it seems excessive to specify fixed-type
after array[Type]
, or not?
If someone doesn't want to specify the items type they can just omit it and specify just array
.
So, actually it is just an opinion.
Thank you for your answser and for the Project.
I'm embarrassed to ask this, but how does one create a simple string variable?
I'd like to fill the array below with a string:
I'd like the response to look like the following in JSON: