Skip to content

Commit 1b5e02e

Browse files
authored
dhall-openapi: Fix autoscaler preference (#2562)
Related to dhall-lang/dhall-kubernetes#191 Before this change the `v1`, `v2beta{1,2}` versions were preferred over *all* other versions (even newer versions like `v2`). This change fixes the comparison logic so that the hardcoded exception doesn't affect any other comparisons.
1 parent 97f9a5b commit 1b5e02e

File tree

1 file changed

+13
-14
lines changed
  • dhall-openapi/openapi-to-dhall

1 file changed

+13
-14
lines changed

dhall-openapi/openapi-to-dhall/Main.hs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -144,29 +144,28 @@ getVersion ModelName{..} =
144144
Right version -> Just version
145145

146146
-- https://github.com/dhall-lang/dhall-kubernetes/issues/112
147-
data Autoscaling = AutoscalingV1 | AutoscalingV2beta1 | AutoscalingV2beta2
148-
deriving (Eq, Ord)
149-
150-
getAutoscaling :: ModelName -> Maybe Autoscaling
151-
getAutoscaling ModelName{..}
152-
| Text.isPrefixOf "io.k8s.api.autoscaling.v1" unModelName =
153-
Just AutoscalingV1
154-
| Text.isPrefixOf "io.k8s.api.autoscaling.v2beta1" unModelName =
155-
Just AutoscalingV2beta1
156-
| Text.isPrefixOf "io.k8s.api.autoscaling.v2beta2" unModelName =
157-
Just AutoscalingV2beta2
147+
-- https://github.com/dhall-lang/dhall-kubernetes/issues/191
148+
comparingAutoscaling :: ModelName -> ModelName -> Ordering
149+
comparingAutoscaling modelNameL modelNameR
150+
| isAutoscaling modelNameL && isAutoscaling modelNameR =
151+
case (getVersion modelNameL, getVersion modelNameR) of
152+
(Just (Version Production 1), Just (Version (Beta _) 2)) -> LT
153+
(Just (Version (Beta _) 2), Just (Version Production 1)) -> GT
154+
_ -> mempty
158155
| otherwise =
159-
Nothing
156+
mempty
157+
where
158+
isAutoscaling ModelName{..} =
159+
Text.isPrefixOf "io.k8s.api.autoscaling." unModelName
160160

161161
isK8sNative :: ModelName -> Bool
162162
isK8sNative ModelName{..} = Text.isPrefixOf "io.k8s." unModelName
163163

164164
preferStableResource :: DuplicateHandler
165165
preferStableResource (_, names) = do
166-
let issue112 = Ord.comparing getAutoscaling
167166
let k8sOverCrd = Ord.comparing isK8sNative
168167
let defaultComparison = Ord.comparing getVersion
169-
let comparison = issue112 <> k8sOverCrd <> defaultComparison
168+
let comparison = comparingAutoscaling <> k8sOverCrd <> defaultComparison
170169
return (List.maximumBy comparison names)
171170

172171
skipDuplicatesHandler :: DuplicateHandler

0 commit comments

Comments
 (0)