mirror of
https://github.com/TECHNOFAB11/kubenix.git
synced 2025-12-14 08:53:50 +01:00
switch formatting to nixpkgs-fmt
This commit is contained in:
parent
3598716c73
commit
2712e89716
65 changed files with 4839 additions and 5222 deletions
|
|
@ -1,45 +1,36 @@
|
|||
{
|
||||
pkgs,
|
||||
lib,
|
||||
}: let
|
||||
{ pkgs, lib }:
|
||||
let
|
||||
generateIstio = import ./istio {
|
||||
inherit
|
||||
pkgs
|
||||
lib
|
||||
;
|
||||
inherit pkgs lib;
|
||||
};
|
||||
|
||||
generateK8S = name: spec:
|
||||
import ./k8s {
|
||||
inherit
|
||||
name
|
||||
pkgs
|
||||
lib
|
||||
spec
|
||||
;
|
||||
inherit name pkgs lib spec;
|
||||
};
|
||||
in {
|
||||
istio = pkgs.linkFarm "istio-generated" [
|
||||
{
|
||||
name = "latest.nix";
|
||||
path = generateIstio;
|
||||
}
|
||||
];
|
||||
in
|
||||
{
|
||||
istio = pkgs.linkFarm "istio-generated" [{
|
||||
name = "latest.nix";
|
||||
path = generateIstio;
|
||||
}];
|
||||
|
||||
k8s = pkgs.linkFarm "k8s-generated" (
|
||||
builtins.attrValues (
|
||||
builtins.mapAttrs (
|
||||
version: sha: let
|
||||
short = builtins.concatStringsSep "." (lib.lists.sublist 0 2 (builtins.splitVersion version));
|
||||
in {
|
||||
name = "v${short}.nix";
|
||||
path = generateK8S "v${short}" (builtins.fetchurl {
|
||||
url = "https://github.com/kubernetes/kubernetes/raw/v${version}/api/openapi-spec/swagger.json";
|
||||
sha256 = sha;
|
||||
});
|
||||
}
|
||||
)
|
||||
(import ../../versions.nix).full
|
||||
builtins.mapAttrs
|
||||
(version: sha:
|
||||
let
|
||||
short = builtins.concatStringsSep "." (lib.lists.sublist 0 2 (builtins.splitVersion version));
|
||||
in
|
||||
{
|
||||
name = "v${short}.nix";
|
||||
path = generateK8S "v${short}" (builtins.fetchurl {
|
||||
url = "https://github.com/kubernetes/kubernetes/raw/v${version}/api/openapi-spec/swagger.json";
|
||||
sha256 = sha;
|
||||
});
|
||||
}
|
||||
)
|
||||
(import ../../versions.nix).full
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
{
|
||||
pkgs ? import <nixpkgs> {},
|
||||
lib ? pkgs.lib,
|
||||
spec ? ./istio-schema.json,
|
||||
{ pkgs ? import <nixpkgs> { }
|
||||
, lib ? pkgs.lib
|
||||
, spec ? ./istio-schema.json
|
||||
}:
|
||||
with lib; let
|
||||
gen = rec {
|
||||
|
|
@ -20,14 +19,9 @@ with lib; let
|
|||
then "null"
|
||||
else builtins.toString value;
|
||||
|
||||
removeEmptyLines = str: concatStringsSep "\n" (filter (l: builtins.match "[[:space:]]*" l != []) (splitString "\n" str));
|
||||
removeEmptyLines = str: concatStringsSep "\n" (filter (l: builtins.match "[[:space:]]*" l != [ ]) (splitString "\n" str));
|
||||
|
||||
mkOption = {
|
||||
description ? null,
|
||||
type ? null,
|
||||
default ? null,
|
||||
apply ? null,
|
||||
}:
|
||||
mkOption = { description ? null, type ? null, default ? null, apply ? null }:
|
||||
removeEmptyLines '' mkOption {
|
||||
${optionalString (description != null) "description = ${builtins.toJSON description};"}
|
||||
${optionalString (type != null) ''type = ${type};''}
|
||||
|
|
@ -53,7 +47,7 @@ with lib; let
|
|||
|
||||
hasTypeMapping = def:
|
||||
hasAttr "type" def
|
||||
&& elem def.type ["string" "integer" "boolean"];
|
||||
&& elem def.type [ "string" "integer" "boolean" ];
|
||||
|
||||
mergeValuesByKey = mergeKey: ''(mergeValuesByKey "${mergeKey}")'';
|
||||
|
||||
|
|
@ -84,157 +78,152 @@ with lib; let
|
|||
refDefinition = attr: head (tail (tail (splitString "/" attr."$ref")));
|
||||
};
|
||||
|
||||
fixJSON = replaceStrings ["\\u"] ["u"];
|
||||
fixJSON = replaceStrings [ "\\u" ] [ "u" ];
|
||||
|
||||
fetchSpecs = path: builtins.fromJSON (fixJSON (builtins.readFile path));
|
||||
|
||||
genDefinitions = swagger:
|
||||
with gen; (mapAttrs
|
||||
(
|
||||
_name: definition:
|
||||
# if $ref is in definition it means it's an alias of other definition
|
||||
if hasAttr "$ref" definition
|
||||
then definitions."${refDefinition definition}"
|
||||
else if !(hasAttr "properties" definition)
|
||||
then {
|
||||
type = mapType definition;
|
||||
}
|
||||
else {
|
||||
options =
|
||||
mapAttrs
|
||||
(
|
||||
propName: property: let
|
||||
isRequired = elem propName (definition.required or []);
|
||||
requiredOrNot = type:
|
||||
if isRequired
|
||||
then type
|
||||
else types.nullOr type;
|
||||
optionProperties =
|
||||
# if $ref is in property it references other definition,
|
||||
# but if other definition does not have properties, then just take it's type
|
||||
if hasAttr "$ref" property
|
||||
then
|
||||
if hasTypeMapping swagger.definitions.${refDefinition property}
|
||||
then {
|
||||
type = requiredOrNot (mapType swagger.definitions.${refDefinition property});
|
||||
}
|
||||
else {
|
||||
type = requiredOrNot (submoduleOf definitions (refDefinition property));
|
||||
}
|
||||
else if !(hasAttr "type" property)
|
||||
genDefinitions = swagger: with gen; (mapAttrs
|
||||
(_name: definition:
|
||||
# if $ref is in definition it means it's an alias of other definition
|
||||
if hasAttr "$ref" definition
|
||||
then definitions."${refDefinition definition}"
|
||||
else if !(hasAttr "properties" definition)
|
||||
then {
|
||||
type = mapType definition;
|
||||
}
|
||||
else {
|
||||
options = mapAttrs
|
||||
(propName: property:
|
||||
let
|
||||
isRequired = elem propName (definition.required or [ ]);
|
||||
requiredOrNot = type:
|
||||
if isRequired
|
||||
then type
|
||||
else types.nullOr type;
|
||||
optionProperties =
|
||||
# if $ref is in property it references other definition,
|
||||
# but if other definition does not have properties, then just take it's type
|
||||
if hasAttr "$ref" property
|
||||
then
|
||||
if hasTypeMapping swagger.definitions.${refDefinition property}
|
||||
then {
|
||||
type = requiredOrNot (mapType swagger.definitions.${refDefinition property});
|
||||
}
|
||||
else {
|
||||
type = requiredOrNot (submoduleOf definitions (refDefinition property));
|
||||
}
|
||||
else if !(hasAttr "type" property)
|
||||
then {
|
||||
type = types.unspecified;
|
||||
}
|
||||
# if property has an array type
|
||||
else if property.type == "array"
|
||||
then
|
||||
# if reference is in items it can reference other type of another
|
||||
# definition
|
||||
if hasAttr "$ref" property.items
|
||||
then
|
||||
# if it is a reference to simple type
|
||||
if hasTypeMapping swagger.definitions.${refDefinition property.items}
|
||||
then {
|
||||
type = types.unspecified;
|
||||
type = requiredOrNot (types.listOf (mapType swagger.definitions.${refDefinition property.items}.type));
|
||||
}
|
||||
# if property has an array type
|
||||
else if property.type == "array"
|
||||
then
|
||||
# if reference is in items it can reference other type of another
|
||||
# definition
|
||||
if hasAttr "$ref" property.items
|
||||
# if a reference is to complex type
|
||||
else
|
||||
# if x-kubernetes-patch-merge-key is set then make it an
|
||||
# attribute set of submodules
|
||||
if hasAttr "x-kubernetes-patch-merge-key" property
|
||||
then
|
||||
# if it is a reference to simple type
|
||||
if hasTypeMapping swagger.definitions.${refDefinition property.items}
|
||||
then {
|
||||
type = requiredOrNot (types.listOf (mapType swagger.definitions.${refDefinition property.items}.type));
|
||||
let
|
||||
mergeKey = property."x-kubernetes-patch-merge-key";
|
||||
in
|
||||
{
|
||||
type = requiredOrNot (coerceAttrsOfSubmodulesToListByKey (refDefinition property.items) mergeKey);
|
||||
apply = attrsToList;
|
||||
}
|
||||
# if a reference is to complex type
|
||||
else
|
||||
# if x-kubernetes-patch-merge-key is set then make it an
|
||||
# attribute set of submodules
|
||||
if hasAttr "x-kubernetes-patch-merge-key" property
|
||||
then let
|
||||
mergeKey = property."x-kubernetes-patch-merge-key";
|
||||
in {
|
||||
type = requiredOrNot (coerceAttrsOfSubmodulesToListByKey (refDefinition property.items) mergeKey);
|
||||
apply = attrsToList;
|
||||
}
|
||||
# in other case it's a simple list
|
||||
else {
|
||||
type = requiredOrNot (types.listOf (submoduleOf definitions (refDefinition property.items)));
|
||||
}
|
||||
# in other case it only references a simple type
|
||||
# in other case it's a simple list
|
||||
else {
|
||||
type = requiredOrNot (types.listOf (mapType property.items));
|
||||
type = requiredOrNot (types.listOf (submoduleOf definitions (refDefinition property.items)));
|
||||
}
|
||||
else if property.type == "object" && hasAttr "additionalProperties" property
|
||||
then
|
||||
# if it is a reference to simple type
|
||||
if
|
||||
(
|
||||
hasAttr "$ref" property.additionalProperties
|
||||
&& hasTypeMapping swagger.definitions.${refDefinition property.additionalProperties}
|
||||
)
|
||||
then {
|
||||
type = requiredOrNot (types.attrsOf (mapType swagger.definitions.${refDefinition property.additionalProperties}));
|
||||
}
|
||||
else if hasAttr "$ref" property.additionalProperties
|
||||
then {
|
||||
type = requiredOrNot types.attrs;
|
||||
}
|
||||
# if is an array
|
||||
else if property.additionalProperties.type == "array"
|
||||
then {
|
||||
type = requiredOrNot (types.loaOf (mapType property.additionalProperties.items));
|
||||
}
|
||||
else {
|
||||
type = requiredOrNot (types.attrsOf (mapType property.additionalProperties));
|
||||
}
|
||||
# just a simple property
|
||||
else {
|
||||
type = requiredOrNot (mapType property);
|
||||
};
|
||||
in
|
||||
mkOption ({
|
||||
description = property.description or "";
|
||||
}
|
||||
// optionProperties)
|
||||
# in other case it only references a simple type
|
||||
else {
|
||||
type = requiredOrNot (types.listOf (mapType property.items));
|
||||
}
|
||||
else if property.type == "object" && hasAttr "additionalProperties" property
|
||||
then
|
||||
# if it is a reference to simple type
|
||||
if
|
||||
(
|
||||
hasAttr "$ref" property.additionalProperties
|
||||
&& hasTypeMapping swagger.definitions.${refDefinition property.additionalProperties}
|
||||
)
|
||||
then {
|
||||
type = requiredOrNot (types.attrsOf (mapType swagger.definitions.${refDefinition property.additionalProperties}));
|
||||
}
|
||||
else if hasAttr "$ref" property.additionalProperties
|
||||
then {
|
||||
type = requiredOrNot types.attrs;
|
||||
}
|
||||
# if is an array
|
||||
else if property.additionalProperties.type == "array"
|
||||
then {
|
||||
type = requiredOrNot (types.loaOf (mapType property.additionalProperties.items));
|
||||
}
|
||||
else {
|
||||
type = requiredOrNot (types.attrsOf (mapType property.additionalProperties));
|
||||
}
|
||||
# just a simple property
|
||||
else {
|
||||
type = requiredOrNot (mapType property);
|
||||
};
|
||||
in
|
||||
mkOption ({
|
||||
description = property.description or "";
|
||||
}
|
||||
// optionProperties)
|
||||
)
|
||||
definition.properties;
|
||||
config =
|
||||
let
|
||||
optionalProps = filterAttrs
|
||||
(propName: _property:
|
||||
!(elem propName (definition.required or [ ]))
|
||||
)
|
||||
definition.properties;
|
||||
config = let
|
||||
optionalProps =
|
||||
filterAttrs
|
||||
(
|
||||
propName: _property:
|
||||
!(elem propName (definition.required or []))
|
||||
)
|
||||
definition.properties;
|
||||
in
|
||||
mapAttrs (_name: _property: mkOverride 1002 null) optionalProps;
|
||||
}
|
||||
)
|
||||
swagger.definitions);
|
||||
in
|
||||
mapAttrs (_name: _property: mkOverride 1002 null) optionalProps;
|
||||
}
|
||||
)
|
||||
swagger.definitions);
|
||||
|
||||
genResources = swagger:
|
||||
(mapAttrsToList
|
||||
(_name: property: rec {
|
||||
splittedType = splitString "." (removePrefix "me.snowdrop.istio.api." property.javaType);
|
||||
group = (concatStringsSep "." (take ((length splittedType) - 2) splittedType)) + ".istio.io";
|
||||
kind = removeSuffix "Spec" (last splittedType);
|
||||
version = last (take ((length splittedType) - 1) splittedType);
|
||||
ref = removePrefix "#/definitions/" property."$ref";
|
||||
})
|
||||
(filterAttrs
|
||||
(
|
||||
_name: property:
|
||||
(hasPrefix "me.snowdrop.istio.api" property.javaType)
|
||||
&& hasSuffix "Spec" property.javaType
|
||||
)
|
||||
swagger.properties))
|
||||
++ (mapAttrsToList
|
||||
(_name: property: rec {
|
||||
splittedType = splitString "." (removePrefix "me.snowdrop.istio.mixer." property.javaType);
|
||||
group = "config.istio.io";
|
||||
version = "v1alpha2";
|
||||
kind = head (tail splittedType);
|
||||
ref = removePrefix "#/definitions/" property."$ref";
|
||||
})
|
||||
(filterAttrs
|
||||
(
|
||||
_name: property:
|
||||
(hasPrefix "me.snowdrop.istio.mixer" property.javaType)
|
||||
&& hasSuffix "Spec" property.javaType
|
||||
)
|
||||
swagger.properties));
|
||||
genResources = swagger: (mapAttrsToList
|
||||
(_name: property: rec {
|
||||
splittedType = splitString "." (removePrefix "me.snowdrop.istio.api." property.javaType);
|
||||
group = (concatStringsSep "." (take ((length splittedType) - 2) splittedType)) + ".istio.io";
|
||||
kind = removeSuffix "Spec" (last splittedType);
|
||||
version = last (take ((length splittedType) - 1) splittedType);
|
||||
ref = removePrefix "#/definitions/" property."$ref";
|
||||
})
|
||||
(filterAttrs
|
||||
(_name: property:
|
||||
(hasPrefix "me.snowdrop.istio.api" property.javaType)
|
||||
&& hasSuffix "Spec" property.javaType
|
||||
)
|
||||
swagger.properties))
|
||||
++ (mapAttrsToList
|
||||
(_name: property: rec {
|
||||
splittedType = splitString "." (removePrefix "me.snowdrop.istio.mixer." property.javaType);
|
||||
group = "config.istio.io";
|
||||
version = "v1alpha2";
|
||||
kind = head (tail splittedType);
|
||||
ref = removePrefix "#/definitions/" property."$ref";
|
||||
})
|
||||
(filterAttrs
|
||||
(_name: property:
|
||||
(hasPrefix "me.snowdrop.istio.mixer" property.javaType)
|
||||
&& hasSuffix "Spec" property.javaType
|
||||
)
|
||||
swagger.properties));
|
||||
|
||||
swagger = fetchSpecs spec;
|
||||
|
||||
|
|
@ -367,14 +356,14 @@ with lib; let
|
|||
}
|
||||
'';
|
||||
in
|
||||
pkgs.runCommand "istio-gen.nix"
|
||||
{
|
||||
buildInputs = [pkgs.nixpkgs-fmt];
|
||||
} ''
|
||||
cat << 'GENERATED' > ./raw
|
||||
"${generated}"
|
||||
GENERATED
|
||||
pkgs.runCommand "istio-gen.nix"
|
||||
{
|
||||
buildInputs = [ pkgs.nixpkgs-fmt ];
|
||||
} ''
|
||||
cat << 'GENERATED' > ./raw
|
||||
"${generated}"
|
||||
GENERATED
|
||||
|
||||
nixpkgs-fmt ./raw
|
||||
cp ./raw $out
|
||||
''
|
||||
nixpkgs-fmt ./raw
|
||||
cp ./raw $out
|
||||
''
|
||||
|
|
|
|||
|
|
@ -1,9 +1,4 @@
|
|||
{
|
||||
name,
|
||||
pkgs,
|
||||
lib,
|
||||
spec,
|
||||
}:
|
||||
{ name, pkgs, lib, spec }:
|
||||
with lib; let
|
||||
gen = rec {
|
||||
mkMerge = values: ''mkMerge [${concatMapStrings
|
||||
|
|
@ -21,14 +16,9 @@ with lib; let
|
|||
then "null"
|
||||
else builtins.toString value;
|
||||
|
||||
removeEmptyLines = str: concatStringsSep "\n" (filter (l: builtins.match "[[:space:]]*" l != []) (splitString "\n" str));
|
||||
removeEmptyLines = str: concatStringsSep "\n" (filter (l: builtins.match "[[:space:]]*" l != [ ]) (splitString "\n" str));
|
||||
|
||||
mkOption = {
|
||||
description ? null,
|
||||
type ? null,
|
||||
default ? null,
|
||||
apply ? null,
|
||||
}:
|
||||
mkOption = { description ? null, type ? null, default ? null, apply ? null }:
|
||||
removeEmptyLines '' mkOption {
|
||||
${optionalString (description != null) "description = ${builtins.toJSON description};"}
|
||||
${optionalString (type != null) ''type = ${type};''}
|
||||
|
|
@ -52,9 +42,7 @@ with lib; let
|
|||
loaOf = type: "(types.loaOf ${type})";
|
||||
};
|
||||
|
||||
hasTypeMapping = def:
|
||||
hasAttr "type" def
|
||||
&& elem def.type ["string" "integer" "boolean"];
|
||||
hasTypeMapping = def: hasAttr "type" def && elem def.type [ "string" "integer" "boolean" ];
|
||||
|
||||
mergeValuesByKey = mergeKey: ''(mergeValuesByKey "${mergeKey}")'';
|
||||
|
||||
|
|
@ -87,43 +75,42 @@ with lib; let
|
|||
|
||||
refType = attr: head (tail (tail (splitString "/" attr."$ref")));
|
||||
|
||||
compareVersions = ver1: ver2: let
|
||||
getVersion = substring 1 10;
|
||||
splitVersion = v: builtins.splitVersion (getVersion v);
|
||||
isAlpha = v: elem "alpha" (splitVersion v);
|
||||
patchVersion = v:
|
||||
if isAlpha v
|
||||
then ""
|
||||
else if length (splitVersion v) == 1
|
||||
then "${getVersion v}prod"
|
||||
else getVersion v;
|
||||
compareVersions = ver1: ver2:
|
||||
let
|
||||
getVersion = substring 1 10;
|
||||
splitVersion = v: builtins.splitVersion (getVersion v);
|
||||
isAlpha = v: elem "alpha" (splitVersion v);
|
||||
patchVersion = v:
|
||||
if isAlpha v
|
||||
then ""
|
||||
else if length (splitVersion v) == 1
|
||||
then "${getVersion v}prod"
|
||||
else getVersion v;
|
||||
|
||||
v1 = patchVersion ver1;
|
||||
v2 = patchVersion ver2;
|
||||
in
|
||||
v1 = patchVersion ver1;
|
||||
v2 = patchVersion ver2;
|
||||
in
|
||||
builtins.compareVersions v1 v2;
|
||||
|
||||
fixJSON = replaceStrings ["\\u"] ["u"];
|
||||
fixJSON = replaceStrings [ "\\u" ] [ "u" ];
|
||||
|
||||
fetchSpecs = path: builtins.fromJSON (fixJSON (builtins.readFile path));
|
||||
|
||||
genDefinitions = swagger:
|
||||
with gen;
|
||||
mapAttrs
|
||||
(
|
||||
_name: definition:
|
||||
# if $ref is in definition it means it's an alias of other definition
|
||||
if hasAttr "$ref" definition
|
||||
then definitions."${refDefinition definition}"
|
||||
else if !(hasAttr "properties" definition)
|
||||
then {}
|
||||
# in other case it's an actual definition
|
||||
else {
|
||||
options =
|
||||
mapAttrs
|
||||
(
|
||||
propName: property: let
|
||||
isRequired = elem propName (definition.required or []);
|
||||
genDefinitions = swagger: with gen; mapAttrs
|
||||
(_name: definition:
|
||||
# if $ref is in definition it means it's an alias of other definition
|
||||
if hasAttr "$ref" definition
|
||||
then definitions."${refDefinition definition}"
|
||||
else if !(hasAttr "properties" definition)
|
||||
then { }
|
||||
# in other case it's an actual definition
|
||||
else {
|
||||
options =
|
||||
mapAttrs
|
||||
(
|
||||
propName: property:
|
||||
let
|
||||
isRequired = elem propName (definition.required or [ ]);
|
||||
requiredOrNot = type:
|
||||
if isRequired
|
||||
then type
|
||||
|
|
@ -146,43 +133,47 @@ with lib; let
|
|||
# if property has an array type
|
||||
else if property.type == "array"
|
||||
then
|
||||
# if reference is in items it can reference other type of another
|
||||
# definition
|
||||
# if reference is in items it can reference other type of another
|
||||
# definition
|
||||
if hasAttr "$ref" property.items
|
||||
then
|
||||
# if it is a reference to simple type
|
||||
# if it is a reference to simple type
|
||||
if hasTypeMapping swagger.definitions.${refDefinition property.items}
|
||||
then {
|
||||
type = requiredOrNot (types.listOf (mapType swagger.definitions.${refDefinition property.items}.type));
|
||||
}
|
||||
# if a reference is to complex type
|
||||
else
|
||||
# make it an attribute set of submodules if only x-kubernetes-patch-merge-key is present, or
|
||||
# x-kubernetes-patch-merge-key == x-kubernetes-list-map-keys.
|
||||
if (hasAttr "x-kubernetes-patch-merge-key" property) && (!(hasAttr "x-kubernetes-list-map-keys" property) || (property."x-kubernetes-list-map-keys" == [property."x-kubernetes-patch-merge-key"]))
|
||||
then let
|
||||
mergeKey = property."x-kubernetes-patch-merge-key";
|
||||
in {
|
||||
type = requiredOrNot (coerceAttrsOfSubmodulesToListByKey (refDefinition property.items) mergeKey []);
|
||||
apply = attrsToList;
|
||||
}
|
||||
# make it an attribute set of submodules if only x-kubernetes-patch-merge-key is present, or
|
||||
# x-kubernetes-patch-merge-key == x-kubernetes-list-map-keys.
|
||||
if (hasAttr "x-kubernetes-patch-merge-key" property) && (!(hasAttr "x-kubernetes-list-map-keys" property) || (property."x-kubernetes-list-map-keys" == [ property."x-kubernetes-patch-merge-key" ]))
|
||||
then
|
||||
let
|
||||
mergeKey = property."x-kubernetes-patch-merge-key";
|
||||
in
|
||||
{
|
||||
type = requiredOrNot (coerceAttrsOfSubmodulesToListByKey (refDefinition property.items) mergeKey [ ]);
|
||||
apply = attrsToList;
|
||||
}
|
||||
# in other case it's a simple list
|
||||
else
|
||||
# make it an attribute set of submodules if only x-kubernetes-patch-merge-key is present, or
|
||||
# x-kubernetes-patch-merge-key == x-kubernetes-list-map-keys.
|
||||
# make it an attribute set of submodules if only x-kubernetes-patch-merge-key is present, or
|
||||
# x-kubernetes-patch-merge-key == x-kubernetes-list-map-keys.
|
||||
if
|
||||
hasAttr "properties" swagger.definitions.${refDefinition property.items}
|
||||
&& hasAttr "name" swagger.definitions.${refDefinition property.items}.properties
|
||||
then let
|
||||
mergeKey = "name";
|
||||
in {
|
||||
type = requiredOrNot (coerceAttrsOfSubmodulesToListByKey (refDefinition property.items) mergeKey (
|
||||
if hasAttr "x-kubernetes-list-map-keys" property
|
||||
then property."x-kubernetes-list-map-keys"
|
||||
else []
|
||||
));
|
||||
apply = attrsToList;
|
||||
}
|
||||
then
|
||||
let
|
||||
mergeKey = "name";
|
||||
in
|
||||
{
|
||||
type = requiredOrNot (coerceAttrsOfSubmodulesToListByKey (refDefinition property.items) mergeKey (
|
||||
if hasAttr "x-kubernetes-list-map-keys" property
|
||||
then property."x-kubernetes-list-map-keys"
|
||||
else [ ]
|
||||
));
|
||||
apply = attrsToList;
|
||||
}
|
||||
else {
|
||||
type =
|
||||
if (refDefinition property.items) == _name
|
||||
|
|
@ -195,7 +186,7 @@ with lib; let
|
|||
}
|
||||
else if property.type == "object" && hasAttr "additionalProperties" property
|
||||
then
|
||||
# if it is a reference to simple type
|
||||
# if it is a reference to simple type
|
||||
if
|
||||
(
|
||||
hasAttr "$ref" property.additionalProperties
|
||||
|
|
@ -221,63 +212,60 @@ with lib; let
|
|||
type = requiredOrNot (mapType property);
|
||||
};
|
||||
in
|
||||
mkOption ({
|
||||
description = property.description or "";
|
||||
}
|
||||
// optionProperties)
|
||||
)
|
||||
definition.properties;
|
||||
config = let
|
||||
optionalProps =
|
||||
filterAttrs
|
||||
mkOption ({
|
||||
description = property.description or "";
|
||||
}
|
||||
// optionProperties)
|
||||
)
|
||||
definition.properties;
|
||||
config =
|
||||
let
|
||||
optionalProps =
|
||||
filterAttrs
|
||||
(
|
||||
propName: _property:
|
||||
!(elem propName (definition.required or []))
|
||||
!(elem propName (definition.required or [ ]))
|
||||
)
|
||||
definition.properties;
|
||||
in
|
||||
mapAttrs (_name: _property: mkOverride 1002 null) optionalProps;
|
||||
}
|
||||
)
|
||||
swagger.definitions;
|
||||
in
|
||||
mapAttrs (_name: _property: mkOverride 1002 null) optionalProps;
|
||||
}
|
||||
)
|
||||
swagger.definitions;
|
||||
|
||||
mapCharPairs = f: s1: s2:
|
||||
concatStrings (imap0
|
||||
(
|
||||
i: c1:
|
||||
f i c1 (
|
||||
if i >= stringLength s2
|
||||
then ""
|
||||
else elemAt (stringToCharacters s2) i
|
||||
)
|
||||
mapCharPairs = f: s1: s2: concatStrings (imap0
|
||||
(i: c1:
|
||||
f i c1 (
|
||||
if i >= stringLength s2
|
||||
then ""
|
||||
else elemAt (stringToCharacters s2) i
|
||||
)
|
||||
(stringToCharacters s1));
|
||||
)
|
||||
(stringToCharacters s1));
|
||||
|
||||
getAttrName = resource: kind:
|
||||
mapCharPairs
|
||||
(
|
||||
i: c1: c2:
|
||||
if hasPrefix "API" kind && i == 0
|
||||
then "A"
|
||||
else if i == 0
|
||||
then c1
|
||||
else if c2 == "" || (toLower c2) != c1
|
||||
then c1
|
||||
else c2
|
||||
getAttrName = resource: kind: mapCharPairs
|
||||
(i: c1: c2:
|
||||
if hasPrefix "API" kind && i == 0
|
||||
then "A"
|
||||
else if i == 0
|
||||
then c1
|
||||
else if c2 == "" || (toLower c2) != c1
|
||||
then c1
|
||||
else c2
|
||||
)
|
||||
resource
|
||||
kind;
|
||||
|
||||
genResourceTypes = swagger:
|
||||
mapAttrs'
|
||||
(name: path: let
|
||||
ref = refType (head path.post.parameters).schema;
|
||||
group' = path.post."x-kubernetes-group-version-kind".group;
|
||||
version' = path.post."x-kubernetes-group-version-kind".version;
|
||||
kind' = path.post."x-kubernetes-group-version-kind".kind;
|
||||
name' = last (splitString "/" name);
|
||||
attrName = getAttrName name' kind';
|
||||
in
|
||||
genResourceTypes = swagger: mapAttrs'
|
||||
(name: path:
|
||||
let
|
||||
ref = refType (head path.post.parameters).schema;
|
||||
group' = path.post."x-kubernetes-group-version-kind".group;
|
||||
version' = path.post."x-kubernetes-group-version-kind".version;
|
||||
kind' = path.post."x-kubernetes-group-version-kind".kind;
|
||||
name' = last (splitString "/" name);
|
||||
attrName = getAttrName name' kind';
|
||||
in
|
||||
nameValuePair ref {
|
||||
inherit ref attrName;
|
||||
|
||||
|
|
@ -309,37 +297,34 @@ with lib; let
|
|||
})
|
||||
resourceTypes);
|
||||
|
||||
resourcesTypesByKindSortByVersion =
|
||||
mapAttrs
|
||||
(
|
||||
_kind: resourceTypes:
|
||||
reverseList (sort
|
||||
(
|
||||
r1: r2:
|
||||
compareVersions r1.version r2.version > 0
|
||||
)
|
||||
resourceTypes)
|
||||
resourcesTypesByKindSortByVersion = mapAttrs
|
||||
(_kind: resourceTypes:
|
||||
reverseList (sort
|
||||
(
|
||||
r1: r2:
|
||||
compareVersions r1.version r2.version > 0
|
||||
)
|
||||
resourceTypes)
|
||||
)
|
||||
resourceTypesByKind;
|
||||
|
||||
latestResourceTypesByKind =
|
||||
mapAttrs (_kind: last) resourcesTypesByKindSortByVersion;
|
||||
latestResourceTypesByKind = mapAttrs (_kind: last) resourcesTypesByKindSortByVersion;
|
||||
|
||||
genResourceOptions = resource:
|
||||
with gen; let
|
||||
submoduleForDefinition' = definition:
|
||||
submoduleForDefinition
|
||||
definition.ref
|
||||
definition.name
|
||||
definition.kind
|
||||
definition.group
|
||||
definition.version;
|
||||
definition.ref
|
||||
definition.name
|
||||
definition.kind
|
||||
definition.group
|
||||
definition.version;
|
||||
in
|
||||
mkOption {
|
||||
inherit (resource) description;
|
||||
type = types.attrsOf (submoduleForDefinition' resource);
|
||||
default = {};
|
||||
};
|
||||
mkOption {
|
||||
inherit (resource) description;
|
||||
type = types.attrsOf (submoduleForDefinition' resource);
|
||||
default = { };
|
||||
};
|
||||
|
||||
generated = ''
|
||||
# This file was generated with kubenix k8s generator, do not edit
|
||||
|
|
@ -530,14 +515,14 @@ with lib; let
|
|||
}
|
||||
'';
|
||||
in
|
||||
pkgs.runCommand "k8s-${name}-gen.nix"
|
||||
{
|
||||
buildInputs = [pkgs.nixpkgs-fmt];
|
||||
} ''
|
||||
cat << 'GENERATED' > ./raw
|
||||
${generated}
|
||||
GENERATED
|
||||
pkgs.runCommand "k8s-${name}-gen.nix"
|
||||
{
|
||||
buildInputs = [ pkgs.nixpkgs-fmt ];
|
||||
} ''
|
||||
cat << 'GENERATED' > ./raw
|
||||
${generated}
|
||||
GENERATED
|
||||
|
||||
nixpkgs-fmt ./raw
|
||||
cp ./raw $out
|
||||
''
|
||||
nixpkgs-fmt ./raw
|
||||
cp ./raw $out
|
||||
''
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue