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

Recursive $ref failed #250

Closed
princehaku opened this issue Sep 25, 2014 · 5 comments
Closed

Recursive $ref failed #250

princehaku opened this issue Sep 25, 2014 · 5 comments
Labels
Milestone

Comments

@princehaku
Copy link

the sample

{
        "type" : "object",
        "properties" : {
          "child1" : {
                "type" : "string"
            },
          "child2" :{
               "$ref" : "#/properties/child1"
            }
        }
}

it doesn't work

got error There's a problem: URI is not absolute

@princehaku
Copy link
Author

private boolean selfReferenceWithoutParentFile(Schema parent, String path) {
    return path.startsWith("#/");
}

line 98 seems return false

@joelittlejohn
Copy link
Owner

@princehaku Are you using the web ui at www.jsonschema2pojo.org or generating this locally? The web UI has a problem with local references (see #183). This is fixed in the current head version, we just need to update the web UI.

@princehaku
Copy link
Author

thanks very much .. i'm using your online version run your sample code.
just thought it might be a same problem as below.

generating this locally from the code below depends on jsonschema2pojo-core head version

package com.test;

import java.io.File;
import java.io.IOException;

import com.sun.codemodel.CodeWriter;
import com.sun.codemodel.JCodeModel;
import org.jsonschema2pojo.*;
import org.jsonschema2pojo.rules.*;

class Test {
    public static void main(String[] args) throws IOException {
            String source = "{\n" +
                    "    \"type\": \"object\",\n" +
                    "    \"definitions\": \n" +
                    "    {\n" +
                    "        \"location\": \n" +
                    "        {\n" +
                    "            \"type\": \"object\",\n" +
                    "            \"properties\": \n" +
                    "            {\n" +
                    "                \"lat\": \n" +
                    "                {\n" +
                    "                    \"type\": \"number\"\n" +
                    "                },\n" +
                    "                \"cat\": \n" +
                    "                {\n" +
                    "                    \"$ref\": \"#/definitions/cat\"\n" +
                    "                }\n" +
                    "            }\n" +
                    "        },\n" +
                    "      \"cat\" : \n" +
                    "      {\n" +
                    "        \"type\" : \"number\"\n" +
                    "      }\n" +
                    "    },\n" +
                    "\n" +
                    "    \"properties\": \n" +
                    "    {\n" +
                    "        \"location\": \n" +
                    "        {\n" +
                    "            \"$ref\": \"#/definitions/location\"\n" +
                    "        }\n" +
                    "    }\n" +
                    "}";

            RuleFactory mockRuleFactory = new RuleFactory();
            DefaultGenerationConfig gcfg = new DefaultGenerationConfig();
            JCodeModel codeModel = new JCodeModel();
            new SchemaMapper(mockRuleFactory, new SchemaGenerator()).generate(codeModel, "ABC", "com.test", source);
            File directory = new File("/home/admin/");
            System.out.println("exporting to : " + directory.getAbsolutePath());
            CodeWriter resourcesWriter = new FileCodeWriterWithEncoding(directory, gcfg.getOutputEncoding());
            codeModel.build(resourcesWriter);
    }
}

Recurisly calling $ref
it failed on URI is not absolute
seems parent node is incorrent

@princehaku princehaku changed the title sample code failed Recurisly $ref faild Sep 26, 2014
@princehaku princehaku changed the title Recurisly $ref faild Recurisly $ref failed Sep 26, 2014
@joelittlejohn joelittlejohn changed the title Recurisly $ref failed Recursive $ref failed Oct 28, 2014
@KalinKanev
Copy link

I can see that this issue is kind of old but I'm running in the same problem. Is there a plan to fix it ?

@joelittlejohn joelittlejohn added this to the 0.4.16 milestone Sep 28, 2015
@joelittlejohn
Copy link
Owner

So it looks like the original example works correctly (the simple case) - that issue was fixed a long time ago. There is a more complicated example here: #250 (comment) and this does not work. This is not a problem with simple recursive refs but a problem with having an inner schema that is referred to by a fragment ref then using another fragment ref to refer outside the inner schema. This only seems to affect the case where there is no parent file (the schema is supplied as a string), and jsonschema2pojo.org is one such place.

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

No branches or pull requests

3 participants