Skip to content

IllegalArgumentException while resolving reference to reference with # #793

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

Closed
xaviarias opened this issue Oct 11, 2017 · 6 comments
Closed
Milestone

Comments

@xaviarias
Copy link

xaviarias commented Oct 11, 2017

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!

@joelittlejohn
Copy link
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.

@xaviarias
Copy link
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.

@xaviarias
Copy link
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.

@joshiste
Copy link

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

@unkish
Copy link
Collaborator

unkish commented Dec 18, 2020

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)

@joelittlejohn joelittlejohn changed the title Exception while resolving reference with # IllegalArgumentException while resolving reference to reference with # Apr 2, 2021
@joelittlejohn
Copy link
Owner

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

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

4 participants