-
Notifications
You must be signed in to change notification settings - Fork 6k
Possible swagger hub codegen issue with Spring Data Mongo #3509
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
Comments
@mherb63 are you saying the following enum name and value mapping is incorrect?
If yes, what would the correct mapping looks like? |
it seems like Mongo is looking for "_100ms" (with lower case). c.c.l.p.exception.ApiExceptionHandler : No enum constant com.ciena.lion.mef.pm.domain.EthOamDmmCfg.FrameTransmissionPeriodEnum._100ms |
Please try the stable version 2.2.1 and let us know if you still experience the same issue. |
I'm generating Spring code from swaggerhub. Just tried and its still uppercasing the enums. |
@mherb63 thanks for checking again. I'll take another look at the issue for Spring (the fix I mentinoed was for Java client) |
Great. Thanks! Please let me know when you want me to re-test from swaggerhub. |
any updates on this issue? When will fixes be pushed to swaggerhub for Spring server code generation? Thanks! |
@mherb63 To be clear, the fix will still convert the enum name to upper case. The fix we did with Java added the I've been very busy these days and I'll try to file a PR for this issue tomorrow (Fri). |
UPDATE: Filed #3615 to add the |
#3615 merged into master. Please pull the latest master and build the JAR locally to use the fix before stable version 2.2.2 is released. |
I'm curious why you are converting the enum name to upper case. This is recent new behavior which has broken our existing code. Can you not use the enum value as the name (without uppercasing)? That's how it was working up until about a month ago or so. Thanks! |
@mherb63 we do it to conform the enum naming convention in Java: http://docs.oracle.com/javase/tutorial/java/javaOO/enum.html, http://stackoverflow.com/a/3069863/677735 |
I believe the "Model Schema" shows the JSON presentation of the model. |
Did you get the error using the latest master, which should have addressed the deserialization for |
I generated the code from Swagger hub on Aug 24th (6 days ago). What new code did you add that I can check if its there? |
We added the |
I just generated our code from swaggerhub and I'm not seeing any fromValue method.
Michaels-iMac:spring-server-generated mherb$ pwd |
I don't think SwaggerHub is using the latest master of Swagger Codegen. |
are you sure this bug is fixed for Spring Server code generation? I just did the below and I'm still not seeing any fromValue methods in the generated model code. brew install swagger-codegen Mike |
brew is not installing the latest master either. It's using the latest stable version 2.2.1 instead. |
Description
Mongo not able to map swagger code generated fields with domain model code generated from swaggerhub.
The following JSON is used on swaggerhub:
"frameTransmissionPeriod": {
"description": "SLM period for frame transmission",
"type": "string",
"enum": [
"_10ms",
"_100ms",
"_1sec",
"_10sec"
],
"default": "_100ms"
},
And here is the generated code (Server->Spring), note the uppercase "MS" and "SEC"
public enum FrameTransmissionPeriodEnum {
_100MS("_100ms"),
_1SEC("_1sec"),
_10SEC("_10sec");
}
When reading from Spring Data mongo we have what's in Mongo:
"ethOamDmmCfg" : {
"testId" : "5555",
"pmCosId" : 1,
"vlanId" : 100,
"frameTransmissionPeriod" : "_100ms",
"frameSize" : "1028"
},
And the following Mongo error:
2016-08-02 15:46:21.804 ERROR 79727 --- [nio-8680-exec-8] c.c.l.p.exception.ApiExceptionHandler : No enum constant com.ciena.lion.mef.pm.domain.EthOamDmmCfg.FrameTransmissionPeriodEnum._100ms
java.lang.IllegalArgumentException: No enum constant com.ciena.lion.mef.pm.domain.EthOamDmmCfg.FrameTransmissionPeriodEnum._100ms
at java.lang.Enum.valueOf(Enum.java:238)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.getPotentiallyConvertedSimpleRead(MappingMongoConverter.java:819)
Swagger-codegen version
swaggerhub.com
Swagger declaration file content or url
Command line used for generation
Steps to reproduce
Related issues
Suggest a Fix
at some point in time, the generated Spring code has upper-cased the enums and I believe this has caused the issue. If I change "MS" and "SEC" to "ms" and "sec" in the generated domain model code, Mongo is happy.
The text was updated successfully, but these errors were encountered: