I am looking for a maven plugin that will simply compare a json file with an associated JSON Schema file. Essentially we are getting plagued with invalid configuration files which are only run in a single environment. So testing of the "dev" environment will pass with flying colors though when the application is launched with the "prod" configurations the application will fail to start is the config is say missing a comma or otherwise the JSON doesn't parse.
Looking for a non-intrusive solution to verify that the config files are at least in the expected format before marking the build as successful (say like within a CI environment).
Posting this for completeness. The maven plugin was opensourced by Groupon and can be found here : https://github.com/groupon/json-schema-validator
Lacking a Maven plugin, I would do this with a small Java unit test which runs a schema validator over your example inputs - you could use a Maven filter to choose which file to parse based on your environment. If all configurations are stored in your SCM, you should be able to validate all configurations with one unit test.
If you're looking for a library to use in your unit test, have a look at the JSON schema validator:
<dependency>
<groupId>com.github.fge</groupId>
<artifactId>json-schema-validator</artifactId>
<version>2.0.1</version>
<scope>test</scope>
Another thought - if your configuration needs runtime validation, you should use the above library to validate when it changes. If you make your configuration update process interactive, you could validate as it changes and reject configuration updates which are invalid.
Related
I'm creating an npm package which contains a schema file, set.schema.json. I'm wondering how I can set this as the $schema of a JSON file in another project with this package installed as a dependency. I'm mainly using the schema for IDE suggestions, rather than validation.
JSON Schema does not specify a way to do this.
Any way you want to do this needs to be supported by the IDE in question.
There are probably a lot of tools/libraries to validate JSON schemas.
I have a library and want users of my library to have configuration files that match the expected API.
Using Webstorm, the IDE will tell me that my Webpack config file schema is incorrect, something like this:
The Webpack files that are responsible are here:
https://github.com/webpack/webpack/blob/master/schemas/webpackOptionsSchema.json
Integration with existing IDEs like Webstorm, VSCode, Atom, ST3, etc, would be a huge plus.
I haven't figured out how to do this right...anybody know?
To integrate with various IDEs, consider uploading your json schema to JSON Schema Store.
Here is the GitHub Repo
https://github.com/SchemaStore/schemastore
This contains json schemas for many well known json files and gets integrated with Visual Studio and VS Code easily.
Also look at step by step integrations steps for Visual Studio
https://scottaddie.com/2016/08/02/community-driven-json-schemas-in-visual-studio-2015/
I'm a beginner in swagger and by following the documentation I'm able to generate swagger.json (swagger definition in json schema format) and also able to view that in swagger-ui.
But currently I'm able to access my json schema file only after deploying my application(It is getting generated under the base path I have given in web.xml).
Is there anyway to get it without deploying the application? Because each time when I want to re-check the documentation after a change has done, I have to deploy my application. It would be better if we have any offline method.
Thanks.
I am using an F# JSON type provider to create a type from a reference JSON document. The reference document "ReferenceItem.json" is part of the F# library. In addition I have a unit test project which tests the library. I am struggling with making the reference document available for the test project without duplicating it.
No matter how I mark "ReferenceItem.json" in Visual Studio (Content, None, Copy to Output etc.) my test project fails to compile because the statement JsonProvider<"ReferenceItem.json"> expects "Reference.json" to be present in the project source folder at compilation time. Including it as a linked item from the library project doesn't help: it's not copied at compile time to the test source folder. So I need to make a duplicate copy of the file in the test project.
I noticed that in F# projects I can mark files as "DesignData" or "DesignDataWithDesignTimeCreatableTypes", but I wasn't able to figure out how I can use them.
This is a tricky problem - when F# compiler references the library, it will invoke the type provider and so the type provider needs to be able to access the sample.
The easiest solution is to just always copy the sample json file so that it is in the folder from where the application is starting. This is obviously sub-optimal, and so we have another way of handling this using resources.
See the "Using JSON provider in a library" section of the documentation. The idea is that you can embed the sample document as a resource in the library and specify the resource name as an additional parameter:
type WB = JsonProvider<"../data/WorldBank.json",
EmbeddedResource="MyLib, worldbank.json">
This will then load the resource when using the library (but it still needs the file name in the original compilation mode). This is still somewhat experimental, so please open an issue on GitHub if you cannot get it to work!
I want to use BIRT to generate reports against data that comes from a JSON based REST API. How can I import this data?
The process for doing this is described at http://developer.actuate.com/community/forum/?app=blog&blogid=45&showentry=471, but it turns out that there are a few important steps missing. I'll fill in a few blanks here.
The original instructions describe creating a Scripted Data Source, with an "open" script that makes use of the com.actuate.json.JSONParser class. First, it is important to realise that this class is not part of BIRT, and needs to be manually added (along with any dependencies).
The download provided by the original instructions provides the com.actuate.json.JSONParser class, but leaves it up to you to source the dependencies. To make things easier I have reimplemented the JSONParser library in Maven, which will then download and package the dependencies for you. It also includes some bug fixes and enhancements like GZIP compression support. You can get the Maven project from https://github.com/mcasperson/birt-jsonparser, and to build the JSONParser library and package the dependencies, run the command
mvn clean package dependency:copy-dependencies
This will result in the birt-jsonparser-0.0.1-SNAPSHOT.jar file being created in the target directory, and all the dependencies copied into the target\dependency directory. Copy all of these JAR files into the {BIRT_INSTALL}/plugins/org.eclipse.birt.report.viewer_{BIRT_VIEWER_VERSION}/birt/scriptlib directory to allow the JSONParser class to be accessed from within your BIRT report.
If you want to debug your report, these JAR files will also have to be referenced in the Debug profile.