-
-
Notifications
You must be signed in to change notification settings - Fork 7k
[Scala] Add enums to scala-http4s-server #21320
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
[Scala] Add enums to scala-http4s-server #21320
Conversation
47c1ab8
to
1cb9c2f
Compare
1cb9c2f
to
3e46ec6
Compare
thanks for the PR cc |
please follow step 3 to update the samples so that the CI can verify the change |
393f94d
to
de1c5c3
Compare
de1c5c3
to
3225064
Compare
cModel.getVendorExtensions().put("x-isEnum", true); | ||
|
||
} else { | ||
cModel.getVendorExtensions().put("x-another", true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the PR. what exactly is another
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added this type to describe types that are not traits or enums. This is necessary to get into this branch in the mustache templates and generate case classes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will x-unsupported
works better in this case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I doubt that "unsupported" is the right name for simple types, which generated to scala case classes. I think "another" better describes all types except traits and enums
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's go with what you've right now. we can always fine tune the extension naming later.
tested locally and the result is good
here is what the change looks like before and after applying this fix diff --git a/src/main/scala/org/openapitools/models/types.scala b/src/main/scala/org/openapitools/models/types.scala
index 8247885..2075ca8 100644
--- a/src/main/scala/org/openapitools/models/types.scala
+++ b/src/main/scala/org/openapitools/models/types.scala
@@ -8,15 +8,17 @@ import io.circe.{ Decoder, Encoder }
import io.circe.generic.semiauto.{ deriveDecoder, deriveEncoder }
+import org.openapitools.models.EnumType.EnumType
/**
*
*/
-case class EnumType(
-)
-object EnumType {
- implicit val encoderEnumType: Encoder[EnumType] = deriveEncoder[EnumType].mapJson(_.dropNullValues)
- implicit val decoderEnumType: Decoder[EnumType] = deriveDecoder[EnumType]
+object EnumType extends Enumeration {
+ type EnumType = Value
+ val Fix = Value
+ val Max = Value
+ implicit val decoder: Decoder[EnumType.Value] = Decoder.decodeEnumeration(EnumType)
+ implicit val encoder: Encoder[EnumType.Value] = Encoder.encodeEnumeration(EnumType)
}
/**
|
There is an example of correct openAPI specification:
For given OpenAPI specification generated not valid type for enum EnumType - empty case class:
case class EnumType()
I added enum handling for scala-http4s-server.
Trying to fix #9987 for scala-http4s-server.