A localization yml file *.yml
errors:
template:
body: "Body error message"
header:
one: "1 error "
other: "%{count} errores"
For some reason it throws an error on a page "(/home/alex/RubymineProjects/psg/config/locales/es.yml): did not find expected key while parsing a block mapping at line 248 column 7" which means there is something wrong in it.
If I delete "Body error message" (only the value, not body key) then everything is good, there is no error on a page.
What is wrong? How do I define the key body with a value and its nested values?
Your indentation is wrong: body and header should be at the same depth:
errors:
template:
body: "Body error message"
header:
one: "1 error "
other: "%{count} errores"
Related
I have a schema for a certain status code that i wan to use in multiple responses.
We can have multiple error messages for the same status code and may be distinct on each response.
ErrorCode:
type: object
properties:
error_code:
type: integer
description: error code
message:
type: string
example: No Authorization
description:
type: string
example: "You aren't allowed"
I would like to provide multiple examples for each response.
For example:
examples:
1:
error_code: 1
message: random 1
description: description 1
2:
error_code: 2
message: random msg 2
description: description 2
In the OpenAPI definition below, the parameter definition causes the parser error "bad indentation of a mapping entry". What is wrong?
paths:
/users/{username}:
get:
tags:
- users
summary: "Get the users profile"
parameters:
-in: path
name: username
description: "get user by name"
type: string
required: true
responses:
200:
description: OK
schema:
$ref: "#/definitions/users"
In YAML sequences (lists), whitespace is required after the - indicator. You need to replace
-in: path
with
- in: path
(and align the subsequent keywords appropriately).
I'm using Eve frameworks with it's hooks.
I'm also using on_insert hook for creating data. I've enabled PUT method, because it causes an error for POST.
Sending PUT requests looks like:
requests.put("http://127.0.0.1:7000/users", headers=headers, json={"name": "John", "age": 30})
It raises an error:
('message: ', u'{"_status": "ERR", "_error": {"message": "An exception occurred: can\'t set attribute", "code": 400}}')
('status: ', 400)
I'm really struggling to understand the format of the examples section of a response. I have the following response defined for a 500 Internal Sever error.
500InternalServerError:
description: The server encountered an unexpected condition which prevented it from fulfilling the request
schema:
allOf:
- $ref: '#/definitions/Failure'
headers:
X-Rate-Limit-Limit:
description: The number of allowed requests in the current period
type: integer
X-Rate-Limit-Remaining:
description: The number of remaining requests in the current period
type: integer
X-Rate-Limit-Reset:
description: The number of seconds left in the current period
type: integer
examples:
application/json:
code: -1
message: The server encountered an unexpected condition which prevented it from fulfilling the request
When I load it up in swagger-ui, it looks like this:
How do I get the response to be formatted over multiple lines and look like this?:
{
"code": "-1",
"message": "The server encountered an unexpected condition which prevented it from fulfilling the request"
}
The lack of pretty print in the response-level examples seems to be a bug or missing functionality in Swagger UI 3.0.x. Feel free to submit an issue on GitHub.
The workaround is to use a schema-level example instead:
definitions:
Failure:
type: object
...
example:
code: "-1" # Quotes force the number to be treated as a string
message: The server encountered an unexpected condition which prevented it from fulfilling the request
By the way, you do not need allOf when using $ref alone (without combining it with other items):
schema:
$ref: '#/definitions/Failure'
My JSON that is being returned from my ASP.NET MVC application looks like this:
{code: "1", error: "0", output: "<div class="a1"><div class="b1">this is fasta's</div></div>}
It is not working because I am not escaping it properly.
I'm not using a JSON library, can someone recommend a function that would clean up my HTML so this works?
I tried escaping for \ but it still doesn't work.
If I HTML encode it, should it work fine?
There will be user generated content so this has to work for all potential inputs by the user.
Are you able to use single quotes to wrap your HTML attribute values? I think that should work if you are able to do that.
For example,
{code: "1", error: "0", output: "<div class='a1'><div class='b1'>this is fasta's</div></div>"}
If that doesn't work, try using 2 backslashes to escape the double quotes.
For example,
{code: "1", error: "0", output: "<div class=\\"a1\\"><div class=\\"b1\\">this is fasta's</div></div>"}
You need to escape the internal double quotes, like this:
{code: "1", error: "0", output: "<div class=\"a1\"><div class=\"b1\">this is fasta's</div></div>"}