Support 'format' key from the swagger schema (#28)

Fix #12 by introducing a `< Int : Natural | String : Text >` Union for the "int-or-string" format key.
This commit is contained in:
Fabrizio Ferrai 2018-08-06 17:13:33 +02:00 committed by GitHub
parent 4a7f02cd0d
commit 4fec2167a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 23 additions and 11 deletions

View File

@ -168,6 +168,7 @@ in let Ingress = ../types/io.k8s.api.extensions.v1beta1.Ingress.dhall
in let defaultIngress = ../default/io.k8s.api.extensions.v1beta1.Ingress.dhall
in let defaultMeta = ../default/io.k8s.apimachinery.pkg.apis.meta.v1.ObjectMeta.dhall
in let defaultSpec = ../default/io.k8s.api.extensions.v1beta1.IngressSpec.dhall
in let IntOrString = ../default/io.k8s.apimachinery.pkg.util.intstr.IntOrString.dhall
-- Our Service type
in let Service = ./Service.dhall
@ -183,7 +184,7 @@ in let makeRule = \(service : Service) ->
{ host = Some Text service.host
, http = Some RuleVal
{ paths = [ { backend = { serviceName = service.name
, servicePort = "80"
, servicePort = IntOrString.Int 80
}
, path = None Text
}]}}
@ -244,13 +245,13 @@ spec:
- http:
paths:
- backend:
servicePort: '80'
servicePort: 80
serviceName: foo
host: foo.example.com
- http:
paths:
- backend:
servicePort: '80'
servicePort: 80
serviceName: default
host: default.example.com
tls:

View File

@ -45,6 +45,9 @@ def build_type(schema, path_prefix, schema_name=None):
return '(List {mapKey : Text, mapValue : Text})'
elif typ == 'array':
return 'List {}'.format(build_type(schema['items'], path_prefix))
# Fix for the funny format parameters they use in Kube
elif typ == 'string' and 'format' in schema and schema['format'] == 'int-or-string':
return '< Int : Natural | String : Text >'
else:
return {
'string' : 'Text',
@ -131,7 +134,13 @@ def main():
f.write('{}\n'.format(build_type(modelSpec, '.', modelName)))
with open('default/' + modelName + '.dhall', 'w') as f:
if 'type' in modelSpec:
f.write('\(a : {}) -> a\n'.format(build_type(modelSpec, '../types')))
typ = build_type(modelSpec, '../types')
# In case we have a union, we make the constructors for it
if typ[0] == '<':
f.write('constructors {}\n'.format(typ))
# Otherwise we just output the identity
else:
f.write('\(a : {}) -> a\n'.format(typ))
elif '$ref' in modelSpec:
path = schema_path_from_ref('.', modelSpec['$ref'])
f.write('{}\n'.format(path))
@ -145,8 +154,9 @@ def main():
resource_data = get_static_data(modelSpec)
param_names = required - set(resource_data.keys())
# If there's any required props, we make it a lambda
if len([k for k in properties if k in required]) > 0:
# If there's multiple required props, we make it a lambda
requiredProps = [k for k in properties if k in required]
if len(requiredProps) > 0:
params = ['{} : ({})'.format(labelize(propName), build_type(propVal, '../types'))
for propName, propVal in properties.items()
if propName in param_names]

View File

@ -1 +1 @@
\(a : Text) -> a
constructors < Int : Natural | String : Text >

View File

@ -12,6 +12,7 @@ in let Ingress = ../types/io.k8s.api.extensions.v1beta1.Ingress.dhall
in let defaultIngress = ../default/io.k8s.api.extensions.v1beta1.Ingress.dhall
in let defaultMeta = ../default/io.k8s.apimachinery.pkg.apis.meta.v1.ObjectMeta.dhall
in let defaultSpec = ../default/io.k8s.api.extensions.v1beta1.IngressSpec.dhall
in let IntOrString = ../default/io.k8s.apimachinery.pkg.util.intstr.IntOrString.dhall
-- Our Service type
in let Service = ./Service.dhall
@ -27,7 +28,7 @@ in let makeRule = \(service : Service) ->
{ host = Some Text service.host
, http = Some RuleVal
{ paths = [ { backend = { serviceName = service.name
, servicePort = "80"
, servicePort = IntOrString.Int 80
}
, path = None Text
}]}}

View File

@ -5,13 +5,13 @@ spec:
- http:
paths:
- backend:
servicePort: '80'
servicePort: 80
serviceName: foo
host: foo.example.com
- http:
paths:
- backend:
servicePort: '80'
servicePort: 80
serviceName: default
host: default.example.com
tls:

View File

@ -1 +1 @@
Text
< Int : Natural | String : Text >