fsprojects / SwaggerProvider

F# generative Type Provider for Swagger
https://fsprojects.github.io/SwaggerProvider/
The Unlicense
262 stars 58 forks source link

Unable to pass httpClient in Provided Client constructor anymore #184

Closed jkone27 closed 1 year ago

jkone27 commented 3 years ago

Description

error FS0001: This expression was expected to have type 'Text.Json.JsonSerializerOptions' but here has type 'HttpClient'

and also trying with empty constructor as well..

Severity Code Description Project File Line Suppression State Error FS3033 The type provider 'SwaggerProvider.SwaggerTypeProvider' reported an error: Constructor 'Void .ctor(System.Net.Http.HttpClient)' not found in type 'tgt type Swagger.ProvidedApiClientBase'. This constructor may be missing in the types available in the target assemblies. Travix.Mockery.Provided C:\Git\travix.mockery\src\Acme.Mockery.Provided\ProvidedTypes.fs 12 Active

Repro steps

let client = new ProvidedTypes.Enosis.Client(httpClient)

try to assign httpClient to a generated provided client from the constructor

Expected behavior

I can still use the same signature constructor as before, passing httpClient

Actual behavior

The constructor doesnt have that public signature anymore

Known workarounds

No known workarounds..

Related information

jkone27 commented 3 years ago

@sergey-tihon is there any integration test on constructors for SwaggerProvider, or did I do something wrong there?

sergey-tihon commented 3 years ago

Sure, this project is integration tests only https://github.com/fsprojects/SwaggerProvider/tree/master/tests/SwaggerProvider.ProviderTests and here is the execution point https://github.com/fsprojects/SwaggerProvider/blob/master/build.fsx#L254

sergey-tihon commented 3 years ago

It is quite strange ... there are multiple ctors for provided client.

can you please try FSI?

#r "nuget: SwaggerProvider, 1.0.0-beta4"

let [<Literal>] Schema = "https://petstore.swagger.io/v2/swagger.json"
type PetStore = SwaggerProvider.OpenApiClientProvider<Schema>

let httpClient = new System.Net.Http.HttpClient(BaseAddress=System.Uri("https://petstore.swagger.io/v2/"))
let client = PetStore.Client(httpClient)

client.GetInventory()
|> Async.AwaitTask
|> Async.RunSynchronously
|> printfn "%O"

I hope it works

image
jkone27 commented 3 years ago

I am not using open api client provider but the swagger provider as I need it to parse an older swagger quite big spec, will try as you suggested

sergey-tihon commented 3 years ago

OpenApiClientProvider support v2 and v3 schemas, it uses different schema parser that more sensitive for spec compliance, but it may work for you as well and definitely worth to try.

jkone27 commented 3 years ago

I have tried already OpenApiClientProvider before , that's why i had to fallback to the old one, But I will give it a new try, thanks for suggesting. 👍

Ps, my error is in VS, I am running this in some integ tests which need to run from VS, if its a visual studio bug only, maybe I could also file it there...

image

Thanks a lot 🥇😃 this provider is amazing!!!

jkone27 commented 3 years ago

this is the error i get if i try to switch to OpenApiClientProvider

error FS3033: The type provider 'SwaggerProvider.OpenApiClientTypeProvider' reported an error: 

Schema parse errors:The key 'ACME.Common.Models.DataSet[ACME.Configuration.Models.Language]' 
in 'schemas' of components 
MUST match the regular expression 
'^[a-zA-Z0-9\.\-_]+$'. 

and many more like it, wheras in old swagger provider used to work

i am now trying replace the open and closed square brackets with dots, to see if its a workaround... but i guess the schema shouldn't fail parsing with those chars, so seems a parsing error @sergey-tihon ?

jkone27 commented 3 years ago

After fixing that parsing error, manually adjusting the openapi spec, i still got the same constructor not available error, as the above screenshot. Type provider project completed the build successfully.. So the issue is shared also with the newer OpenApiClientProvider

Build started...
Restored C:\Git\ACME.mockery\test\ACME.Mockery.UnitTests\ACME.Mockery.UnitTests.fsproj (in 453 ms).
Restored C:\Git\ACME.mockery\test\ACME.Mockery.IntegrationTests\ACME.Mockery.IntegrationTests.fsproj (in 1,11 sec).
Restored C:\Git\ACME.mockery\src\ACME.Mockery.WebService\ACME.Mockery.WebService.fsproj (in 1,38 sec).
1>------ Build started: Project: ACME.Mockery.Provided, Configuration: Debug Any CPU ------
1>ACME.Mockery.Provided -> C:\Git\ACME.mockery\src\ACME.Mockery.Provided\bin\Debug\net5.0\ACME.Mockery.Provided.dll
2>------ Build started: Project: ACME.Mockery.WebService, Configuration: Debug Any CPU ------
3>------ Build started: Project: ACME.Mockery.UnitTests, Configuration: Debug Any CPU ------
3>ACME.Mockery.UnitTests -> C:\Git\ACME.mockery\test\ACME.Mockery.UnitTests\bin\Debug\net5.0\ACME.Mockery.UnitTests.dll
2>C:\Git\ACME.mockery\src\ACME.Mockery.WebService\Services\EnosisApiClient.fs(16,44): 
error FS0001: This expression was expected to have type    'Text.Json.JsonSerializerOptions'    <<<<<<< this is weird !??????
but here has type    'HttpClient'
jkone27 commented 3 years ago

got the same error on dotnet build in ionide image

and the constructor hint... also showing something not right in generated type, only 1 weird constructor image

provided builds fine (as reported also from VS2019) though, with latest preview-4 , image

but the problem is in other assembly using it see that above weird error, the new generated type constructor makes no sense... image

sergey-tihon commented 3 years ago

Please try SwaggerProvider 1.0.0-beta5 I reverted optional parameters in provided actor's - it may help with intellisence

jkone27 commented 3 years ago

it works now after cleaning all and reopening a few times, it builds fine. Thanks a lot @sergey-tihon !! 👍 👍 🥇 in visual studio is still a bit challenging to work with TP though... wonder if Microsoft guys could put some more effort there on type providers battle testing. Still got red squiggles all over the place...

jkone27 commented 3 years ago

@sergey-tihon I am also submitting this to microsoft visualstudio team if they can do anything, if by chance you want to try it out, I managed to reproduce the bug: https://github.com/jkone27/test-broken. Still very mysterious

sergey-tihon commented 3 years ago

@jkone27 report it please, it is definitely looks weird.

jkone27 commented 3 years ago

A regression was spotted related to ref proj with type providers ! Should be merged in now, prob will go in next vs2019 update I suppose... 🥳

https://github.com/dotnet/fsharp/issues/11771

xperiandri commented 2 years ago

@jkone27 so can this be closed then?