json-kotlin-schema-codegen icon indicating copy to clipboard operation
json-kotlin-schema-codegen copied to clipboard

net.pwall.json.pointer.JSONPointerException: Recursive $ref - /definitions/Extension for FHIR v4.0.1 schema

Open tower-guidev2 opened this issue 2 years ago • 3 comments

I wish to generate kotlin data classe for the FHIR v4.0.1 draft v7 json schema (download) and executing

    val codeGenerator = CodeGenerator()
    codeGenerator.baseDirectoryName = "/Users/xxxxxx/IdeaProjects/Generation/src/output"
    codeGenerator.basePackageName = "com.example"
    codeGenerator.generate(File("/Users/xxxxxx/IdeaProjects/Generation/src/resource/fhir.schema.json")) 

gives


SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Exception in thread "main" net.pwall.json.pointer.JSONPointerException: Recursive $ref - /definitions/Extension
	at net.pwall.json.schema.parser.Parser.parseSchema(Parser.kt:175)
	at net.pwall.json.schema.parser.Parser.parseRef(Parser.kt:327)
	at net.pwall.json.schema.parser.Parser.parseSchema(Parser.kt:202)
	at net.pwall.json.schema.parser.Parser.parseItems(Parser.kt:336)
	at net.pwall.json.schema.parser.Parser.parseSchema(Parser.kt:223)
	at net.pwall.json.schema.parser.Parser.parseProperties(Parser.kt:342)
	at net.pwall.json.schema.parser.Parser.parseSchema(Parser.kt:215)
	at net.pwall.json.schema.parser.Parser.parseRef(Parser.kt:327)
	at net.pwall.json.schema.parser.Parser.parseSchema(Parser.kt:202)
	at net.pwall.json.schema.parser.Parser.parseItems(Parser.kt:336)
	at net.pwall.json.schema.parser.Parser.parseSchema(Parser.kt:223)
	at net.pwall.json.schema.parser.Parser.parseProperties(Parser.kt:342)
	at net.pwall.json.schema.parser.Parser.parseSchema(Parser.kt:215)
	at net.pwall.json.schema.parser.Parser.parseRef(Parser.kt:327)
	at net.pwall.json.schema.parser.Parser.parseSchema(Parser.kt:202)
	at net.pwall.json.schema.parser.Parser.parseProperties(Parser.kt:342)
	at net.pwall.json.schema.parser.Parser.parseSchema(Parser.kt:215)
	at net.pwall.json.schema.parser.Parser.parseRef(Parser.kt:327)
	at net.pwall.json.schema.parser.Parser.parseSchema(Parser.kt:202)
	at net.pwall.json.schema.parser.Parser.parseCombinationSchema(Parser.kt:309)
	at net.pwall.json.schema.parser.Parser.parseSchema(Parser.kt:208)
	at net.pwall.json.schema.parser.Parser.parse(Parser.kt:149)
	at net.pwall.json.schema.parser.Parser.parse(Parser.kt:120)
	at net.pwall.json.schema.codegen.CodeGenerator.addTarget(CodeGenerator.kt:478)
	at net.pwall.json.schema.codegen.CodeGenerator.addTargets(CodeGenerator.kt:370)
	at net.pwall.json.schema.codegen.CodeGenerator.addTargets$default(CodeGenerator.kt:364)
	at net.pwall.json.schema.codegen.CodeGenerator.generate(CodeGenerator.kt:354)
	at net.pwall.json.schema.codegen.CodeGenerator.generate(CodeGenerator.kt:344)
	at Generate_FHIR_schemaKt.main(Generate_FHIR_schema.kt:11)

tower-guidev2 avatar Feb 14 '23 16:02 tower-guidev2

I think the message is self-explanatory - $ref doesn't allow recursion. Draft 2019-09 of JSON Schema introduced $recursiveRef, and draft 2020-12 introduced $dynamicRef, but json-kotlin-schema-codegen does not support either of these constructs. Sorry about that.

I have been working on a new version which supports the full draft 2020-12 spec., but I'm afraid that's still some months away from being ready.

Sorry I can't be more help.

pwall567 avatar Feb 15 '23 11:02 pwall567

thanks for responding to my issue. and nice work on your library i have managed to make some progress with a hacky approach

tower-guidev2 avatar Feb 15 '23 12:02 tower-guidev2

@tower-guidev2 If that still has any relevance for you, you may try out my PR: https://github.com/pwall567/json-kotlin-schema-codegen/pull/43 Feedback welcome!

milux avatar Aug 14 '24 12:08 milux