Skip to content

Commit 011c348

Browse files
authored
minor performance tweaks (#233)
1 parent a7326e1 commit 011c348

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

src/SwaggerProvider.DesignTime/v2/Parser/Schema.fs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ and DefinitionProperty =
6969

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

9596

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

117119

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

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

208212
/// Allows adding meta data to a single tag.
209213
/// http://swagger.io/specification/#tagObject
214+
[<Struct>]
210215
type TagObject =
211216
{
212217
/// Required. The name of the tag.

src/SwaggerProvider.DesignTime/v3/DefinitionCompiler.fs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ type DefinitionCompiler(schema: OpenApiDocument, provideNullable) as this =
369369
match schemaObj with
370370
| null -> failwithf $"Cannot compile object '%s{tyName}' when schema is 'null'"
371371
| _ when
372-
schemaObj.Reference <> null
372+
(not(isNull schemaObj.Reference))
373373
&& not <| schemaObj.Reference.Id.EndsWith(tyName)
374374
->
375375
ns.ReleaseNameReservation tyName
@@ -382,15 +382,18 @@ type DefinitionCompiler(schema: OpenApiDocument, provideNullable) as this =
382382
| _ -> failwithf $"Cannot compile object '%s{tyName}' based on unresolved reference '{schemaObj.Reference.ReferenceV3}'"
383383
// TODO: fail on external references
384384
//| _ when schemaObj.Reference <> null && tyName <> schemaObj.Reference.Id ->
385-
| _ when schemaObj.Type = "object" && schemaObj.AdditionalProperties <> null -> // Dictionary ->
385+
| _ when
386+
schemaObj.Type = "object"
387+
&& not(isNull schemaObj.AdditionalProperties)
388+
-> // Dictionary ->
386389
ns.ReleaseNameReservation tyName
387390
let elSchema = schemaObj.AdditionalProperties
388391

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

392395
ProvidedTypeBuilder.MakeGenericType(typedefof<Map<string, obj>>, [ typeof<string>; elTy ])
393-
| _ when schemaObj.Type = null || schemaObj.Type = "object" -> // Object props ->
396+
| _ when isNull schemaObj.Type || schemaObj.Type = "object" -> // Object props ->
394397
compileNewObject()
395398
| _ ->
396399
ns.MarkTypeAsNameAlias tyName

src/SwaggerProvider.DesignTime/v3/OperationCompiler.fs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ open Swagger.Internal
2121
// Probably related to https://github.com/fsprojects/FSharp.TypeProviders.SDK/issues/274
2222
type ApiCall = string * OpenApiPathItem * OperationType
2323

24+
[<Struct>]
2425
type PayloadType =
2526
| NoData
2627
| AppJson
@@ -218,9 +219,9 @@ type OperationCompiler(schema: OpenApiDocument, defCompiler: DefinitionCompiler,
218219

219220
let headers =
220221
<@
221-
[ if payloadMime <> null then
222+
[ if not(isNull payloadMime) then
222223
"Content-Type", payloadMime
223-
if retMime <> null then
224+
if not(isNull retMime) then
224225
"Accept", MediaTypes.ApplicationJson ]
225226
@>
226227

0 commit comments

Comments
 (0)