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

Migrating to System.Text.Json #176

Merged
merged 16 commits into from
Jan 29, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 12 additions & 24 deletions src/SwaggerProvider.DesignTime/v2/OperationCompiler.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ open SwaggerProvider.Internal.v2.Parser.Schema
open Swagger.Internal

open System
open System.Collections.Generic
open System.Net.Http
open System.Text.Json
open System.Text.RegularExpressions

open Microsoft.FSharp.Quotations
open Microsoft.FSharp.Quotations.ExprShape
open System.Text.Json
open System.Text.RegularExpressions
open System.Net.Http
open System.Collections.Generic
open SwaggerProvider.Internal
open Swagger
open Swagger.Internal
Expand Down Expand Up @@ -256,30 +256,18 @@ type OperationCompiler (schema:SwaggerObject, defCompiler:DefinitionCompiler, ig
[
ProvidedConstructor(
[ProvidedParameter("httpClient", typeof<HttpClient>);
ProvidedParameter("options", typeof<JsonSerializerOptions>)],
invokeCode = (fun args -> <@@ () @@>),
ProvidedParameter("options", typeof<JsonSerializerOptions>, optionalValue = (null:JsonSerializerOptions))],
invokeCode = (fun args ->
match args with
| [] -> failwith "Generated constructors should always pass the instance as the first argument!"
| _ -> <@@ () @@>),
BaseConstructorCall = fun args -> (baseCtor, args))
ProvidedConstructor(
[ProvidedParameter("httpClient", typeof<HttpClient>)],
invokeCode = (fun args -> <@@ () @@>),
BaseConstructorCall = fun args ->
let args' = args @ [ <@@ null @@> ]
(baseCtor, args'))
ProvidedConstructor(
[ProvidedParameter("options", typeof<JsonSerializerOptions>)],
invokeCode = (fun args -> <@@ () @@>),
BaseConstructorCall = fun args ->
let httpClient = <@@ RuntimeHelpers.getDefaultHttpClient defaultHost @@>
let args' =
match args with
| [instance; options] -> [instance; httpClient; options]
| _ -> failwithf "unexpected arguments received %A" args
(baseCtor, args'))
ProvidedConstructor([],
[ProvidedParameter("options", typeof<JsonSerializerOptions>, optionalValue = (null:JsonSerializerOptions))],
invokeCode = (fun args -> <@@ () @@>),
BaseConstructorCall = fun args ->
let httpClient = <@@ RuntimeHelpers.getDefaultHttpClient defaultHost @@>
let args' = args @ [ httpClient; <@@ null @@> ]
let httpClient = <@ RuntimeHelpers.getDefaultHttpClient defaultHost @>
let args' = args @ [httpClient]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This arguments order is incorrect

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the correct one?

Copy link
Member

@sergey-tihon sergey-tihon Jan 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The one that you revered in your commit [this; httpClient; options] as base class ctor expects

8459021#diff-4b6d8e966f147a1fd45efd232f8c3d4d993b57ddb43baa435c99211e4bb3e2ddL273-L276

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still no, you build [this; options; httpClient; null] instead of [this; httpClient; options]

Copy link
Contributor Author

@xperiandri xperiandri Jan 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like this?

let httpClient = <@ RuntimeHelpers.getDefaultHttpClient defaultHost @> :> Expr
let this :: tail = args
let args' = this :: httpClient :: tail

(baseCtor, args'))
] |> ty.AddMembers

Expand Down
29 changes: 8 additions & 21 deletions src/SwaggerProvider.DesignTime/v3/OperationCompiler.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ namespace SwaggerProvider.Internal.v3.Compilers

open System
open System.Net.Http
open System.Threading.Tasks
open System.Text.Json
open System.Text.RegularExpressions

Expand Down Expand Up @@ -384,30 +383,18 @@ type OperationCompiler (schema:OpenApiDocument, defCompiler:DefinitionCompiler,
[
ProvidedConstructor(
[ProvidedParameter("httpClient", typeof<HttpClient>);
ProvidedParameter("options", typeof<JsonSerializerOptions>)],
invokeCode = (fun args -> <@@ () @@>),
ProvidedParameter("options", typeof<JsonSerializerOptions>, optionalValue = (null:JsonSerializerOptions))],
invokeCode = (fun args ->
match args with
| [] -> failwith "Generated constructors should always pass the instance as the first argument!"
| _ -> <@@ () @@>),
BaseConstructorCall = fun args -> (baseCtor, args))
ProvidedConstructor(
[ProvidedParameter("httpClient", typeof<HttpClient>)],
invokeCode = (fun args -> <@@ () @@>),
BaseConstructorCall = fun args ->
let args' = args @ [ <@@ null @@> ]
(baseCtor, args'))
ProvidedConstructor(
[ProvidedParameter("options", typeof<JsonSerializerOptions>)],
invokeCode = (fun args -> <@@ () @@>),
BaseConstructorCall = fun args ->
let httpClient = <@@ RuntimeHelpers.getDefaultHttpClient defaultHost @@>
let args' =
match args with
| [instance; options] -> [instance; httpClient; options]
| _ -> failwithf "unexpected arguments received %A" args
(baseCtor, args'))
ProvidedConstructor([],
[ProvidedParameter("options", typeof<JsonSerializerOptions>, optionalValue = (null:JsonSerializerOptions))],
invokeCode = (fun args -> <@@ () @@>),
BaseConstructorCall = fun args ->
let httpClient = <@@ RuntimeHelpers.getDefaultHttpClient defaultHost @@>
let args' = args @ [ httpClient; <@@ null @@> ]
let httpClient = <@ RuntimeHelpers.getDefaultHttpClient defaultHost @>
let args' = args @ [httpClient]
(baseCtor, args'))
] |> ty.AddMembers

Expand Down