Skip to content

Possible swagger hub codegen issue with Spring Data Mongo #3509

Closed
@mherb63

Description

@mherb63
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");

private String value;

FrameTransmissionPeriodEnum(String value) {
  this.value = value;
}

@Override
@JsonValue
public String toString() {
  return value;
}

}

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions