Skip to content

Commit

Permalink
Added new ParamKind primitive object in 1.26.0
Browse files Browse the repository at this point in the history
  • Loading branch information
hnaderi committed Dec 9, 2022
1 parent e657767 commit 53e7c4e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright 2022 Hossein Naderi
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.k8s.api.admissionregistration.v1alpha1

import dev.hnaderi.k8s.utils._

/** ParamKind is a tuple of Group Kind and Version. */
final case class ParamKind(group: String, version: String) {
val value = s"$group/$version"
}
object ParamKind {
private val pattern = "(.+)/(.+)".r
implicit def encoder[T](implicit builder: Builder[T]): Encoder[ParamKind] =
Encoder[String].contramap(_.value)
implicit def decoder[T: Reader]: Decoder[ParamKind] = Decoder[String].emap {
case pattern(group, version) => Right(ParamKind(group, version))
case other => Left(s"""Invalid ParamKind format "${other}"""")
}
}
6 changes: 6 additions & 0 deletions modules/scalacheck/src/main/scala/PrimitiveGenerators.scala
Original file line number Diff line number Diff line change
Expand Up @@ -260,4 +260,10 @@ private[scalacheck] trait PrimitiveGenerators { self: NonPrimitiveGenerators =>
maxLength = maxLength,
allOf = allOf
)

implicit lazy val arbitrary_io_k8s_api_admissionregistration_v1alpha1_ParamKind
: Arbitrary[io.k8s.api.admissionregistration.v1alpha1.ParamKind] =
Arbitrary(
Gen.resultOf(io.k8s.api.admissionregistration.v1alpha1.ParamKind(_, _))
)
}

0 comments on commit 53e7c4e

Please sign in to comment.