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

Wrong return type generated by provider, is unit, instead the openapi spec declares a default return type #219

Closed
1 task done
jkone27 opened this issue Apr 5, 2023 · 3 comments · Fixed by #223
Closed
1 task done

Comments

@jkone27
Copy link
Contributor

jkone27 commented Apr 5, 2023

Description

Wrong return type generated by provider, is unit, instead the openapi spec declares a default return type

Repro steps

Please provide the steps required to reproduce the problem

  1. Type provider type definition with parameters :
// in any .fsx script

#r "nuget:SwaggerProvider"
open SwaggerProvider
open System.Threading.Tasks

[<Literal>]
let refundOpenapi = 
    "https://developers.trip.com/flight/docs/distributor-refund-service/openapi.v1.7.en-US.yaml"

type TripRefundProvider = OpenApiClientProvider<refundOpenapi>

[<Literal>]
let orderOpenapi =
    "https://developers.trip.com/flight/docs/distributor-order-service/openapi.v1.7.en-US.yaml"

type TripOrderProvider = OpenApiClientProvider<orderOpenapi>


let refundClient = TripRefundProvider.Client()

let orderClient = TripOrderProvider.Client()

let getOrderDetails orderId = 
    task {

        let orderDetailRequest = 
            new TripOrderProvider.QueryOrderDetailRequest(
                orderId, 
                languageCode = "en-US"
            )

        let! order = orderClient.QueryOrderDetail orderDetailRequest
        
        order // unit! wrong this should be OrderDetailResponse type, also according to openapi spec
}
  1. Sample schema or relevant schema part :
    https://developers.trip.com/flight/docs/distributor-order-service/?lang=en-US
    : https://developers.trip.com/flight/docs/distributor-refund-service/openapi.v1.7.en-US.yaml

Expected behavior

I should see the correct return type in generated api client, not unit.

 QueryOrderDetailResponse:
      description: |
        QueryOrderDetail's response.
      content:
        application/json:
          examples:
            success:
              summary: "success"
              description: |
                success response
              externalValue: "../distributor-order-service/json/QueryOrderDetail-Response.json"
          schema:
            description: |
              QueryOrderDetail's response.
            $ref: "#/components/schemas/QueryOrderDetailResponse"

Actual behavior

the generated client has unit type.

Known workarounds

Not known

Affected Type Providers

  • [? ] SwaggerClientProvider (haven't tried)
  • OpenApiClientProvider

Related information

  • macos - intel chip
  • latest public released package
  • .NET 7
@sergey-tihon
Copy link
Member

externalValue is not supported at the moment, there is no way to resolve schema parts defined in multiple files, download them form somewhere and combine into one full schema.

Like if your case, yaml schema reference some json files with relative path.

Related discussions:

@jkone27
Copy link
Contributor Author

jkone27 commented Apr 14, 2023

can we maybe parse schema before examples node?
and ignore if there is errors in examples node...

         examples:
            success:
              summary: "success"
              description: |
                success response
              externalValue: "../distributor-order-service/json/QueryOrderDetail-Response.json"
          schema: // THIS PART SHOULD STILL BE PARSED DOESNT DEPEND ON EXTERNAL VALUES
            description: |
              QueryOrderDetail's response.
            $ref: "#/components/schemas/QueryOrderDetailResponse"

@sergey-tihon
Copy link
Member

OpenApiClientProvider uses Microsoft.OpenApi to parse schema and as far as I know does not use examples node at all, my bad, sorry.

We are looking for a 20x status code that does not support default as the responses. If I am right then it should be easy to fix somewhere here - https://github.com/fsprojects/SwaggerProvider/blob/master/src/SwaggerProvider.DesignTime/v3/OperationCompiler.fs#L158-L162 ...

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

Successfully merging a pull request may close this issue.

2 participants