SwaggerProvider
SwaggerProvider copied to clipboard
Unable to pass httpClient in Provided Client constructor anymore
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
- Windows 10
- beta-4 (preview package)
- NET5
@sergey-tihon is there any integration test on constructors for SwaggerProvider, or did I do something wrong there?
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
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
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
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.
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...
Thanks a lot 🥇😃 this provider is amazing!!!
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 ?
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'
got the same error on dotnet build in ionide
and the constructor hint... also showing something not right in generated type, only 1 weird constructor
provided builds fine (as reported also from VS2019) though, with latest preview-4 ,
but the problem is in other assembly using it see that above weird error, the new generated type constructor makes no sense...
Please try SwaggerProvider 1.0.0-beta5 I reverted optional parameters in provided actor's - it may help with intellisence
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...
@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
@jkone27 report it please, it is definitely looks weird.
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
@jkone27 so can this be closed then?