Skip to content

Commit 6c51693

Browse files
committed
Supported wrappers around primitive types - APIs-guru/openapi-directory#98
1 parent 613a178 commit 6c51693

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

Diff for: RELEASE_NOTES.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#### 0.6.0 - April 13, 2017
22
* Supported `allOf` composition with `properties` definition in the same SchemaObject - https://github.com/fsprojects/SwaggerProvider/issues/72
3+
* Supported wrappers around primitive types - https://github.com/APIs-guru/openapi-directory/issues/98
34
* No runtime dependency on YamlDotNet
45
* NuGet dependency on FSharp.Core
56

Diff for: src/SwaggerProvider.DesignTime/SchemaParser.fs

+19-4
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,6 @@ module Parser =
8787
| _ -> None
8888
)
8989
|> Option.map (parseSchemaObject definitions)
90-
let (|IsAllOf|_|) (obj:SchemaNode) =
91-
// Identify composition element 'allOf'
92-
obj.TryGetProperty("allOf")
93-
|> Option.map (fun x -> x.AsArray())
9490
let (|IsPrimitive|_|) (obj:SchemaNode) =
9591
// Parse primitive types
9692
obj.TryGetProperty("type")
@@ -136,6 +132,10 @@ module Parser =
136132
obj.TryGetProperty("additionalProperties")
137133
|> Option.map (parseSchemaObject definitions)
138134
| _ -> None
135+
let (|IsAllOf|_|) (obj:SchemaNode) =
136+
// Identify composition element 'allOf'
137+
obj.TryGetProperty("allOf")
138+
|> Option.map (fun x -> x.AsArray())
139139
let (|IsComposition|_|) (obj:SchemaNode) =
140140
// Models with Object Composition
141141
match obj with
@@ -164,6 +164,20 @@ module Parser =
164164
else None // One of elements is not an Object and we cannot Compose
165165

166166
| _ -> None
167+
let (|IsWrapper|_|) (obj:SchemaNode) =
168+
// Support for obj that wrap another obj / primitive
169+
// Sample https://github.com/APIs-guru/openapi-directory/issues/98
170+
match obj with
171+
| IsAllOf allOf when allOf.Length = 1 ->
172+
parseSchemaObject definitions allOf.[0]
173+
|> function
174+
| Reference path ->
175+
match definitions.TryGetValue path with
176+
| true, lazeObj ->
177+
Some <| lazeObj.Value
178+
| _ -> failwithf "Reference to unknown type %s" path
179+
| _ -> None
180+
| _ -> None
167181
let (|IsPolymorphism|_|) (obj:SchemaNode) =
168182
// Models with Polymorphism Support
169183
obj.TryGetProperty("discriminator")
@@ -178,6 +192,7 @@ module Parser =
178192
Object <| Array.append compProps objProps
179193
| IsObject props -> Object props
180194
| IsComposition props -> Object props
195+
| IsWrapper ty -> ty
181196
| IsPolymorphism _ ->
182197
failwith "Models with Polymorphism Support is not supported yet. If you see this error please report it on GitHub (https://github.com/fsprojects/SwaggerProvider/issues) with schema example."
183198
| _ -> Object [||] // Default type when parsers could not determine the type based ob schema.

Diff for: tests/SwaggerProvider.Tests/APIs.guru.fs

+1-3
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@ let private schemaUrls =
3535
Array.concat [manualSchemaUrls; apisGuruJsonSchemaUrls]
3636

3737
let private ignoreList =
38-
["https://api.apis.guru/v2/specs/rebilly.com/2.1/swagger.json" // tricky `allOf` using DateTime
39-
"https://api.apis.guru/v2/specs/rebilly.com/2.1/swagger.yaml"
40-
38+
[
4139
// Following schemas require additional investigation and fixes
4240
"https://api.apis.guru/v2/specs/clarify.io/1.3.3/swagger.json" // StackOverflowException during FCS compilation
4341
"https://api.apis.guru/v2/specs/clarify.io/1.3.3/swagger.yaml"

0 commit comments

Comments
 (0)