jsonschema2pojo icon indicating copy to clipboard operation
jsonschema2pojo copied to clipboard

Nothing happens, unable to generate from OpenAPI JSON Schema

Open ruckc opened this issue 3 years ago • 6 comments
trafficstars

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>

ruckc avatar Jun 24 '22 18:06 ruckc

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.

unkish avatar Jul 08 '22 14:07 unkish

So no way to consume unaltered Json schema files then?

ruckc avatar Jul 08 '22 14:07 ruckc

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.

chrberSTO avatar Jul 11 '22 11:07 chrberSTO

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.

joelittlejohn avatar Jul 11 '22 12:07 joelittlejohn

Yes, this has been changed since version 2019-09. Versions below (e.g. draft-0[1-7]) has this explicit restriction

eirnym avatar Jul 11 '22 13:07 eirnym

It looks like this PR might fix this issue for swagger/OAS2? https://github.com/joelittlejohn/jsonschema2pojo/pull/1523

lejtemxviw avatar May 30 '23 04:05 lejtemxviw