
You can define reusable enums in the global components section and reference them via $ref elsewhere. This is typical of PBT tools in all languages, as they make use of existing. In OpenAPI 3.0, both operation parameters and data models use a schema, making it easy to reuse the data types. The example uses ScalaCheck, a PBT tool, which in turn uses ScalaTest and Checker. The companion object of an enum also defines three utility methods. The integer associated with an enum value is returned by its ordinal method: scala> val red Color.Red val red: Color Red scala> red.ordinal val res0: Int 0.

Using nullable: true alone is not enough here. The values of an enum correspond to unique integers. Note that null must be explicitly included in the list of enum values. * `desc` - Descending, from Z to A Nullable enumsĪ nullable enum can be defined as follows: type: string If you need to specify descriptions for enum items, you can do this in the description of the parameter or property: In YAML, you can also specify one enum value per line:Īll values in an enum must adhere to the specified type. It uses reflection so if you use it, you may need to add libraryDependencies + 'org.scala-lang' 'scala-reflect' scalaV to your project. For example, the sort parameter in GET /items?sort= can be described as: This is simple 40-lines implementation of enums based on sealed classes (supporting pattern matching exhaustion checks). You can use the enum keyword to specify possible values of a request parameter or a model property. If you use OpenAPI 2.0, see our OpenAPI 2.0 guide. The fromOrdinal method obtains an enum value from its ordinal ( Int ) value. We believe that this covers most use cases of The values method returns all enum values defined in an enumeration in an Array.
#SCALA ENUM FULL#
Therefore, the full rewrite is: val = Value ( if ( nextName != null & nextName. Consider the following example: sealed trait Direction case object East extends Direction case object West extends Direction. Note that the name rewriting honors the nextName Or calls to constructors of the protected Val class without anĮxplicit name as parameter, will issue a warning.

1 matches Byte, Short, Int, Float, Double.Short, Int, Float, Double are based on the value and not the Instance tests (and consequently pattern matching) on any of Byte,
#SCALA ENUM PORTABLE#
To get sensible and portable string representation of floating point numbers, Which means their lack of precision shows up. toString // "1.399999976158142" instead of "1.4"įloats print in a weird way because they are printed as if they were Doubles, scala.Enumeration Foo.custom shouldBe 'This is a foo' case object Foo.custom shouldBe 'This is a foo' Java Enum FOO.custom shouldBe 'This is a foo' Indexed: Items have a consecutive incremental numeric value scala.Enumeration Mon.id shouldBe 1 Sun.id shouldBe 7 case object Foo.order shouldBe 1 Bar.

toString // "undefined", instead of "()" 1.0. X.toString() returns slightly different results for floating point numbersĪnd () ( Unit). There is also no attribute access either. What I notice is that enum is not yet a monad, so there is no flatMap and get, and there is no predefined apply and unapply function. Primitive data typesĪll nine primitive data types of Scala, i.e., Boolean, Char, Byte, Short, Int, Long, Float, Double and Unit, work exactly as on the JVM, with the following three exceptions. enum Task: case CleaningTask () extends Task case CookingTask () extends Task case ShoppingTask () extends Task. However, a few differences exist, which we mention here. In general, the semantics of the Scala.js language are the same as Scala on
