DEV Community

Discussion on: Opine Tutorial Part 1: Express for Deno

Collapse
 
iampeters profile image
Peters Chikezie • Edited

this is awesome. looks very easy to use. thanks

Collapse
 
iampeters profile image
Peters Chikezie

I tried to use your example to get it to work with my code but I got this error

NotFound: No such file or directory (os error 2)
at unwrapResponse ($deno$/ops/dispatch_json.ts:42:11)
at Object.sendSync ($deno$/ops/dispatch_json.ts:69:10)
at Object.openSync ($deno$/ops/fs/open.ts:22:10)
at Object.openSync ($deno$/files.ts:28:15)
at Object.readFileSync ($deno$/read_file.ts:6:16)
at readFileStrSync (read_file_str.ts:18:30)
at parseApiFile (parseApiFile.ts:13:23)
at getSpecificationObject (getSpecificationObject.ts:16:24)
at swaggerDoc (index.ts:23:33)
at server.ts:41:21
No such file or directory (os error 2)
error: Uncaught Error: NotFound: No such file or directory (os error 2)
throw new Error(err);
^
at swaggerDoc (index.ts:38:11)
at server.ts:41:21
[denon] app crashed - waiting for file changes before starting ...

here's the repo

github.com/iampeters/deno-opine/bl...

Collapse
 
craigmorten profile image
Craig Morten • Edited

Hey Peters πŸ˜„ I fell into the same problems initially as well, the key is around apis array which you provide in the options object that is then passed to the swaggerDoc() method.

Unfortunately the swagger doc module doesn't perform auto discovery of files, you need to list them in the array. You also need to take care with the path used, as it expects the path to be relative to the current working directory where the deno run command is executed.

Looking at your example it looks like you still have references to Opine example files (REF: github.com/iampeters/deno-opine/bl...). Hopefully amending this array to mirror your repo should fix your problem. E.g. providing ./server.ts, and your paths under ./src/.

Thread Thread
 
iampeters profile image
Peters Chikezie

thanks for this. I have been able to get it to work. However, is there a swagger-UI that can be used in place of this JSON that is being served? with express, I can use swagger-UI-express and swagger-jsdoc to serve HTML to users. I am just curious.

Thread Thread
 
craigmorten profile image
Craig Morten

Unfortunately afaik this particular module is just for swagger JSON generation and doesn’t support the swagger UI as far as I know.

I don’t think there is a Deno module that can do this just yet - I might look to port the swagger UI node module so this can be done (unless someone has already done it!)

If you find something that can do it in Deno, please let me know!

Thread Thread
 
iampeters profile image
Peters Chikezie

oh ok. thanks. May I ask how you port these modules, I would love to learn so I can port some for myself 😜

Thread Thread
 
craigmorten profile image
Craig Morten

That would awesome for you to get involved! It depends very much on the module you wish to port.

  1. If it is already ESM and typescript, then you can just import it directly using the raw url!
  2. If it has no dependency on Node APIs in its code or subdeps then you can use JSPM CDN to import.
  3. Otherwise you need to port it - there are some tools to help, the rest is manually converting commonjs to ESM and swapping out Node methods for Deno ones.

Also check out my post on Reddit reddit.com/r/Deno/comments/h9ejsk/... for some more resources.

I might look to write a post on it if think would be useful?

Thread Thread
 
iampeters profile image
Peters Chikezie

thanks that would be awesome. I have been looking for a way to contribute to open-source but don't know where to start. You have been a great help so far.

Thread Thread
 
craigmorten profile image
Craig Morten

Generally it's a case of "I need to do a thing", seeing if it exists. If not then go code it and put it out there! If it helps you it'll help others πŸ˜„.

Check out things like firsttimersonly.com/ as well - there is a whole community worth of projects and issues geared towards helping people get involved in Open Source.