Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

204 returning empty body throw #252

Open
1 of 2 tasks
kant2002 opened this issue Dec 28, 2024 · 5 comments
Open
1 of 2 tasks

204 returning empty body throw #252

kant2002 opened this issue Dec 28, 2024 · 5 comments

Comments

@kant2002
Copy link

Description

I have API method which described like this

  "paths": {
    "/auth": {
      "put": {
        "operationId": "CreateAuth",
        "consumes": [
          "application/json"
        ],
        "produces": [
          "application/json"
        ],
        "parameters": [
          {
            "name": "body",
            "in": "body",
            "schema": {
              "$ref": "#/definitions/CreateAuth"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "No Content"
          }
        },
        "deprecated": false
      }
....

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
@sergey-tihon
Copy link
Member

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 json and 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
Copy link
Author

kant2002 commented Jan 7, 2025

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>]
type ILTableName(idx: int) =
    member __.Index = idx
    static member FromIndex n = ILTableName n

@kant2002
Copy link
Author

kant2002 commented Jan 7, 2025

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'.

@sergey-tihon
Copy link
Member

error FS0842: This attribute is not valid for use on this language element

This is strange, The Windows CI build was ok yesterday
https://github.com/fsprojects/SwaggerProvider/actions/runs/12639820322/job/35218945655

Notice that I pass Swagger document to OpenApiClient.

Why? I remember that swagger support by Microsoft.OpenApi.Readers was quite limited.

Yesterday I also added API for NoContent and tests. They works.

@kant2002
Copy link
Author

kant2002 commented Jan 7, 2025

Why? Because of my mistake :) anyway it was confusing experience.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants