jsonschema-generator | Java JSON Schema Generator – creating JSON Schema ( Draft | JSON Processing library
kandi X-RAY | jsonschema-generator Summary
kandi X-RAY | jsonschema-generator Summary
Java JSON Schema Generator – creating JSON Schema (Draft 6, Draft 7, Draft 2019-09, or Draft 2020-12) from Java classes
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Merge all of the elements of the given schema
- Determines whether a list of sub - schema nodes can be merged
- Returns a map of supported tag values from all of the fields that are supported
- Computes the overlap of strings
- Provides a custom schema definition for the given type
- Checks the validity of the given type
- Checks whether the given type is serialized or not
- Applies the configuration options to the given schema generation strategy
- Apply common member configurations
- Resolve a Number type annotation
- Provides a custom schema definition for the given type
- Provides a custom property definition for the given scope
- Apply the required fields to the configuration builder
- Lookup the field associated with this method
- Creates a definition for the given member map
- Provides a custom definition for the given type
- Determine the maximum value of a field
- Apply options to the config builder
- An implementation of this method
- Checks if any of the elements in the given Json SchemaNode contains any tag
- Adds the given field to the collection
- Adds the given method to the collection
- Allows to override the instance attributes for the given member
- Creates a simple type for primitive types
- Provides a custom property schema for the given field or method
- Invokes the schema generator
jsonschema-generator Key Features
jsonschema-generator Examples and Code Snippets
Community Discussions
Trending Discussions on jsonschema-generator
QUESTION
In my project I have some DTO classes that I use in my REST communication. With Karate I want to create some external e2e/integration tests where I check if the API responses comply with the contract defined in the DTOs. To keep the whole setup DRY I want to avoid manually writing Karate JSON schemas describing the DTOs. Instead I am looking for a way to translate my Java classes into Karate JSON schemas.
What I already have:Let's say this is one of my Java DTOs.
...ANSWER
Answered 2021-May-24 at 17:39I very strongly recommend that you do NOT re-use your production DTO-s for your tests. Think about it, you are setting yourself up for failure - and run the risk of not realizing when a "refactoring" that someone applied via the IDE etc. breaks your API clients.
You should be testing from the perspective of clients which for many teams is a web-browser. That is why Karate avoids Java and sticks to JSON + HTTP.
Second, testing for schema-fit has very little value in my honest opinion. Based on what you said, it is quite likely that your JSON is being generated from the DTO-s already, which makes it even less valuable in your specific case.
Sorry if that sounds harsh, but I see this mistake made all over the place. Being DRY is over-rated especially in a test-automation context.
That said, if you are lucky, the karate.toJson()
method would be able to convert your DTO-s into JSON, but if you are using some fancy annotations it may not work, it is all based on the JavaBean conventions.
Finally I would say just use Java inter-op, call some Java library to do schema validation and call it a day as seen in schema.feature
over here.
To summarize, I think you should forget about schema validation and focus on testing the "business flows" of your API-s, where you typically chain API-s. Create product. Create order. Check if inventory is reduced. Etc etc. Once you have those in place, then think about whether it is worth testing for schema-fit or not.
QUESTION
I'm using jsonschema-generator to generate a JSON schema file based on my POJOs. Currently I'm doing it via a test that is run during the gradle build
step. This works fine but it doesn't feel right as really what I'm doing is not testing anything.
I've also found this answer which details how to run it on gradle run
but this is not ideal either as it will pointlessly execute this every time the application comes up but not when I build.
Therefore, is there a way to tell gradle (in build.gradle
) to run a piece of Java code at build time?
For completeness, here the code I'm looking to run:
...ANSWER
Answered 2020-Apr-05 at 19:03The JavaExec Plugin seems to meet your requirements.
This allows you to run a main()
method and thereby any Java Code you want – including whatever JSON Schema generation you like.
This other answer also describes pretty much what you want to do.
Adapted from the linked documentation:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install jsonschema-generator
You can use jsonschema-generator like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the jsonschema-generator component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page