joelittlejohn / jsonschema2pojo

Generate Java types from JSON or JSON Schema and annotate those types for data-binding with Jackson, Gson, etc
http://www.jsonschema2pojo.org
Apache License 2.0
6.24k stars 1.66k forks source link

Code only generated for top-level file #1508

Closed pab233 closed 1 year ago

pab233 commented 1 year ago

I have been provided with a large json schema that is contained in 8 separate files. When I try to generate the associated java classes using a maven build, code is only generated for the highest level, apparently ignoring the definitions in any of the other files. Is this a known issue or am I doing something wrong?

Plugin configuration

           <plugin>
                <groupId>org.jsonschema2pojo</groupId>
                <artifactId>jsonschema2pojo-maven-plugin</artifactId>
                <version>1.2.1</version>
                <configuration>
                <sourcePaths>
                    <sourcePath>${basedir}/src/main/resources/schema</sourcePath>
</sourcePaths>
                    <outputDirectory>c:/temp/datex3/</outputDirectory>
                    <targetPackage>com.example.types</targetPackage>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

Top-level schema

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "definitions": {},
  "type": "object",
  "additionalProperties": true,
  "anyOf": [
    {
      "$ref": "DATEXII_3_Common.json#/definitions/_PayloadPublication"
    }
  ]
}

Generated code - only "DATEXII3D2Payload" has been generated, nothing from the referenced file (which in turn references other files)

package com.example.types;

import java.util.LinkedHashMap;
import java.util.Map;
import javax.annotation.Generated;
import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({

})
@Generated("jsonschema2pojo")
public class DATEXII3D2Payload {

    @JsonIgnore
    private Map<String, Object> additionalProperties = new LinkedHashMap<String, Object>();

    @JsonAnyGetter
    public Map<String, Object> getAdditionalProperties() {
        return this.additionalProperties;
    }

    @JsonAnySetter
    public void setAdditionalProperty(String name, Object value) {
        this.additionalProperties.put(name, value);
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(DATEXII3D2Payload.class.getName()).append('@').append(Integer.toHexString(System.identityHashCode(this))).append('[');
        sb.append("additionalProperties");
        sb.append('=');
        sb.append(((this.additionalProperties == null)?"<null>":this.additionalProperties));
        sb.append(',');
        if (sb.charAt((sb.length()- 1)) == ',') {
            sb.setCharAt((sb.length()- 1), ']');
        } else {
            sb.append(']');
        }
        return sb.toString();
    }

    @Override
    public int hashCode() {
        int result = 1;
        result = ((result* 31)+((this.additionalProperties == null)? 0 :this.additionalProperties.hashCode()));
        return result;
    }

    @Override
    public boolean equals(Object other) {
        if (other == this) {
            return true;
        }
        if ((other instanceof DATEXII3D2Payload) == false) {
            return false;
        }
        DATEXII3D2Payload rhs = ((DATEXII3D2Payload) other);
        return ((this.additionalProperties == rhs.additionalProperties)||((this.additionalProperties!= null)&&this.additionalProperties.equals(rhs.additionalProperties)));
    }

}
unkish commented 1 year ago

Hi

Is this a known issue or am I doing something wrong?

There are know limitations:

  1. anyOf/allOf/oneOf are not supported and thus are not processed
  2. if "schema" is used as container (contains only defitions) then it doesn't represent any type at all and so nothing is generated (see https://github.com/joelittlejohn/jsonschema2pojo/issues/1500#issuecomment-1465185420)
pab233 commented 1 year ago

Thank you @unkish

Looks like I'll have to interpret the data by hand then :(