Coder Social home page Coder Social logo

saasquatch / json-schema-inferrer Goto Github PK

View Code? Open in Web Editor NEW
153.0 12.0 37.0 2.06 MB

Java library for inferring JSON schema from sample JSONs

License: Apache License 2.0

Java 100.00%
java java-8 java-library json-schema-inferrer schemas json json-schema jackson json-schema-inference

json-schema-inferrer's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

json-schema-inferrer's Issues

Installation of json-schema-inferrer

Hello,

I don't know how to install json-schema-inferrer on my computer (install/build java applications is still very opaque to me).

After installing gradle 8.7 through sdk, I tried to follow the guidelines in the README.md, adding the dependencies and repository in build.gradle:

plugins {
    id 'java-library'
}

group = 'com.saasquatch'
version = '1.0-SNAPSHOT'

java {
    registerFeature('builtInFormatInferrerSupport') {
        usingSourceSet(sourceSets.main)
    }
}

tasks.compileJava.options.encoding = 'UTF-8'
tasks.compileTestJava.options.encoding = 'UTF-8'
tasks.javadoc.options.encoding = 'UTF-8'

repositories {
    mavenCentral()
    maven { url 'https://jitpack.io' } # I added this line
}

dependencies {
    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.10.1'
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.10.1'
    implementation 'com.google.code.findbugs:jsr305:3.0.2'
    api 'com.fasterxml.jackson.core:jackson-databind:2.16.1'
    builtInFormatInferrerSupportImplementation 'commons-validator:commons-validator:1.8.0'
    testImplementation 'com.networknt:json-schema-validator:1.1.0'
    testImplementation 'com.google.guava:guava:33.0.0-jre'
    implementation 'com.github.saasquatch:json-schema-inferrer:0.2.1' # I added this line also
}

tasks.test {
    useJUnitPlatform()
}

java {
    toolchain {
        languageVersion.set(JavaLanguageVersion.of(8))
    }
}

I don't know if even this is correct.

Next I launched the command:
./gradlew

Which resulted in:

Downloading https://services.gradle.org/distributions/gradle-8.7-bin.zip
............10%.............20%.............30%.............40%............50%.............60%.............70%.............80%.............90%............100%

> Task :help

Welcome to Gradle 8.7.

To run a build, run gradlew <task> ...

To see a list of available tasks, run gradlew tasks

To see more detail about a task, run gradlew help --task <task>

To see a list of command-line options, run gradlew --help

For more detail on using Gradle, see https://docs.gradle.org/8.7/userguide/command_line_interface.html

For troubleshooting, visit https://help.gradle.org

Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

For more on this, please refer to https://docs.gradle.org/8.7/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation.

BUILD SUCCESSFUL in 15s
1 actionable task: 1 executed

Fine, but I don't see any executable/jar file to launch, so I am stuck. Could you please help me? Thanks.

Build Errors.

Description Resource Path Location Type
Missing artifact com.github.saasquatch:json-schema-inferrer:jar:0.2.0 pom.xml /jsontojsonschema line 17 Maven Dependency Problem
The container 'Maven Dependencies' references non existing library 'C:\dev\devtools\cache\m2_repository\com\github\saasquatch\json-schema-inferrer\0.2.0\json-schema-inferrer-0.2.0.jar' jsontojsonschema Build path Build Path Problem
The project cannot be built until build path errors are resolved jsontojsonschema Unknown Java Problem

It is not parsed according to the original JSON field order

I expect to return the schema to me in the order of the JSON fields I give. Now I find that the order it gives me is not in the order of the JSON fields I give him. I can't find a method in the jsonschemainferrer and no method in the test class. Can you help me see what to do?

image

Field order is different in the schema

I noticed that the order of the fields in the schema is different to that of the input json object. I wanted to know whether this was intentional. If so is there a way to predict the field order in the schema? I am using this as an intermediary in one of my libraries and I am having trouble writing the tests as I cannot determine the exact output beforehand. Any help would be much appreciated.

Publish to maven central repository

Hi! This is the best tool out there that converts a sample of json to json schema. Unfortunately I have a requirement that I can only use packages available in the maven central repository. Any chance you can publish it there?

There is no JsonNode's key in GenericSchemaFeatureInput.

Sometimes, I only want some keys to generate rules, but the current GenericSchemaFeatureInputcan only get the type and value of the json node, not its key.
For an example:

{
  "result": "success",
  "msg": "xxxxxxxxx"
}

I want this json gen that json schema:

{
	"$schema": "http://json-schema.org/draft-07/schema#",
	"type": "object",
	"properties": {
		"result": {
			"type": "string",
                        "const": "success"
		},
		"msg": {
			"type": "string"
		}
	},
	"additionalProperties": false,
	"required": [
		"result",
		"msg"
	]
}

