Is there a way to use Swagger just for validation without using the whole framework? - swagger

Suppose I have an existing Java service implementing a JSON HTTP API, and I want to add a Swagger schema and automatically validate requests and responses against it without retooling the service to use the Swagger framework / code generation. Is there anything providing a Java API that I can tie into and pass info about the requests / responses to validate?
(Just using a JSON schema validator would mean manually implementing a lot of the additional features in Swagger.)

I don't think there's anything ready to do this alone, but you can easily do this by the following:
Grab the SchemaValidator from the Swagger Inflector project. You can use this to validate inbound and outbound payloads
Assign a schema portion to your request/response definitions. That means you'll need to assign a specific section of the JSON schema to your operations
Create a filter for your API to grab the payloads and use the schema
That will let you easily see if the payloads match the expected structure.
Of course, this is all done for you automatically with Inflector but there should be enough of the raw components to help you do this inside your own implementation

Related

Using Parameters of One Request to Dynamically Change the Response of Another

I have been using response templating to give dynamic responses, given that all the request and query parameters are associated with that request itself. However, I wanted to make a POST request with several parameters, and later use those parameters in a stubbed GET method's body response by using response templating. Is this something possible to do in wiremock? Any input is greatly appreciated, thank you!
Storing state between requests is not a default feature of WireMock outside of mocking the behavior through Stateful Behaviour, which is different from being actually stateful.
Without a custom plugin being able to share information between several requests is therefor not possible. In the WireMock documentation there is a section in the documentation on how to create such a plugin yourself. With a little development experience this is certainly doable.
On GitHub there are several plugin that create a storage mechanism to store information
WireMockCsv: store and retrieve information using HSQL Database.
wiremock-redis-extension does something similar using Redis.
An alternative to these approaches is to create mappings/data just before the test starts. For example generating all the responses beforehand and then using Templated BodyFileName tag to retrieve the just-in-time created file. Another way of achieving this result is to use the Admin API to create the mappings themselves directly.

Web Crawler for testing purpose?

I want to test a set of ruby-on-rails applications. Specifically, I want to trigger all possible GET/POST requests available. I am considering using some web crawler-like tool, which could (recursively) send requests to my web server, get responses, and parse the response HTML file to get all possible "href tags", "form submission buttons", etc.
Essentially I want to see the performance of these web applications and get some logs of things like what are the request routes, parameters, database accesses, queries, transactions, etc.
Sending GET requests is relatively easy to handle, I would need to simply parse the HTML response and extract the href attributes of all anchors. However, I don't know how to handle those POST requests; they would require me to fill in all these parameter fields included in the form fields. I am wondering if there exist some tools doing such work. Or some tools I can easily modify (not too much) code to achieve my functionality?
Thanks a lot.

Use of REST with scaffolding actions

I see that Grails 2.3 is using REST for the CRUD actions in scaffolding. While it's a great way to learn how REST works, I am wondering if using REST to communicate inside of a single application stack is very efficient. Doesn't it send the request all the way up to the network layer and back down again instead of going directly from the app server to the database? I am visualizing a "pop fly" as opposed to a "line drive." Am I misunderstanding how this works?
I assume when you say, "using REST for the CRUD actions in scaffolding" you are referring to the basic scaffolding (i.e. generate-all example.Book). The scaffolded controllers are not calling the REST API (https://yourapp/book.json) to retrieve the data, they are still using GORM to access the database, and then using the Respond method to render the data in the appropriate format based on the Request's content-type (XML, JSON, HTML). So,
Typical request-response cycle
Client, typically an HTML page, makes request (GET http://yourapp/books/1)
Grails 'parses' request params (id: 1)
Grails' GORM retrieves data from database and creates object instance
Grails resolves response content type to HTML
Grails "responds" to the request with an HTML response using a view from the views directory
SPA/API call
Client, typically javascript, makes request (GET http://yourapp/books/1.json **)
Grails 'parses' request params (id: 1)
Grails' GORM retrieves data from database and creates object instance
Grails resolves response content type to JSON
Grails "responds" to the request with an JSON response
Client consumes the JSON response and acts accordingly
** content-type can be specified in a number of ways, just used the .json suffix since it is the most transparent. See http://grails.org/doc/2.3.x/guide/single.html#contentNegotiation.
And to answer your question regarding whether it "very efficient". I would argue that it is almost always yes, because your payload tends to be much smaller, since you are only transferring data, not data + formatting (HTML, javascript, css, etc). It also provides a way of separating concerns, allowing the client to focus on state and presentation and the backend to focus on data. Furthermore, it means that you can create multiple clients (mobile, desktop-based, web-based) using the same backend API.

TIBCO - Generate WSDL Dynamically

I have a WebService that is a service dispacher and it has a Body with the type anyType, so that way I have only one webservice and my client only needs to know the schema to put in the Body for the specific service that he is calling.
Now the problem is that everytime I create a new service or modify an existing one, I need to send the new schema for them. I need a way so I can generate the WSDL with the body replaced with the schema of the desired service, so I don't have to resend the schema everytime it changes.
Thanks in advance!
BTW I'm using Tibco Designer, if it matters :P
Create an XSLT that expects the generic WSDL as an input and takes a path to a schema as a parameter. Use the XSLT to generate the WSDL you want for your consumers.

simple WSDL wrapper for HTTP process?

Suppose I have a simple HTTP form that uses POST to pass some parameters
and returns OK or BAD (which I do). A client wants this to be published
as a WSDL description. Looking into WSDL I see an infinite morass of
formalisms, but no practical tools.
Surely there must be a simple way to create a wrapper for a simple form processor?
When you do a POST of the form data, do you use HTML to send the users data? If yes then you have to change both client and server. The idea you encapsulate the form's data in a SOAP envelope and send it over HTTP. So I am not sure what you mean by
a wrapper for a simple form processor

Resources