I'm currently using Swagger node.js and I am able to get a response through swagger with the mock option enabled (swagger project start -m)
However, when I hit the API, the mock response is very primitive.
"description": "Sample text",
"disabled": true,
So for string properties, I get back "Sample Text" and for Boolean, I get back True.
Is there any way to control these values? Maybe force swagger to refer to the example property?
I looked online, but couldn't find any way to achieve this.
swagger-node-express does not use the example values specified in the API definition. To customize mock responses, you'll need to create custom mock controllers.
From the documentation:
By default, mock mode returns programmed responses, like "Sample text" for a string, a number for an integer, and so on.
But you can also create mock controllers with handler methods that return custom responses.
Place these custom "mock" controllers in the /api/mock directory.
But there are other OpenAPI/Swagger mock servers that support example values.
Related
I know that with openapi 3 I can use oneOf/anyOf but currently we can't upgrade to openapi 3. In one of definitions I need to use many response types which doesn't have common attributes (basically response is interface without any method/attribute and has multiple different implementations). Can I somehow define multiple response types with openapi 2? Is it possible to use for example headers/content-types/... to distinguish between this reponse types and have valid openapi2 definition?
thanks
Update:
Turns out there can be multiple responses as long as they have different HTTP status code as a "key". default keyword is just that, user of API is supposed to expect that if HTTP status is not on the list of responses default should be used. (e.g. if somebody uses switch to handle responses default maps to default case in switch).
As for single HTTP status code signaling multiple possible types of response, that's not supported explicitly. One ugly workaround would be to create type that contain all the fields, and it would be up to a client to discriminate based on which fields hold values.
for our scopes we need to use unique ID generated by us for the answers submitted by users. This is possible by adding "?c=" at the end of the survey link followed by the ID number.
Example Format: http://www.surveymonkey.com/s/XXXXX?c=00001
The terrific problem is that the custom value is not returned anyway via API. It is not added as a property of the Answer object neither its value replaces somehow the respondant_id property.
We see that you are able to expose that data from your internal endpoints that you use for your proprietary web interface but how to get this data from he outside via API?
Thanks
When you call 'get_respondent_list', ensure you pass through 'custom_id' in the list of strings in the 'fields' parameter. This will then be returned in the output with the custom value you entered.
It seems that there is no around interceptor for the filter in grails.We have the same in case of Spring.If we want to implement it as per grails format what will be the best way to do it.
You could mimic that somewhat. In the before closure you can check the request, session, etc. and determine whether to proceed with the regular call. If you want you can redirect, or render a response in the filter, and return false to indicate that the controller shouldn't be called.
If you want to allow the controller to proceed, you can then do work in the after closure. You can store information in request scope in the before closure (e.g. request.currentRequestNumber = counter.incrementAndGet()) and retrieve it in the after closure (e.g. int currentRequestNumber = request.currentRequestNumber) taking advantage of using property access to store and retrieve request attributes.
You cannot however "call" the controller and inspect its result, and choose whether to send that response, or modify it, or send a different response. You could probably do that with a response wrapper though, where you have a custom writer that captures the rendered response.
Note that you have more flexibility (but less Grails/Groovy help) with a regular servlet filter, i.e. a class that implements javax.servlet.Filter and is registered in web.xml.
I am writing some webservices using spring. I wanna know what's the argument to the service methods: domain objects or request parameters? for example a "User" object or a bunch of strings containing name, e-mail, etc.
Depending on your configuration (and the method signature) you will receive unmarshalled objects (Jaxb for instance), the MessageContext and so on.
Take a look in the documentation, you'll find some examples and everything you need to know about the service methods and parameters.
I'm getting up to speed with the WCF Web API. I want to expose an endpoint that can accept notes, via the POST method. My issue is, I want to support multiple representations for notes. For example, I might want to accept a note using a custom XML serialization that we're using elsewhere, or as an atom:entry element. I already have formatters that can deserialize these into a Note class (our own custom class) or as a SyndicationItem.
The question comes though, how do I define the method? I've currently got this:
[WebInvoke(UriTemplate = GetNotesUriRoot,Method="POST")]
public HttpResponseMessage PostNote(ObjectContent item,HttpRequestMessage request)
Which fails when starting up:
The service operation 'PostNote' will never receive a value for the input parameter 'item' of type 'ObjectContent'. Ensure that a request HttpOperationHandler has an output parameter with a type assignable to 'ObjectContent'.
I initially tried having two separate methods (with appropriately typed parameters), but they can't share the same endpoint name. The current effort (using ObjectContent) was based on other posts I could find that suggested that it could be a parameter. There is no common base type or interface between Note and SyndicationItem
We're using v0.6.0 of the WCF Web API
You need to have a parameter / return type of type Note and your formatters will (de-)serialize it to / from the required representation.
[WebInvoke(UriTemplate = GetNotesUriRoot,Method="POST")]
public HttpResponseMessage PostNote(Note note)
then in your request the content-type header will determine how the object is deserialised. You don't need to worry about deciding how to deserialise, the decision is made for you, as long as the relevant formatter exists (I've not delved in to formatters yet as json/xml have been enough for me so far)