fsprojects / SwaggerProvider

F# generative Type Provider for Swagger

Home Page:https://fsprojects.github.io/SwaggerProvider/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

jkone27 opened this issue · comments

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

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:

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"

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