JSON response validation against JSON schema using groovy script - validation

I have a rest service which returns a json response. I need to validate response against my predefined json schema using groovy script. All the options I have found on the net describe validating json response using groovy.json.JsonSlurper against some pre conditions not the schema. So I am kinda confused where to start from. But I roughly know that I need the following steps get done.
Define custom json schema
Importing some json validator library
And validate response against schema in groovy
I'd be highly grateful if anybody helps out on the steps 2 and 3.
For your notice, I am using Soap ui tool and here is my custom schema:
{
"$schema": "http://json-schema.org/schema#",
"type":"array",
"items":{
"type": "string"
}
}

Loading libraries in Groovy depends on the tool. In SoapUI-5.6.0 the standard way is to put jar files in (from SoapUI base installation path):
On Mac: bin/ext
On Linux & Windows: lib
Validation differs depending on the library. For example with groovy-json-schema:
def json = new JsonSlurper().parseText('{"an": "example"}')
use(JsonSchema) {
json.schema = 'file://path/to/your/json/schema.json'
json.conformsSchema()
}

Related

Export / finding GraphQL Schema with Strapi and GraphQL plugin

I’m new to Strapi and to GraphQL.
I successfully created a website that uses Apollo to query data from my Strapi website.
So functionally I have everything I need.
For my DX I’m wondering:
Since I installed the GraphQL IntelliJ plugin: Where do I find the schemas for it? I read something about remote schema detection - is that supported with Strapi GraphQL Plugin? Where can I read about it? Otherwise how can I export GraphQL schema files from Strapi?
If I got 1) to work: Will TypeScript types work out of the box? Would I use one of the GraphQL schema to TS converters out there? It feels like there might be something working automatically, but I can’t tell till I get 1) to work.
First, you asked two separate questions and should therefore separate then in two separate threads.
To answer your first question: Here is how you can utilise the GraphQL IntelliJ plugin:
You need to create a .graphlconfig file. In Webstorm select your project folder and go to 'File' -> 'New' -> 'GraphQl Configuration File'.
Change the endpoint url to your strapi endpoint.
Visit the GraphQl Tool Window, double click your endpoint and select 'Get GraphQl Schema from Endpoint (introspection)'. This will retrieve the schema file from strapi and save it to schema.graphql.
Now you can run queries against your endpoint, e.g. create a new Scratch File scratch.graphql and run queries against your endpoint or try to figure out how to solve your second question ;)
Thank you for the answer! This was helpful!
Further to this, one query - typically, is .graphlconfig committed to git repo and scratch.graphql ignored from the git repo?
In addition for others looking for a similar solution - you could use values from .env. using the format below:
{
"name": "Strapi GraphQL Schema",
"schemaPath": "schema.graphql",
"extensions": {
"endpoints": {
"Default GraphQL Endpoint": {
"url": "${env:GRAPHQL_HOST}/graphql",
"headers": {
"Authorization": "Bearer ${env:GRAPHQL_TOKEN}",
"user-agent": "JS GraphQL"
},
"introspect": false
}
}
}
}

How to test graphql + apollo server for upload file mutation using postman?

I using apollo server, and have this mutation :
mutation {
updateData(
file1: fileOne,
file2: fileTwo,
file3: fileThree,
payload: {
id: "7e3583b4-5673-48df-a3cf-44a4ec33f0e1"
}
){
isSuccess
error
data
}
}
I want to test it using postman, because i didnt find any clue test it using graphql playground.
I already find how to test graphql from postman, but it doesn't contains information about file upload. graphql postman
I have an idea from apollo-upload-client to post using multipart-formdata but it still fail.
please help how to test graphql with apollo server for upload file mutation using postman?
thanks
I need to understand about how file upload works in node js (because I use nodejs ini this case)
I install multer for file upload middleware using nodejs and expressjs, if you use other framework or programming language, just try adjust it
In postman I use formdata
you can find the good step by step here
Upload file graphql using postman