Now, I can't make rules to generate const only for the field result.

Upgrade on Draft version

As this library supports schema draft version upto 7, will there be any update on the latest schema draft version.

Can you give items a default value when the array is empty?

JSON Sample:

{
  "model_setting": {
    "hidden_layers": []
  }
}
The format I want looks like this:When the array is empty give items a default value。
{
  "type": "object",
  "properties": {
    "model_setting": {
      "type": "object",
      "properties": {
        "hidden_layers": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      }
    }
  }
}

My code is as follows

  @RequestMapping(value ="/getJsonSchema", method=RequestMethod.POST, produces="application/json;charset=UTF-8")
    public String getJsonSchema(@RequestBody Map<String,Object> jsonData) throws JsonProcessingException {
        ObjectMapper mapper = new ObjectMapper();
        JsonSchemaInferrer inferrer = JsonSchemaInferrer.newBuilder()
                .setSpecVersion(SpecVersion.DRAFT_04)
                .setAdditionalPropertiesPolicy(AdditionalPropertiesPolicies.noOp())
                .setDefaultPolicy(DefaultPolicies.useFirstSamples())
                .setRequiredPolicy(RequiredPolicies.noOp())
                .build();

        ObjectNode inferForSample = inferrer.inferForSample(mapper.readTree(mapper.writeValueAsString(jsonData)));
        return inferForSample.toPrettyString();
    }

The result generated is as follows,no default value

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "properties": {
    "model_setting": {
      "type": "object",
      "properties": {
        "hidden_layers": {
          "type": "array"
        }
      }
    }
  }
}

Maven dependency-check displays json-schema-inferrer-0.1.4 as Critical because the vulnerability CVE-2021-3918

Hi,

I have an application which depends on json-schema-inferrer. The security report runned with the dependency-check-maven plugin displays a Critical vulnerability CVE-2021-3918.

Reading the report, it says this vulnerability is related to: "json-schema is vulnerable to Improperly Controlled Modification of Object Prototype Attributes ('Prototype Pollution')".

I forked the repo and I tried to find any dependency to the json-schema it mentions but I couldn't find where it is used further than in the SpecVersion.java:14 as a URL String.

The application where I am using this library cannot be released to production until all critical vulnerability will be fixed. Could you give me any hint about how to resolve this vulnerability?

This is the dependency-check-maven configuration in the pom.xml:

<plugin>
  <groupId>org.owasp</groupId>
  <artifactId>dependency-check-maven</artifactId>
  <version>7.1.0</version>
  <configuration>
    <failBuildOnCVSS>7</failBuildOnCVSS>
    <skipProvidedScope>true</skipProvidedScope>
    <skipRuntimeScope>true</skipRuntimeScope>
    <skipTestScope>true</skipTestScope>
  </configuration>
  <executions>
    <execution>
      <goals>
         <goal>check</goal>
       </goals>
    </execution>
  </executions>
</plugin>

image

image

Kind regards

Need JAR

How to download the jar for this library, I can find only the maven dependency in jitpackio. So I need to know where to download the JAR directly?

State of the repo

What is the long term plan to support and enhance this library?
I am thinking of either creating something myself or betting on this lib.
Are the artifacts published to maven repo?
When the support of draft-08 will be available?
Are you open to contributors PRs?

intelliJ gradle dependency failure

I don't know if this question belongs here, but maybe someone has encountered this issue before.

I basically want to use this library in a production java environment using IntelliJ as the IDE.

After attempting to create a gradle dependency in the IDE, the Maven artifact for this library does not show up in the relevant artifact list.

How to reproduce:

  1. press cmd-N when viewing build.gradle in the editor
  2. Select Add Maven artifact dependency
  3. the identifier to use is from the maven repo website: com.github.saasquatch:json-schema-inferrer:0.1.3
  4. paste the identifer into the artifact search field
  5. This artifact does not show up in the resulting list.

Even adding a custom repository (https://repository.mulesoft.org/nexus/content/repositories/public/) to IntelliJ from the Maven repository website does not help. This directory apparently does not to contain the desired resources.

Any thoughts or help would be greatly appreciated.

Not support const field.

The best desigin is config the field that can generate const validate.
such as:

JsonSchemaInferrer.newBuilder().setSpecVersion(SpecVersion.DRAFT_07)
           .setConstPolicy(ConstPolicies.xxx())

$ref and $id

How to generate schema using $ref and $id. Seen this can be achieved using genericSchema interface. Can you share any code snippet or document to show how to use genericschema interface.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.