Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
13 changes: 1 addition & 12 deletions src/SwaggerProvider.DesignTime/DefinitionCompiler.fs
Original file line number Diff line number Diff line change
Expand Up @@ -328,19 +328,8 @@ type DefinitionCompiler(schema: OpenApiDocument, provideNullable, useDateOnly: b

let pField, pProp = generateProperty propName pTy

let enumValuesDoc = XmlDoc.buildEnumDoc propSchema.Enum

let propDoc =
match
propSchema.Description
|> Option.ofObj
|> Option.filter(String.IsNullOrWhiteSpace >> not),
enumValuesDoc
with
| None, None -> null
| Some d, None -> d
| None, Some ev -> ev
| Some d, Some ev -> $"{d}\n{ev}"
XmlDoc.combineDescAndEnum propSchema.Description (XmlDoc.buildEnumDoc propSchema.Enum)

if not(isNull propDoc) then
pProp.AddXmlDoc propDoc
Expand Down
11 changes: 1 addition & 10 deletions src/SwaggerProvider.DesignTime/OperationCompiler.fs
Original file line number Diff line number Diff line change
Expand Up @@ -502,16 +502,7 @@ type OperationCompiler(schema: OpenApiDocument, defCompiler: DefinitionCompiler,
else
None

match
p.Description
|> Option.ofObj
|> Option.filter(String.IsNullOrWhiteSpace >> not),
enumDoc
with
| None, None -> null
| Some d, None -> d
| None, Some ev -> ev
| Some d, Some ev -> $"{d}\n{ev}"
XmlDoc.combineDescAndEnum p.Description enumDoc

let paramDescriptions =
[ for p in openApiParameters -> niceCamelName p.Name, buildParamDesc p
Expand Down
16 changes: 16 additions & 0 deletions src/SwaggerProvider.DesignTime/Utils.fs
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,22 @@ module XmlDoc =
let values = enumValues |> Seq.map formatEnumValue |> String.concat ", "
Some $"Allowed values: {values}"

/// Combines a schema description with optional enum-value documentation into a single
/// XML doc string. Returns null if both inputs are absent.
/// Callers use this to avoid duplicating the four-case match expression in every property
/// and parameter doc-building site.
let combineDescAndEnum (description: string) (enumDoc: string option) =
match
description
|> Option.ofObj
|> Option.filter(String.IsNullOrWhiteSpace >> not),
enumDoc
with
| None, None -> null
| Some d, None -> d
| None, Some ev -> ev
| Some d, Some ev -> $"{d}\n{ev}"

/// Builds a structured XML doc string from summary, description, and parameter descriptions.
/// paramDescriptions is a sequence of (camelCaseName, description) pairs.
let buildXmlDoc (summary: string) (description: string) (paramDescriptions: (string * string) seq) =
Expand Down
28 changes: 27 additions & 1 deletion src/SwaggerProvider.Runtime/RuntimeHelpers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,32 @@ module RuntimeHelpers =
let combineUrl (urlA: string) (urlB: string) =
sprintf "%s/%s" (urlA.TrimEnd('/')) (urlB.TrimStart('/'))

// Pre-built map of standard HTTP method names to their corresponding static HttpMethod
// instances. Uses an ordinal case-insensitive comparer so callers passing different
// casing (for example, "get") still resolve to the cached standard HttpMethod without
// allocating a normalized string for lookup.
let private standardHttpMethods =
let methods =
[| HttpMethod.Get
HttpMethod.Post
HttpMethod.Put
HttpMethod.Delete
HttpMethod("PATCH")
HttpMethod.Head
HttpMethod.Options
HttpMethod.Trace |]

let dictionary =
System.Collections.Generic.Dictionary<string, HttpMethod>(StringComparer.OrdinalIgnoreCase)

methods |> Array.iter(fun m -> dictionary.Add(m.Method, m))
System.Collections.ObjectModel.ReadOnlyDictionary<string, HttpMethod>(dictionary)

let private resolveHttpMethod(method: string) : HttpMethod =
match standardHttpMethods.TryGetValue method with
| true, m -> m
| false, _ -> HttpMethod(method.ToUpperInvariant())

let createHttpRequest (httpMethod: string) address queryParams =
let requestUrl =
let fakeHost = "http://fake-host/"
Expand All @@ -516,7 +542,7 @@ module RuntimeHelpers =
builder.Query <- query.ToString()
builder.Uri.PathAndQuery.TrimStart('/')

let method = HttpMethod(httpMethod.ToUpper())
let method = resolveHttpMethod httpMethod
new HttpRequestMessage(method, Uri(requestUrl, UriKind.Relative))

let fillHeaders (msg: HttpRequestMessage) (headers: (string * string) seq) =
Expand Down
Loading