You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
this breaks when I attempt to call this endpoint with following exception
System.AggregateException: One or more errors occurred. (The input does not contain any JSON tokens. Expected the input to start with a valid JSON token, when isFinalBlock is true. Path: $ | LineNumber: 0 | BytePositionInLine: 0.)
---> System.Text.Json.JsonException: The input does not contain any JSON tokens. Expected the input to start with a valid JSON token, when isFinalBlock is true. Path: $ | LineNumber: 0 | BytePositionInLine: 0.
---> System.Text.Json.JsonReaderException: The input does not contain any JSON tokens. Expected the input to start with a valid JSON token, when isFinalBlock is true. LineNumber: 0 | BytePositionInLine: 0.
Known workarounds
I did not find any workarounds for this.
Affected Type Providers
SwaggerClientProvider
OpenApiClientProvider
Related information
Operating system
Branch
.NET Runtime, CoreCLR or Mono Version
Performance information, links to performance testing scripts
I clone repo and after running build.cmd receive following error
SwaggerProvider.Runtime failed with 1 error(s) (17.0s)
C:\SwaggerProvider\paket-files\fsprojects\FSharp.TypeProviders.SDK\src\ProvidedTypes.fs(3224,7): error FS0842: This attribute is not valid for use on this language element
This is around
[<AutoOpen>][<Struct>]typeILTableName(idx: int)=member__.Index= idx
static memberFromIndex n = ILTableName n
Okay. I take a deeper look, and seems to be issue arise in following way
type WebAPI2 = OpenApiClientProvider<"http://localhost:5000/swagger/v1/swagger.json", IgnoreOperationId=true>
Notice that I pass Swagger document to OpenApiClient. I cannot make test case for this since there other errors when compiling Swagger schema
C:\SwaggerProvider\tests\SwaggerProvider.ProviderTests\v3\Swashbuckle.ReturnControllers.Tests.fs(17,16): error FS3033: The type provider 'SwaggerProvider.OpenApiClientTypeProvider' reported an error: Cannot compile object 'GetApiUpdateEnum_x' when schema is 'null'
C:\SwaggerProvider\tests\SwaggerProvider.ProviderTests\v3\Swashbuckle.ReturnControllers.Tests.fs(17,16): error FS3033: The type provider 'SwaggerProvider.OpenApiClientTypeProvider' reported an error: Cannot compile object 'GetApiUpdateEnum_x' when schema is 'null'
C:\SwaggerProvider\tests\SwaggerProvider.ProviderTests\v3\Swashbuckle.ReturnControllers.Tests.fs(33,13): error FS0039: The type 'WebAPI2' does not define the field, constructor or member 'Client'.
C:\SwaggerProvider\tests\SwaggerProvider.ProviderTests\v3\Swashbuckle.NoContentControllers.Tests.fs(16,21): error FS0039: The type 'Object' does not define the field, constructor or member 'PostApiNoContent'.
It currently appears to work when the server returns 200, but throws a json exception for the 204 case (where the response is empty so there is no json to parse).
I'm not sure what it can do other than make the return type nullable or an option or something like that and return None/null for the 204 case, but I don't think trying to deserialize the json in a 204 case is right?
I've seen similar issues in other client generators (e.g. RicoSuter/NSwag#4853) though maybe some of those throw an exception that contains the status code rather than a json error, so at least that can be special cased even if it's not an ideal approach)
Activity
sergey-tihon commentedon Jan 6, 2025
I think the bug somewhere here
https://github.com/fsprojects/SwaggerProvider/blob/master/src/SwaggerProvider.DesignTime/v3/OperationCompiler.fs#L156-L168
we see that API produces
jsonand infers some response type and then later try to parse json from empty response body.Would you like to conduct test for this use case?
kant2002 commentedon Jan 7, 2025
I clone repo and after running build.cmd receive following error
This is around
kant2002 commentedon Jan 7, 2025
Okay. I take a deeper look, and seems to be issue arise in following way
Notice that I pass Swagger document to OpenApiClient. I cannot make test case for this since there other errors when compiling Swagger schema
sergey-tihon commentedon Jan 7, 2025
This is strange, The Windows CI build was ok yesterday
https://github.com/fsprojects/SwaggerProvider/actions/runs/12639820322/job/35218945655
Why? I remember that swagger support by
Microsoft.OpenApi.Readerswas quite limited.Yesterday I also added API for NoContent and tests. They works.
kant2002 commentedon Jan 7, 2025
Why? Because of my mistake :) anyway it was confusing experience.
Numpsy commentedon Mar 11, 2026
Q. What should happen if you have an endpoint that can return either 200 or 204 under different circumstances?
e.g if you have an OpenApi spec like
It currently appears to work when the server returns 200, but throws a json exception for the 204 case (where the response is empty so there is no json to parse).
I'm not sure what it can do other than make the return type nullable or an option or something like that and return None/null for the 204 case, but I don't think trying to deserialize the json in a 204 case is right?
I've seen similar issues in other client generators (e.g. RicoSuter/NSwag#4853) though maybe some of those throw an exception that contains the status code rather than a json error, so at least that can be special cased even if it's not an ideal approach)