Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nothing happens, unable to generate from OpenAPI JSON Schema #1412

Open
ruckc opened this issue Jun 24, 2022 · 6 comments
Open

Nothing happens, unable to generate from OpenAPI JSON Schema #1412

ruckc opened this issue Jun 24, 2022 · 6 comments

Comments

@ruckc
Copy link

ruckc commented Jun 24, 2022

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>
@unkish
Copy link
Collaborator

unkish commented Jul 8, 2022

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.

@ruckc
Copy link
Author

ruckc commented Jul 8, 2022

So no way to consume unaltered Json schema files then?

@chrberSTO
Copy link

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.

@joelittlejohn
Copy link
Owner

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.

@eirnym
Copy link

eirnym commented Jul 11, 2022

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

@lejtemxviw
Copy link

It looks like this PR might fix this issue for swagger/OAS2? #1523

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants