bterlson / cadl-rdfs

A cadl to rdfs emitter
0 stars 0 forks source link

Enums #12

Closed mspaulik closed 1 year ago

mspaulik commented 1 year ago

@bterlson Pii custom decorator still does not work I believe. Could you have a look into that and I am happy to merge then?

bterlson commented 1 year ago

@mspaulik I updated everything to use the latest cadl. I'm not sure what version you're using over there, but what's here should work with 0.37.x and above. I don't think I regressed any functionality, can you take a look and see? You will need to npm install after you pull the changes.

There are I think two notable changes in the new versions of Cadl since this package was authored:

  1. extern dec declarations, see rdf.cadl for an example. This gives you nice intellisense and makes validation easier: image
  2. Introduction of scalar - previously, types like integers were just models. Now they are scalars, which actually more closely aligns with how RDF works and so I think this was overall a simplification.

There were a few other modifications I made to remove usage of deprecated APIs. Anyway, try it out and let me know what you think.

mspaulik commented 1 year ago

Hey @bterlson

I did look over - everything makes sense. Thanks!

Just maybe one thing until we merge this PR: I seem to be unable to specify @ispii decorator without providing value (true or false). I remember you saying that once this line is written like that context.call($extension, target, "x-ms-pii", isPii ?? true); , we should be able to use decorator without passing any values.

However, I am still getting this issue : Expected 2 arguments, but got 1.Cadl(invalid-argument-count) for this model: @isPii model Person { name: string; color: Colors; }

mspaulik commented 1 year ago

Hey @bterlson ,

One more question regarding cadl-project.yaml. How do you specify the output folder?

Because if I dont have "cadl-output" folder manually created before running emitter, I am getting this error: _Unhandled promise rejection! Internal compiler error! File issue at https://github.com/microsoft/cadl

[Error: ENOENT: no such file or directory, open 'C:\Users\Administrator\Desktop\cadl-rdf\cadl-rdfs\cadl-output\models.ttl'] { errno: -4058, code: 'ENOENT', syscall: 'open', path: 'C:\Users\Administrator\Desktop\cadl-rdf\cadl-rdfs\cadl-output\models.ttl' }_

However, if I create "cadl-output" folder - the emitter puts the result successfully in there.

So, I guess, we need some extra line in cadl-project.yaml to handle this? Thanks!

bterlson commented 1 year ago

You can use the emitFile function from the compiler, and it will handle creating the parent directories for you. It looks something like:

import  { emitFile } from "@cadl-lang/compiler";
await emitFile(program, { path: "cadl-output/whatever.rdf", content: "...." });
bterlson commented 1 year ago

Hmm, I can't repro the issue you point out with @isPii. If I check out this branch and build, the sample.cadl file emits the expected output... Can you give me more precise repro steps or maybe double-check that you were checking against the latest code in this branch? Might try starting from a clean repo also, in case there are stale things sitting around.

mspaulik commented 1 year ago

Hey @bterlson ,

I ran again isPii decorator - all works fine now, I probably did not compile index.ts correctly before. We should be able to merge now?