unable to render JSON/JSONSchema. Invalid member type of object in MSON definition - apiblueprint

I have API documentation and suddenly without any changes it started throwing validation alert unable to render JSON/JSONSchema. Invalid member type of object in MSON definition at Response 200 (application/json) line.
+ Response 200 (application/json)
+ Attributes (Restaurant Full)
I tried to google it but I cannot see what I'm doing wrong. Thanks for help!

Disclaimer: I work for Apiary
The message suggests there is an error in Restaurant Full object definition - one of the members has an invalid type.
This error is related to object type members, primitive types do not yield this. For instance - it would be thrown if you define an object type member with a string sample value like this:
+ Attributes (Restaurant Full):
+ `invalid-member-type`: sample value (object)
If this doesn't resolve your issue, could you post your definition of the Restaurant Full object?

Related

What causes this error , unmarshalling json

I am unit testing a basic controller wherein, in certain scenarios, I return some pre compiled static json from a file.
The problem I am experiencing is that, when I attempt to return this static json inside my response as follows:
//records is my json from a file
return ResponseEntity.ok(new JsonApiEnvelope<>(records));
I get the following error :
java.lang.IllegalArgumentException: Passed in List contains (at least) one element (type: java.util.LinkedHashMap) that is not JsonApi annotated. Expected ALL contents of the list be of type(s) with the #JsonApiType annotation
at com.cradlepoint.jsonapiary.envelopes.JsonApiEnvelope.validateTypeJsonAPIAnnotated(JsonApiEnvelope.java:144)
at com.cradlepoin...
What may be causing this behaviour? The json is valid, it has been through a formatter.
I'm glad to report that I've solved my issue. Now, the controller that returns the static json simply has a return type of String and produces 'application/json'. That error occurs, in this case, because I was attempting to marshall my static json into a list of objects then send that list, unmarshalled, as json. Crazy, in hindsight

generic return type for restemplate.exchange

I am using resttemplate.exchange to invoke a URL and get response. But the issue is the response type varies when I successfully receives the output and if I get some error.
eg.
ResponseEntity<XXX[]> response = restTemplate.exchange(endPoint,HttpMethod.GET,req,
new ParameterizedTypeReference<XXX[]>() {},uriVariables);
If there is no issue with service and then output is in format of list. but if there is error like "NO DATA FOUND" then the response is in MAP. so whenever I have any issue with URL i get "404: null error" because my response type is unable to identify the error which is in MAP.
Could you please suggest what could be done as i can not change the response type of services.
Edit:: http://localhost:9090/data/getDetail?name=XXX
response [{"name":"XXX","Dept":"teaching","createdby":"YYY","createdDt":"06/09/2018"}]
when data not found case::http://localhost:9090/data/getDetail?name=YYY
response
{"response":"DATA NOT FOUND"}

Referencing a property inside a defined data structure in API Blueprint/MSON

I've been working with the API Blueprint format for designing an API and have had a lot of fun working with it. When I was declaring my data structures I came upon a code reuse or model reuse issue.
According to the documentation when declaring a Response it has to be done like this:
For example:
+ Request 200 (application/json)
However when multiple people work on the document I don't want to instruct them what return code to use since we have them defined and they're numbers so people forget them. So to avoid having to go back and forth, instead I made this with the idea that I can use/reference one of the properties:
# Data Structures
## HttpCode (object)
+ success: 200 - Request processed successfully
+ not_found: 404 - Content requested not found
+ forbidden: 403 - Access to content is forbidden
I would reference it as such:
+ Response (HttpCode.success) (application/json)
...
It obviously does not work and I cannot find anything that pertains to what I want to do in the docs. Maybe i've missed it.
So how do you do it? Is it possible?
Thanks!
This is not possible. Their representative in GitHub closed my issue.
https://github.com/apiaryio/api-blueprint/issues/411

HTTP - Status Code

I'm using Spring Boot and controllers I'm feeling difficulty to treat some errors, for this reason I have some questions about the most appropriate status for each of the following situation:
PUT Object no Id
Put the URL localhost:8080/users/1 with a JSON without the Id attribute.
PUT Object with different parameter Id
Put the URL localhost:8080/users/1 with a JSON with Id 2, ie, different from what was passed in the parameter.
GET with invalid parameter
GET on the URL localhost:8080/users/search?sex=ABC, or an invalid sex for the system (the correct would be sex = male or female?).
JSON POST with id
Performing a POST in order to persist the data (create) but with id.
Case 1. Id is in the uri : no error
Case 3. "400 Bad request" is acceptable. (client should not retry the exact same request)
Cases 2. and 4. Just ignore the Id from the body and return 200 or return a "400 Bad Request"
Note that the id shouldn't be seen as an attribute of the resource: it is a part of the resource identifier.

Web API ignores non-model body parameters; should throw error

In Web API v2 when you supply data in the POST body that are not part of the model, they are ignored by the framework. This is fine in most cases, but I need to check this and return an error response, so the user doesn't get unexpected results (he expects these wrong parameters to do something...).
So how do I check for this? The model will be null, but when the framework has parsed the data and returned a null-model, I can no longer access the body through Request.Content. So what options are there?
One way is to derive your DTO class from DynamicObject. Check out my blog post: http://lbadri.wordpress.com/2014/01/28/detecting-extra-fields-in-asp-net-web-api-request/

Resources