rstudio / plumber

Turn your R code into a web API.
https://www.rplumber.io
Other
1.38k stars 256 forks source link

Generate plumber stub file from openapi yaml #508

Open schloerke opened 4 years ago

schloerke commented 4 years ago

cc @krlmlr

Related: https://github.com/rstudio/plumber/issues/354

mcjudd commented 4 years ago

Hello, just curious as to if/where you're tracking progress on the second task above (i.e., "produce a stub plumber file given the open api file"). Would love to see plumber support a workflow where the OpenAPI spec is designed first, then plumber server stubs are generated a la Swagger Codegen. Many thanks!

schloerke commented 4 years ago

cc @blairj09

schloerke commented 4 years ago

@mcjudd Last time I looked at the Swagger Codegen, they were producing functions via R6.

Integrating with Swagger Codegen would introduce a very external dependency. I am hoping we will be able to produce this within plumber with native R.

meztez commented 4 years ago

A reverse parseBlock? I'll think about it while generalizing lines parsing. So each block (endpoint) has a from and to open api definition. What I am afraid is that plumber does not fully support openapi entire definition. You would obviously lose some details if you used unsupported tags. Also types are not quite the same.

I agree it should be done internally. Now comes the hardest part. Pick a function name

I kind of like jsonlite naming.

fromOpenAPI({openapi.json})
toOpenAPI({router})
schloerke commented 4 years ago

@meztez fromOpenAPI and toOpenAPI sound great to me!

Goal:

  1. Start with a fully defined plumber.R
  2. Produce an openapi spec
  3. Produce a shell plumber.R file
  4. Produce the same openapi spec as in step 2

If we can loop back between steps 3 and 4, I'd call it a success

meztez commented 3 years ago

@blairj09 I'm stuck on this one trying to dereference input OpenApi specification. https://swagger.io/docs/specification/using-ref/. Is it something you have tackled before?

I'm not sure this should be a problem solved by plumber as it a more general feature.