From de8f563dc4f2409effe7c8a2cceb3037c8e1310f Mon Sep 17 00:00:00 2001 From: Tuomas Hietanen Date: Wed, 8 Nov 2023 17:49:35 +0000 Subject: [PATCH 1/2] minor performance tweaks --- src/SwaggerProvider.DesignTime/v2/Parser/Schema.fs | 5 +++++ src/SwaggerProvider.DesignTime/v3/DefinitionCompiler.fs | 9 ++++++--- src/SwaggerProvider.DesignTime/v3/OperationCompiler.fs | 5 +++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/SwaggerProvider.DesignTime/v2/Parser/Schema.fs b/src/SwaggerProvider.DesignTime/v2/Parser/Schema.fs index 83a94cf..7c48597 100644 --- a/src/SwaggerProvider.DesignTime/v2/Parser/Schema.fs +++ b/src/SwaggerProvider.DesignTime/v2/Parser/Schema.fs @@ -69,6 +69,7 @@ and DefinitionProperty = /// The type of the REST call. /// http://swagger.io/specification/#pathItemObject +[] type OperationType = /// Returns en element or collection. | Get @@ -94,6 +95,7 @@ type OperationType = /// Determines the format of the array if type array is used. Array value separator. +[] type CollectionFormat = /// Comma separated values. | Csv @@ -116,6 +118,7 @@ type CollectionFormat = /// Required. The location of the parameter. +[] type ParameterObjectLocation = /// Parameter that are appended to the URL. For example, in /items?id=###, the query parameter is id. | Query @@ -194,6 +197,7 @@ type OperationObject = /// Basic swagger information, relevant to the type provider. /// http://swagger.io/specification/#infoObject +[] type InfoObject = { /// Required. The title of the application. @@ -207,6 +211,7 @@ type InfoObject = /// Allows adding meta data to a single tag. /// http://swagger.io/specification/#tagObject +[] type TagObject = { /// Required. The name of the tag. diff --git a/src/SwaggerProvider.DesignTime/v3/DefinitionCompiler.fs b/src/SwaggerProvider.DesignTime/v3/DefinitionCompiler.fs index 370dd8c..a0e980d 100644 --- a/src/SwaggerProvider.DesignTime/v3/DefinitionCompiler.fs +++ b/src/SwaggerProvider.DesignTime/v3/DefinitionCompiler.fs @@ -369,7 +369,7 @@ type DefinitionCompiler(schema: OpenApiDocument, provideNullable) as this = match schemaObj with | null -> failwithf $"Cannot compile object '%s{tyName}' when schema is 'null'" | _ when - schemaObj.Reference <> null + (not(isNull schemaObj.Reference)) && not <| schemaObj.Reference.Id.EndsWith(tyName) -> ns.ReleaseNameReservation tyName @@ -382,7 +382,10 @@ type DefinitionCompiler(schema: OpenApiDocument, provideNullable) as this = | _ -> failwithf $"Cannot compile object '%s{tyName}' based on unresolved reference '{schemaObj.Reference.ReferenceV3}'" // TODO: fail on external references //| _ when schemaObj.Reference <> null && tyName <> schemaObj.Reference.Id -> - | _ when schemaObj.Type = "object" && schemaObj.AdditionalProperties <> null -> // Dictionary -> + | _ when + schemaObj.Type = "object" + && not(isNull schemaObj.AdditionalProperties) + -> // Dictionary -> ns.ReleaseNameReservation tyName let elSchema = schemaObj.AdditionalProperties @@ -390,7 +393,7 @@ type DefinitionCompiler(schema: OpenApiDocument, provideNullable) as this = compileBySchema ns (ns.ReserveUniqueName tyName "Item") elSchema true ns.RegisterType false ProvidedTypeBuilder.MakeGenericType(typedefof>, [ typeof; elTy ]) - | _ when schemaObj.Type = null || schemaObj.Type = "object" -> // Object props -> + | _ when isNull schemaObj.Type || schemaObj.Type = "object" -> // Object props -> compileNewObject() | _ -> ns.MarkTypeAsNameAlias tyName diff --git a/src/SwaggerProvider.DesignTime/v3/OperationCompiler.fs b/src/SwaggerProvider.DesignTime/v3/OperationCompiler.fs index 17c3e24..6630838 100644 --- a/src/SwaggerProvider.DesignTime/v3/OperationCompiler.fs +++ b/src/SwaggerProvider.DesignTime/v3/OperationCompiler.fs @@ -21,6 +21,7 @@ open Swagger.Internal // Probably related to https://github.com/fsprojects/FSharp.TypeProviders.SDK/issues/274 type ApiCall = string * OpenApiPathItem * OperationType +[] type PayloadType = | NoData | AppJson @@ -218,9 +219,9 @@ type OperationCompiler(schema: OpenApiDocument, defCompiler: DefinitionCompiler, let headers = <@ - [ if payloadMime <> null then + [ if not(isNull payloadMime) then "Content-Type", payloadMime - if retMime <> null then + if not(isNull retMime) then "Accept", MediaTypes.ApplicationJson ] @> From 7dd7d173e02107447da1bb51405a7717bb99b7bf Mon Sep 17 00:00:00 2001 From: Tuomas Hietanen Date: Mon, 13 Nov 2023 07:34:07 +0000 Subject: [PATCH 2/2] update ProvidedTypes.fs --- paket.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/paket.lock b/paket.lock index 3f11e13..e4464d2 100644 --- a/paket.lock +++ b/paket.lock @@ -37,8 +37,8 @@ NUGET YamlDotNet (13.7.1) GITHUB remote: fsprojects/FSharp.TypeProviders.SDK - src/ProvidedTypes.fs (b7c930b0bd9e0e0476981ba0813ac17e7d61742b) - src/ProvidedTypes.fsi (b7c930b0bd9e0e0476981ba0813ac17e7d61742b) + src/ProvidedTypes.fs (48abfa531a90a42a7f62a7cbfd0027741e83b9da) + src/ProvidedTypes.fsi (48abfa531a90a42a7f62a7cbfd0027741e83b9da) remote: fsprojects/FSharp.Data src/FSharp.Data.Runtime.Utilities/NameUtils.fs (6e7d332943f1b26be034d283ef292296913d40ab) src/FSharp.Data.Runtime.Utilities/Pluralizer.fs (6e7d332943f1b26be034d283ef292296913d40ab)