jsonschema2pojo
jsonschema2pojo copied to clipboard
Nothing happens, unable to generate from OpenAPI JSON Schema
I am trying to leverage the OpenAPI JSON Schema, to validate some user provided OpenAPI definitions. When trying to use the maven-plugin or the jsonschema2pojo website, I get no results.
JSON Schema: https://raw.githubusercontent.com/OAI/OpenAPI-Specification/main/schemas/v3.1/schema.json
<plugin>
<groupId>org.jsonschema2pojo</groupId>
<artifactId>jsonschema2pojo-maven-plugin</artifactId>
<version>1.1.2</version>
<configuration>
<sourceType>jsonschema</sourceType>
<sourceDirectory>${basedir}/src/main/resources/schemas</sourceDirectory>
<targetPackage>com.example.openapi</targetPackage>
</configuration>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
Hi @ruckc
I'm pretty sure it's due to L77: "$ref": "#/$defs/specification-extensions", which is defined on top level.
The way current plugin works - it tries to resolve and apply given reference (see SchemaRule).
Running plugin with L77 removed triggers generation of several java files.
So no way to consume unaltered Json schema files then?
Hi,
I have a similar problem and the plugin does not state that there is any problem with the schema files. How am I supposed to know what is wrong with my JSON files, if the plugin just finishes with a success?
Thank you. Kind regards.
It's possible to have a JSON schema with no meaningful rules or types to generate. This means the plugin has done its work but there is nothing to do.
Until recent versions, the JSON schema spec explicitly mentioned that the presence of $ref in a schema should mean that all other keys in the schema must be ignored. So this is what jsonschema2pojo does. I believe that this may have changed in recent versions of the JSON schema spec, however we should find an explicit reference.
Yes, this has been changed since version 2019-09. Versions below (e.g. draft-0[1-7]) has this explicit restriction
It looks like this PR might fix this issue for swagger/OAS2? https://github.com/joelittlejohn/jsonschema2pojo/pull/1523