Skip to content

Commit

Permalink
minor performance tweaks (#233)
Browse files Browse the repository at this point in the history
  • Loading branch information
Thorium authored Nov 8, 2023
1 parent a7326e1 commit 011c348
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
5 changes: 5 additions & 0 deletions src/SwaggerProvider.DesignTime/v2/Parser/Schema.fs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ and DefinitionProperty =

/// The type of the REST call.
/// http://swagger.io/specification/#pathItemObject
[<Struct>]
type OperationType =
/// Returns en element or collection.
| Get
Expand All @@ -94,6 +95,7 @@ type OperationType =


/// Determines the format of the array if type array is used. Array value separator.
[<Struct>]
type CollectionFormat =
/// Comma separated values.
| Csv
Expand All @@ -116,6 +118,7 @@ type CollectionFormat =


/// Required. The location of the parameter.
[<Struct>]
type ParameterObjectLocation =
/// Parameter that are appended to the URL. For example, in /items?id=###, the query parameter is id.
| Query
Expand Down Expand Up @@ -194,6 +197,7 @@ type OperationObject =

/// Basic swagger information, relevant to the type provider.
/// http://swagger.io/specification/#infoObject
[<Struct>]
type InfoObject =
{
/// Required. The title of the application.
Expand All @@ -207,6 +211,7 @@ type InfoObject =

/// Allows adding meta data to a single tag.
/// http://swagger.io/specification/#tagObject
[<Struct>]
type TagObject =
{
/// Required. The name of the tag.
Expand Down
9 changes: 6 additions & 3 deletions src/SwaggerProvider.DesignTime/v3/DefinitionCompiler.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -382,15 +382,18 @@ 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

let elTy =
compileBySchema ns (ns.ReserveUniqueName tyName "Item") elSchema true ns.RegisterType false

ProvidedTypeBuilder.MakeGenericType(typedefof<Map<string, obj>>, [ typeof<string>; elTy ])
| _ when schemaObj.Type = null || schemaObj.Type = "object" -> // Object props ->
| _ when isNull schemaObj.Type || schemaObj.Type = "object" -> // Object props ->
compileNewObject()
| _ ->
ns.MarkTypeAsNameAlias tyName
Expand Down
5 changes: 3 additions & 2 deletions src/SwaggerProvider.DesignTime/v3/OperationCompiler.fs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ open Swagger.Internal
// Probably related to https://github.com/fsprojects/FSharp.TypeProviders.SDK/issues/274
type ApiCall = string * OpenApiPathItem * OperationType

[<Struct>]
type PayloadType =
| NoData
| AppJson
Expand Down Expand Up @@ -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 ]
@>

Expand Down

0 comments on commit 011c348

Please sign in to comment.