Unsure how to retrieve data from a custom endpoint?

Context to this post is I'm a java developer attempting to teach myself Ember. It isn't going well. I realize this question is pretty vague so I apologize, I'm not even sure what I should be asking...
I need to pull data into a model, i.e. via some sort of query, from a heroku json endpoint. In the application.js file, I have the following:
import DS from ‘ember-data’;
export default DS.JSONAPIAdapter.extend({
host: 'https://cag-brain.herokuapp.com'
});
Ideally I would like to pull this data into a user model, then display that data on a page as a sort of proof of concept. This unfortunately gets me nothing. Nor am I even sure I'm going about this correctly. Should I be doing something different than attempting to use Host Customization? Any guidance would be much appreciated!
There are different things involved for retrieving records via ember-data.
First of all you should define your models:
// app/models/post.js
import DS from 'ember-data';
export default DS.Model.extend({
title: DS.attr('string')
});
You should retrieve records in a model hook of a route.
// app\routes\posts.js
import Route from '#ember/routing/route';
export default Route.extend({
model() {
return this.get('store').findAll('post');
}
});
Then you should configure your api host and maybe a namespace. You included that step in your question:
// app/adapters/application.js
import DS from ‘ember-data’;
export default DS.JSONAPIAdapter.extend({
host: 'https://cag-brain.herokuapp.com'
});
If your api does not implement JSON Api specification you need to customize your serializer and adapter. Ember-data ships with a RESTAdapter/RestSerializer additionally to the default adapter and serializer which implements JSON Api spec. There is also one abstract adapter and serializer If you need to start from scratch. Before that I would definitely have a look if there is any community adapter/serializer fitting your needs.
To decouple api and client development and to speed up tests I would recommend ember-cli-mirage which allows you to mock your api.

How to send custom form data to FineUploader Azure Success endpoint?

I am using FineUploader 5.13.0 with the Azure Blob Storage end point.
I have it successfully uploading files directly to blob storage, and also successfully hitting my web server success endpoint when the upload is concluded.
However, I am looking for a way to include custom data in the post to the success endpoint.
This bit in the documentation seems to imply that it is possible.
Under the section "Optional server-side tasks" for "uploadSuccess.endpoint", it says it will send
"Any parameters/form fields you have associated with the file".
However, I just cannot seem to figure out how to do that.
This issue seems to refer to it, but doesn't give enough info.
https://github.com/FineUploader/fine-uploader/issues/1313
Note, I am not referring to the feature to hook into existing HTML forms as explained on this documentation page:
"Integrating with Existing HTML Forms"
https://docs.fineuploader.com/branch/master/features/forms.html
You might be looking for FineUploader's Request params. This allows you to add extra form data.
Eg:
new qq.FineUploader({
// elided
request: {
params: {
testing: "THIS IS A TEST"
}
}
});
This will show up in the multi-part body of the request:

How to add for format=json in oracle weblogic server

I have installed oracle weblogic server 11g.Implemented RESTFul but as per document when I place there format=json. It should works but it is not working.
Can you please let me know, how to resolve response as json.
you can get a working example of how to do this here: https://www.samplecode.oracle.com/sf/projects/oracle-parcel-svc/ and we have a webcast series that covers JAX-RS on WLS in Session 4 at this link:http://www.oracle.com/technetwork/middleware/weblogic/learnmore/weblogic-javaee6-webcasts-358613.html
When you configure your method that you want to return JSON from you have to specify that it produces JSON. Here's one way to do it:
#GET
#Path("{id}.json")
#Consumes({MediaType.APPLICATION_JSON})
#Produces({MediaType.APPLICATION_JSON})
public Parcel getParcelById_json(#PathParam("id") int id)
{
return getParcelById(id);
}
You also need to put the right HTTP headers in the client in order to specify that it expects a JSON response. Some test clients like SOAP-UI auto-convert JSON to XML such that you can do an XPATH on it, even though the actual transmission of data is JSON.

Resources