Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSONSchemaProps.dhall references itself (Cyclic import) #47

Closed
jvanbruegge opened this issue Feb 16, 2019 · 3 comments · Fixed by #57
Closed

JSONSchemaProps.dhall references itself (Cyclic import) #47

jvanbruegge opened this issue Feb 16, 2019 · 3 comments · Fixed by #57

Comments

@jvanbruegge
Copy link
Contributor

When trying to create a custom resource definition, dhall errors with

↳ ./../dhall-kubernetes/default/io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1beta1.CustomResourceDefinition.dhall
  ↳ ./../dhall-kubernetes/types/io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1beta1.CustomResourceDefinitionSpec.dhall
    ↳ ./../dhall-kubernetes/types/io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1beta1.CustomResourceValidation.dhall
      ↳ ./../dhall-kubernetes/types/io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1beta1.JSONSchemaProps.dhall

Cyclic import: ./io.k8s.apiextensions-apiserver.pkg.apis.apiextensions.v1beta1.JSONSchemaProps.dhall

The reason is that JSONSchemaProps references itself (at least I think that's the issue)

@jvanbruegge
Copy link
Contributor Author

Could possibly be fixed by copying the file, remove all fields that reference itself and use the copy in the place of the self-reference in the original file. So you would have 1 layer of recursion and not infinite

@jvanbruegge
Copy link
Contributor Author

jvanbruegge commented Feb 16, 2019

For reference, my quick&dirty fix: jvanbruegge@110e5e4 works as intented

@f-f
Copy link
Member

f-f commented Feb 16, 2019

@jvanbruegge yes, this is a known bug and the reason is indeed the cyclic imports. In fact we do run tests on all the generated Dhall definitions, and the ones you stumbled on are the only ones that don't compile

Now, I don't have a "good" fix for this, so any of your fixes (0 or 1 levels of recursion) would be good 👍 (an imperfect definition that compiles is better than a perfect one that doesn't)

@f-f f-f mentioned this issue Apr 1, 2019
12 tasks
f-f added a commit that referenced this issue Apr 2, 2019
@f-f f-f closed this as completed in #57 May 1, 2019
f-f added a commit that referenced this issue May 1, 2019
This ports the conversion script from Python to Haskell (fix #7)

The main reasons for this port are that:
- the Python script was really hard to maintain for reasons like 
  "converting from Swagger to Dhall is interleaved with string formatting"
- in Haskell we can use the dhall library to generate always syntactically 
  correct Dhall AST. It's also much easier to keep an eye on correctness, 
  because types and pattern matching. It also forces us to deal with things
  like cyclic imports from the get go.

Things happening here:
- remove the `api` folder, removing the difference between "raw api" and "nice api"
- move defaults from `default` to `defaults` folder, as it is in `dhall-nethack`
- transition to the new syntax for `Optional` (fix #49)
- add `types.dhall` and `defaults.dhall`, so that one can now easily "pin a version"
  by just importing these two records at a specific commit/tag. They also make it really
  easy to access objects, e.g.
  `let types = https://raw.githubusercontent... sha256:... in types.Deployment`
- also add typesUnion.dhall (fix #54), so one is able to send to Kubernetes different
  objects in the same stream. This is also documented in the README
- defaults are resolved recursively (fix #46): if there's an import of a "nullable" record,
  then it's not marked as Optional, making merging objects much easier
- default objects are not lambdas anymore, and instead they just don't include the required
  fields (that is, the ones that are not nullable records), as suggested in dhall-lang/dhall-lang#382
- for objects that are simple types we used to generate a simple lambda
  `\(a : Text) -> a` as a default, now we just don't generate a default (e.g. see
  `io.k8s.apimachinery.pkg.apis.meta.v1.Time`)
- autoformat all generated Dhall code
- remove cyclic imports (fix #47)
- update to dhall-1.22 and dhall-json-1.2.8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants