-
Notifications
You must be signed in to change notification settings - Fork 9.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposed format: jsonObject and jsonArray to type: string #552
Comments
I'm closing this issue, |
I'm re-opening this issue, because I think this would be a great proposal for the 2.0 specification. |
So you are wrapping JSON data into a string, and put this into some JSON data structure? This sounds somehow wrong. Why not include the JSON data directly in your data structure? (Also, you can use any format string as you want, just the ones in the spec have predefined meaning.) |
The problem I encountered was with a common third party middleware that JSON.stringified the response before sending as the http body. Therefore I could only validate that the output was a string, and not the contents of the string. If there was a method to define that a string contained a json object or json array, then I could validate the contents of that string contained a json object or json array, and the proceed to validate those objects or arrays within the string. I want to be able to validate the output of a middleware without having to change the middleware just to validate it. See the swagger tools error above. |
Tackling PR: #741 |
This is covered in 3.0 now in a different way. You can specify that any parameter is serialized as |
@webron I think that @deefactorial didn't want to use JSON for parameters (or response headers), but to have string-typed fields in a normal JSON response (or request) body (i.e. properties in a schema) containing a serialized JSON object or array, and to describe what is in there. I guess this could solved the same way, if a As an example derived from the OP's example: definitions:
foo:
type: object
properties:
token:
$ref: '#/definitions/token_response'
token_response:
type: string
content:
'application/json':
schema:
type: object
minProperties: 2
maxProperties: 5
required:
- access_token
- expires
properties:
access_token:
type: string
expires:
type: string And an object fitting {
"token": "{\"access_token\":\"abcd\", \"expires\":\"tomorrow\"}"
} |
That's not my understanding from the post, but if @deefactorial wants to clarify, then by all means. If it's what you think, then agreed, we shouldn't support it. |
Yes, ePaul was correct. I wanted to be able to validate the contents of a string that contains JSON. It all stems from this issue: In which a middleware project stringified the output before being sent. Therefore I didn't have the the tools to be able to verify the output of the stringified response without modifying the middleware package. |
So is this solved or not? I have exactly the same problem as @deefactorial. @ePaul's example looks like a good proposal, but as far as I understand it was just to show how it could look like, not how it actually works, right? |
Yes, it's solved. You can use the "content*" keywords in the json schema in an openapi 3.1 document, if your evaluator supports those keywords. https://json-schema.org/draft/2020-12/json-schema-validation.html#name-a-vocabulary-for-the-conten |
Oh that's nice :) |
Here is the problem:
I'm lacking the tools to fully validate the response of an API end point of 3rd party middleware. The middleware is passportJS and the response is JSON.stringified before being sent. The only way I've found to validate the response is to say that it's a string and perhaps provide a regex to the string. But what I would really like to do is JSON.parse the string and validate the contents of the string.
What is the proper way to define an response to do so ?
Perhaps there is a way to do it with the 2.0 spec. If there isn't a way I would like to propose a format: jsonObject and format: jsonArray added to the type: string
proposed format: jsonObject:
proposed format: jsonArray
The text was updated successfully, but these errors were encountered: