Skip to content

IllegalArgumentException while resolving reference to reference with # #793

Closed

Description

@xaviarias

Hi,

I am having troubles to generate POJOS for a JSON schema that contains a reference with pound (#). E.g.

{
  "$schema": "http://json-schema.org/draft-04/schema",
  "id": "test.json",
  "properties": {
    "id": {
      "$ref": "basic_types.json#/definitions/positive_int"
    }
  }
}

I am using recently installed CLI with Brew under Mac OS X.

Here is the complete trace:

Exception in thread "main" java.lang.IllegalArgumentException: Path not present: definitions
        at org.jsonschema2pojo.FragmentResolver.resolve(FragmentResolver.java:54)
        at org.jsonschema2pojo.FragmentResolver.resolve(FragmentResolver.java:31)
        at org.jsonschema2pojo.SchemaStore.create(SchemaStore.java:61)
        at org.jsonschema2pojo.SchemaStore.create(SchemaStore.java:128)
        at org.jsonschema2pojo.rules.PropertyRule.resolveRefs(PropertyRule.java:160)
        at org.jsonschema2pojo.rules.PropertyRule.resolveRefs(PropertyRule.java:162)
        at org.jsonschema2pojo.rules.PropertyRule.apply(PropertyRule.java:81)
        at org.jsonschema2pojo.rules.PropertyRule.apply(PropertyRule.java:43)
        at org.jsonschema2pojo.rules.PropertiesRule.apply(PropertiesRule.java:70)
        at org.jsonschema2pojo.rules.PropertiesRule.apply(PropertiesRule.java:38)
        at org.jsonschema2pojo.rules.ObjectRule.apply(ObjectRule.java:119)
        at org.jsonschema2pojo.rules.ObjectRule.apply(ObjectRule.java:70)
        at org.jsonschema2pojo.rules.TypeRule.apply(TypeRule.java:90)
        at org.jsonschema2pojo.rules.TypeRule.apply(TypeRule.java:40)
        at org.jsonschema2pojo.rules.SchemaRule.apply(SchemaRule.java:73)
        at org.jsonschema2pojo.rules.SchemaRule.apply(SchemaRule.java:66)
        at org.jsonschema2pojo.rules.SchemaRule.apply(SchemaRule.java:30)
        at org.jsonschema2pojo.rules.PropertyRule.apply(PropertyRule.java:75)
        at org.jsonschema2pojo.rules.PropertyRule.apply(PropertyRule.java:43)
        at org.jsonschema2pojo.rules.PropertiesRule.apply(PropertiesRule.java:70)
        at org.jsonschema2pojo.rules.PropertiesRule.apply(PropertiesRule.java:38)
        at org.jsonschema2pojo.rules.ObjectRule.apply(ObjectRule.java:119)
        at org.jsonschema2pojo.rules.ObjectRule.apply(ObjectRule.java:70)
        at org.jsonschema2pojo.rules.TypeRule.apply(TypeRule.java:90)
        at org.jsonschema2pojo.rules.TypeRule.apply(TypeRule.java:40)
        at org.jsonschema2pojo.rules.SchemaRule.apply(SchemaRule.java:73)
        at org.jsonschema2pojo.rules.SchemaRule.apply(SchemaRule.java:30)
        at org.jsonschema2pojo.rules.ArrayRule.apply(ArrayRule.java:81)
        at org.jsonschema2pojo.rules.ArrayRule.apply(ArrayRule.java:37)
        at org.jsonschema2pojo.rules.TypeRule.apply(TypeRule.java:113)
        at org.jsonschema2pojo.rules.TypeRule.apply(TypeRule.java:40)
        at org.jsonschema2pojo.rules.SchemaRule.apply(SchemaRule.java:73)
        at org.jsonschema2pojo.rules.SchemaRule.apply(SchemaRule.java:30)
        at org.jsonschema2pojo.rules.PropertyRule.apply(PropertyRule.java:75)
        at org.jsonschema2pojo.rules.PropertyRule.apply(PropertyRule.java:43)
        at org.jsonschema2pojo.rules.PropertiesRule.apply(PropertiesRule.java:70)
        at org.jsonschema2pojo.rules.PropertiesRule.apply(PropertiesRule.java:38)
        at org.jsonschema2pojo.rules.ObjectRule.apply(ObjectRule.java:119)
        at org.jsonschema2pojo.rules.ObjectRule.apply(ObjectRule.java:70)
        at org.jsonschema2pojo.rules.TypeRule.apply(TypeRule.java:90)
        at org.jsonschema2pojo.rules.TypeRule.apply(TypeRule.java:40)
        at org.jsonschema2pojo.rules.SchemaRule.apply(SchemaRule.java:73)
        at org.jsonschema2pojo.rules.SchemaRule.apply(SchemaRule.java:66)
        at org.jsonschema2pojo.rules.SchemaRule.apply(SchemaRule.java:30)
        at org.jsonschema2pojo.SchemaMapper.generate(SchemaMapper.java:92)
        at org.jsonschema2pojo.Jsonschema2Pojo.generate(Jsonschema2Pojo.java:77)
        at org.jsonschema2pojo.cli.Jsonschema2PojoCLI.main(Jsonschema2PojoCLI.java:48)

Thanks!

Activity

  1. joelittlejohn commented on Oct 11, 2017

    @joelittlejohn
    Owner

    Does the basic_types.json that is alongside test.json have a property called definitions? It looks like jsonschema2pojo does not see it in there.

  2. xaviarias commented on Oct 11, 2017

    @xaviarias
    Author

    No it is not a JSON Schema property but a JSON property, i.e:

    {
      "$schema": "http://json-schema.org/draft-04/schema",
      "id": "basic_types.json",
      "definitions": {
          "positive_int": {
          "type": "integer",
          "minimum": 1
        }
      }
    }
    

    By reading the docs that seems to be a valid alternative for structuring complex schemas.

  3. xaviarias commented on Oct 11, 2017

    @xaviarias
    Author

    My minimal example generates valid code though. The id field is properly generated as a Java integer. I would need to find an extended example to reproduce the error.

  4. joshiste commented on Dec 16, 2020

    @joshiste

    the same happens when trying to generate the schemas from oci: https://github.com/tianon/oci-runtime-spec/tree/master/schema

  5. unkish commented on Dec 18, 2020

    @unkish
    Collaborator

    A simplified reproducible case would be:
    selfRef.json:

    {
      "definitions": {
        "Name": {
          "type": "string"
        },
        "NameRef": {
          "$ref": "#/definitions/Name"
        }
      }
    }
    

    Referencing schema:

    {
      "type" : "object",
      "properties" : {
        "propertyOfA" : {
          "$ref": "selfRef.json#/definitions/NameRef"
        }
      }
    }
    

    Looks like #322 would fix this (though given PR does not conform to contribution rules)

  6. changed the title [-]Exception while resolving reference with #[/-] [+]IllegalArgumentException while resolving reference to reference with #[/+] on Apr 2, 2021
  7. joelittlejohn commented on Apr 2, 2021

    @joelittlejohn
    Owner

    Thanks for the minimal example @unkish, that helped a lot 😃

  8. added this to the 1.1.1 milestone on Apr 2, 2021
  9. added a commit that references this issue on Aug 8, 2024
    e484204
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions