swagger-api / swagger-codegen-generators

Apache License 2.0
284 stars 424 forks source link

Spring-Cloud Codegen Broken due to unknown import import io.swagger.configuration.NotUndefined; #1319

Open FrostbittenKing opened 1 week ago

FrostbittenKing commented 1 week ago

Hi, since introduction of the annotation NotUndefined in swagger-codegen-generators v1.0.52, spring cloud code generation breaks, due to a new annotation io.swagger.configuration.NotUndefined that doesn't seem to exist anywhere. Commit: 2835d9de I can't locate the dependency where this comes from. Not via grep, not google. I have no idea how this slipped by all tests, and randomly breaks code generators using swagger-codegen-generators. I checked the source, and for now i can only disable it with legacy in the swagger-codegen-maven-plugin / using a command line flag, when invoking swagger-codegen cli directly. Whats the point of this annotation, and why can't I find anything about it in any package, where this got introduced. Google doesn't turn up squats when i try to directly search ' io.swagger.configuration.NotUndefined', there is no dependency with the package path io.swagger.configuration. At least none I could find.

Thanks.

frantuma commented 1 week ago

NotUndefined is a generated annotation to support nullable/required combinations as detailed in https://github.com/swagger-api/swagger-codegen-generators/pull/1308/, as you mentioned used when validationMode is set to strict or loose.

It shouldn't create issues or errors, if you are still experiencing issues please provide the spec causing the issues along with the generator options used. Please close ticket if your problem is solved

FrostbittenKing commented 1 week ago

Thanks, I will check, I would assume it's a bug caused by my spec, that wasn't anticipated. I check the generated code, if I can locate the annotation there. Maybe there's a package name mismatch. Edit: The annotation itself just isn't generated.

FrostbittenKing commented 1 week ago

Ok got it. What in my opinion wasn't anticipated is, I configured generateSupportingFiles to false, since we didn't need them. It creates an ApiKeyRequestInterceptor we don't need, a clientconfiguration we don't need, since we need to adjust it anyways, and also as I've seen now the missing annotation @NotUndified, in the wrong package (it uses the packagepath of what I configured with configPackage. So, this doesn't really work in maven-codegen-maven-plugin this way. It would only work, if i didn't change the configPackage name, and even then, it might cause problems, cause we don't need the supporting files (they might even cause problems currently).

Edit: Sadly this is kinda messy at the moment. I also had to enable useBeanValidation, for the annotation to be generated. I would assume useBeanValidation should disable adding the import to the annotation at all. So in short: when useBeanValidation is set to false, I would expect to not use beanValidation, and also not add the imports to the classes.

frantuma commented 1 week ago

@FrostbittenKing thanks for the feedback, and you are right! We are working on that, it would help if you could share the full config you are using

FrostbittenKing commented 1 week ago

Yes, I will post this, after I cleaned it up, since it's work related.

FrostbittenKing commented 1 week ago

Hi @frantuma , here is the maven plugin build block, cleaned up. broken-swagger-codegen-3_0_63.zip To generate the annotation: I had to set first generateSupportingFiles to true (apparently this is a still obscure badly documented config property), and secondly set useBeanValidation=true. Then it gets at least generated, with other stuff we just don't need. When we set useBeanValidation=false, the annotation doesn't get generated, but the java classes still show the import to the annotaiton. When we change the default configPackage path name, it doesn't work either cause of a package path mismatch between the generated annotation in the config package, and what's written into the java classes as imports. This is all I could gather as far. I'm sorry since I don't have to work with this daily, I haven't remembered how this all works in detail, and how tight the collaboration is between the maven plugin and the generators, and if this is a bug in this library or the maven plugin.

There are also probably still one or two workarounds in the config attached, for bugs that occurred in the past (i think the typemappings stuff + dateLibrary legacy, also defaultInterces enabled caused problems with missing imports as far as I remember), but these don't seem to be having an effect on our issue at hand.

It would be really nice, if the imports were removed, if useBeanValidation is set to false, and also, that the package paths genertated match the configPackage property, if useBeanValidation was set to true. I'm not sure if generation of the annotation should be disabled, when generateSupportingFiles is set to false.

frantuma commented 3 days ago

This has been fixed in https://github.com/swagger-api/swagger-codegen-generators/pull/1322 and https://github.com/swagger-api/swagger-codegen/pull/12487.

@FrostbittenKing please have a go with latest 3.0.64-SNAPSHOT (release will follow in 1-2 days), the issues mentioned should be fixed.

FrostbittenKing commented 2 days ago

This has been fixed in #1322 and swagger-api/swagger-codegen#12487.

@FrostbittenKing please have a go with latest 3.0.64-SNAPSHOT (release will follow in 1-2 days), the issues mentioned should be fixed.

Thank you!!!, I will try when I get to it.