FSharp.Data icon indicating copy to clipboard operation
FSharp.Data copied to clipboard

Relative paths and external loading on library usage

Open Thorium opened this issue 1 year ago • 2 comments

I would like to keep 3rd party data-structures of JSON / XML files (samples) in separate files, so that e.g. the intellisense of those files is easily checked.

So I like using F# data with, great:

// Library 1 (a dll):
FSharp.Data.JsonProvider<"json-samples/whateverService.json", SampleIsList = true>
//...logic to use the types.

// Root project (e.g. myprogram.exe): Project reference (or NuGet) to Library 1.

However, when multiple F# projects exist, e.g., via separate NuGet libraries or separate F# dlls, it's really unclear (on compile-time) what the relative path is pointing to.

So it seems this "json-samples"-folder should be included in all the root level programs, while my expectation would be that it only points to the library of actual source code above (Library1). FSharp.Data is a generative provider. Wouldn't it be enough to generate the types on the compilation of Library1, then embed them there, and never spend resources to regenerate them again (on design-time and compilation of "root programs")?

Thorium avatar Dec 11 '24 11:12 Thorium

Another question on usage in external libraries: I don't want user of my library to suffer the high memory load of VS IDE when using a typeprovider. So would it help to try to hide FSharp.Data provider to internal by something like this:

type internal serviceResponseRaw = FSharp.Data.JsonProvider<"...", SampleIsList = true>
type serviceResponse = serviceResponseRaw.Root
let myPublicLibraryMethod() : serviceResponse = 
   serviceResponseRaw.Parse(...) 

Thorium avatar Jan 10 '25 09:01 Thorium

Ok, the static parameter EmbeddedResource seems to be to solve the path issue.

Thorium avatar Jun 06 '25 17:06 Thorium