-
Notifications
You must be signed in to change notification settings - Fork 14
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
Bug: target class name does not get updated after first schema #30
Comments
I just tried renaming the directory |
Okay, I did some debugging of the code, and the culprit seems to be in fun parse(file: File): JSONSchema {
if (!file.isFile)
throw JSONSchemaException("Invalid file - $file")
val uri = file.toURI()
schemaCache[uri]?.let { return it }
val json = jsonReader.readJSON(file)
return parse(json, uri)
} Why is it caching the URI, which is different between each schema file, and also used to determine the output class name? Am I missing something obvious here 🤔 |
According to #13, this is apparently intended behavior in A more likely suspect might be It's also interesting that |
The only place in the code where any entries are added to |
Okay, another clue. I supplied the following {
"classNames": {
"urn:OCPP:Cp:2:2020:3:AuthorizeRequest": "AuthorizeRequest",
"urn:OCPP:Cp:2:2020:3:NotifyEVChargingNeedsRequest": "SomeDifferentClassName"
},
"derivePackageFromStructure": true
} And now it writes out all the parsed schemas as So it appears that the schema URI gets cached upon the first parsed JSON schema, and does not get updated for each subsequently parsed schema, even though the file name of each generated class is based on the schema URI. So whether or not there are any mappings in Also, changing |
It's not the complex logic in It really seems like the caching mechanism it its current form doesn't seem to be working well with directories containing multiple JSON schemas, each with different URIs (URNs in the In particular, the following step seems to never take place:
|
Thank you for providing such extensive information to assist with diagnosing this issue. Your analysis is mostly correct, but the underlying problem is that the caching mechanism uses as its key the extended URI, that is, the original URI plus the pointer as a fragment (the portion after the '#'), but the function that it uses to create that extended URI (in the Java URI class) does not operate as expected. That's not to say that the Java class is wrong, just that it does not work in the way that I thought it would. The problem arises when the URI is a URN (or any other form of "opaque" URI), and that is a case that I had not tested extensively. I can see a straightforward fix for this and I will deploy a new version as quickly as possible, but that may take a day or more. Thank you again for bringing this to my attention, and for persevering in your attempts to use the code generator. Regards, |
Thank you for your quick reply and for willing to release a fix so quickly! I appreciate that. 🙂 By the way, to make things more challenging, I've been trying to use your Gradle plugin in a Kotlin Multiplatform project, and it seems like I actually managed to get that working with some tweaks in the build script file. For one thing, the code generator defaults to using Java-specific types such as Java JSR-310 date/time classes and BigDecimal. Obviously, that causes the Kotlin/Native and Kotlin/JS builds in the project to fail. But with custom Also, in Instead, I've found the following workaround in project.tasks.withType<KotlinCompileCommon>().configureEach {
dependsOn(project.tasks.findByName("generate"))
} Anyway, if I end up getting it fully working, I'll be happy to share all of the needed workarounds with you, so that you can perhaps make the Gradle plugin more Kotlin-Multiplatform-friendly out of the box. Thanks again! |
OK, version 0.93 should fix the issue with the use of URN as And I'm very interested to about your workarounds to get the Multiplatform project working – I'm always keen to make the code generator usable by a wider audience. I'd be happy to incorporate your suggestions into the project if you're willing to share them. (i didn't incorporate your suggestion regarding the Regards, |
Oops! I deployed version 0.93 of Sorry about that! |
Yes! I can confirm that with version Thank you for releasing a fix so quickly. One small thing I noticed, though: even though version Anyway, I'm resolving this ticket, since it has been resolved. |
Thanks for pointing out that I had forgotten to push the changes to GitHub That has now been done 👍 |
Hi,
While using the Gradle plugin based on this project, I encountered a weird bug in which the target class name gets "stuck" after processing the first of a number of JSON schemas in a directory, leading to each subsequent schema overwriting the previous one, resulting in only a single remaining generated class.
This happens with version
0.92
of bothjson-kotlin-schema-codegen
and version0.91
ofjson-kotlin-gradle
. I also tried an earlier version ofjson-kotlin-gradle
(I believe I randomly picked0.87
), and the issue existed there as well.Code to reproduce:
the JSON schemas that this code expects in
src/main/resources/OCPP-2.0.1_part3_JSON_schemas
can be downloaded from the website of the Open Charge Alliance. Free registration is required, and I'm not sure if I can just share the schemas here. You need to select "OCPP 2.0.1 (all files)". and will receive a download link. The ZIP fileOCPP-2.0.1_-all_files_1.zip
will in turn contain the ZIP fileOCPP-2.0.1_part3_JSON_schemas
, which contains these JSON schemas.I'll try to get a clarification whether I'm allowed to immediately share the JSON schemas here as an attachment.
Anyway, once you run this code on these JSON schemas, the output will be as follows (I'm just showing the first couple of lines, because that's enough to see what's going wrong):
(I replaced my actual home folder with
$HOME
in this output.)As you can see, the source file name gets updated properly each log line
Generating for ...
, but it remains stuck on the first one in each log line-- target class ...
.And indeed, once the application finishes, only one file
NotifyEVChargingNeedsRequest.kt
ends up in the generated sources.I briefly looked into the code, and my guess it that some kind of instance variable in
CodeGenerator.kt
does not seem to get updated properly. PossiblyclassNameMapping
?Anyway, let me know if I can offer assistance in solving this issue.
Thanks for sharing this very useful project with the world!
The text was updated successfully, but these errors were encountered: