I'm importing a swagger specification file into postman to create a collection, at this point, works as expected and the collection is generated with all requests & sub-folders, fine!!. But when the api is updated, I need update the postman to update all requests based on the new specification. I can't find a action like "update" or something else. I'm trying import the new specification into postman and he say:
A collection APIName already exists.
What would you like to do?
Replace or Import as copy
a copy its a not feasible option, then I use replace and the existent collection is updated, but all tests, parameters, pre-req scripts are remove and I need reconfigure all again.
I'm missing something, exist a way to import & update a existent collection from a specification file, without losing existent tests & configuration?
thanks in advance!
Postman does not support this as of now. Link
Alternative I learned from this blog. In short:
Update your OpenAPI YAML/JSON files.
Import to Postman as a new collection.
Export the new collection from Postman. As JSON in Collection v2.1 format (recommended).
Using Postman API (Update Collection), update the existing collection with the JSON in step 3 as body. Make sure to update collection_uid accordingly.
Postman update collection API body sample:
{
"collection":
<------- YOUR EXPORTED COLLECTION HERE --------->
}
I have made a small tool to do this: swagger2postman: convert swagger to postman collection and update exist collection
The tool will combine new and old collection, when conflict, it will use saved in postman. The tool can detect update in query parameter, but not post body. It will keep all your collection and test cases.
There is no straightforward solution. There also probably won't be one for quite some time - the devs said it is hard to correlate old Postman requests in a collection with new requests generated from incoming Swagger file (or any other source of updates, for that matter).
You can do it outside of Postman, though. Postman collections are really just JSON data and can be manipulated as such.
Transform your Swagger file to a Postman collection file. (You can just import it and export it again, or use tools like Swagger2Postman if you want to automate. Save it as collection 2.0 or newer, that format makes step 3 a lot easier.)
Export your old collection in the same version
Merge the two JSONs in your preferred scripting language
Import the merged JSON back to Postman
I made myself a simple helper for step 3. It is fine if you are just adding more stuff to the collection (my case), but can't remove anything. If anyone has a more versatile solution, please, post it - I would gladly use it instead.
function execute() {
collection = JSON.parse($(".collection").val());
swagger = JSON.parse($(".swagger").val());
result = JSON.stringify($.extend(true, {}, swagger, collection));
$(".result").val(result);
}
<html><body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<br>Collection: <br> <textarea class="collection"></textarea>
<br>Swagger: <br> <textarea class="swagger"></textarea>
<br>Result: <br> <textarea class="result"></textarea>
<br>
<button onClick="execute()">EXECUTE</button>
</body></html>
It seems that they have implemented this feature,
https://github.com/postmanlabs/postman-app-support/issues/6722#issuecomment-652929581
https://learning.postman.com/docs/designing-and-developing-your-api/validating-elements-against-schema/
You can paste your new schema in the API define tab and update it.
Related
Because I am rewriting a legacy app, I cannot change what the clients either send or accept. I have to accept and return JSON, HTML, and an in-house XML-like serialization.
They do, fortunately set headers that describe what they are sending and what they accept.
So right now, what I do is have a decoder module and an encoder module with methods that are basically if/elif/else chains. When a route is ready to process/return something, I call the decoder/encoder module with the python object and the header field, which returns the formatted object as a string and the route processes the result or returns Response().
I am wondering if there is a more Quart native way of doing this.
I'm also trying to figure out how to make this work with Quart-Schema. I see from the docs that one can do app.json_encoder = <class> and I suppose I could sub in a different processor there, but it seems application global, there's no way to set it based on what the client sends. Optimally, it would be great if I could just pass the results of a dynamically chosen parser to Quart-Schema and let it do it's thing on python objects.
Thoughts and suggestions welcome. Thanks!
You can write your own decorator like the quart-schema #validation_headers(). Inside the decorator, check the header for the Content-Type, parse it, and pass the parsed object to the func(...).
I set up a basic JHipster project and generated an entity that supports filtering with JDL.
The generator made a Swagger API which I use for querying the database.
The Swagger API doc shows me a list of parameters which can be used to build query.
The template query looks like this:
GET /api/client?name.equals=john&surname.equals=doe&country.in=uk&country.in=de
The request works fine but the parameters are chained like name==john OR surname==doe OR country==uk OR country==de so I get all johns, does, and everoyne from uk and de.
This is ok, but for some queries i need name==john AND surname==doe so not all Johns and Does but specifically John Doe. I searched here and on the swagger forum but couldn't find the answer.
My question is: how do I achieve changing the OR to AND in the query?
Does this swagger query support AND or do I have to make changes in the backend?
Your question is not about swagger, this is why you could not find anything in swagger forum.
It's about JHipster JPA entity filtering and the answer is no: you can't generate code that would use a OR.
You must code it yourself, look at the *QueryService classes and assemble your criteria with the logic you need.
I am trying to update a JSON file from my iOS app in Swift. I do not want to write a separate JQuery script, since I do not have enough knowledge nor the time to do so. The JSON file is hosted at the myjson api at api.myjson.com Here they explain how to use the api: http://myjson.com/api
I understand that each method such as 'PUT' or 'POST' is appended to the end of the website, like api.myjson.com/example?type=PUT.
What I am trying to figure out is the syntax to add to or update my JSON files stored here.
The url in .ajax() calls follows the exact same rules as an href or src in plain html would:
e.g you're on http://example.com/dir/subdir/somescript.php:
$.ajax('foo.php'); -> http://example.com/dir/subdir/foo.php
$.ajax('/foo.php); -> http://example.com/foo.php
$.ajax('../foo.php'); -> http://example.com/dir/foo.php
The method used is generally GET, but you can specify whatever method you want in the options:
$.ajax(url, {method:"POST"});
I know this question is been discussed many times but for me those solutions are not working. I want to return JSON data from my ASP.NET web API. I am hitting the end point using Firefox REST client plugin.
What I have tried:
I have specific accept header : Accept: application/json. Use accept header
Removed the XML formatter on Application_Start method
var formatters = GlobalConfiguration.Configuration.Formatters;
formatters.Remove(formatters.XmlFormatter);
This is how I return data at the end
return myModel.OrderBy(d => d.SortOrder);
Where myModel is just a class with few public property. I am not decorating this class or its property with any attribute.
But these two approach's are not working. I am still getting data in XML format :(
Please provide your suggestions.
I would like to introduce you to http://www.servicestack.net/
This is rest API framework that hooks up with .net.
It does everything what you require .
https://docs.google.com/presentation/d/16ey0MrpHOSz5N5sjctAliOgYWO3ZYeJe070fLZlPdrE/present#slide=id.i27
FROM COMMENT
Check that the application/json header is the first header and has a q=1 quality attribute: "application/json;q=1".
You can read more about quality attributes in the specs. Basically they are a way for a client of providing a preference system on the returned datatype.
To answer your other question (when I have explicitly removed the XML format in the code, why I was getting the data in XML format?), I can only guess what was going on: either the header was not setup correctly or the client was defaulting the other header to a different quality value.
Another guess could be that your way of removing the formatter is wrong: you can check this answer on SO or this article for alternative methods and see if they do the trick for you as well.
I'm writing a restful XML API for a university assignment, the spec requires no HTML frontend.
There doesn't seem to be any documentation (or guessable functionality) regarding how to change the default format? Whilst thus far I have created all templates as ...Success.xml.php it would be easier to just use the regular ones and set this globally; I really expected this functionality to be configurable from YAML.. yet I have found some hard coded references to the HTML format.
The main issue I'm encountering is that part of the assessment is returning a 404 in a certain way (not as a 404 :/), but importantly it must always return XML, and the default setup of a missing route is a HTML 404 not XML (so it only works when I use forward404 from an action running via a XML route.
So in summary, is there a way to do this / what class(es) do I have to override?
Try putting this in factories.yml
all:
request:
class: sfWebRequest
param:
default_format: xml
That will still need the template names changing though. It will just mean that urls that don't specify a format will revert to xml instead of html.
You can subclass sfPHPView and override the initialise method to affect this (copy paste the initialise method from sfView) - the lines like this need changing:
if ('html' != $format)
You then need to change the view class used ... try this:
http://mirmodynamics.com/post/2009/02/23/symfony%3A-use-your-own-View-class