Skip to content

Commit f1a43c7

Browse files
committed
Merge pull request #10 from sergey-tihon/swashbuckle
Dependency to Newtonsoft.Json NuGet package
2 parents f486ac2 + bcbcc19 commit f1a43c7

33 files changed

+561
-446
lines changed

RELEASE_NOTES.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
#### 0.1.3-beta - December 12 2015
1+
#### 0.2.0 - December 13 2015
2+
* `AssemblyResolve` handler that resolve location of 3rd party dependencies
3+
* Added dependencies on `Newtonsoft.Json` NuGet package
4+
5+
#### 0.1.3-beta - December 7 2015
26
* Bug fixes
37

48
#### 0.1.2-beta - November 22 2015

SwaggerProvider.sln

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio 14
44
VisualStudioVersion = 14.0.23107.0
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "SwaggerProvider", "src\SwaggerProvider\SwaggerProvider.fsproj", "{AD0B2860-9373-4BD9-906D-6D19F2F7DEE9}"
6+
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "SwaggerProvider.Runtime", "src\SwaggerProvider.Runtime\SwaggerProvider.Runtime.fsproj", "{AD0B2860-9373-4BD9-906D-6D19F2F7DEE9}"
77
EndProject
88
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "SwaggerProvider.Tests", "tests\SwaggerProvider.Tests\SwaggerProvider.Tests.fsproj", "{524FCCB2-CEA4-402B-BF6E-EE659966C853}"
99
EndProject
@@ -26,6 +26,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Files", "Solution
2626
EndProject
2727
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Swashbuckle.OWIN.Server", "tests\Swashbuckle.OWIN.Server\Swashbuckle.OWIN.Server.fsproj", "{C2CD65DA-37A4-4A58-B450-C2AA7C8E8D2F}"
2828
EndProject
29+
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "SwaggerProvider.DesignTime", "src\SwaggerProvider.DesignTime\SwaggerProvider.DesignTime.fsproj", "{DBE9AA3E-AB4C-4FE3-915B-886CC6E6A88D}"
30+
EndProject
31+
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "SwaggerProvider", "src\SwaggerProvider\SwaggerProvider.fsproj", "{F5FD2EFD-D6EC-4735-BEE7-DE1A9A35A6FD}"
32+
EndProject
2933
Global
3034
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3135
Debug|Any CPU = Debug|Any CPU
@@ -44,6 +48,14 @@ Global
4448
{C2CD65DA-37A4-4A58-B450-C2AA7C8E8D2F}.Debug|Any CPU.Build.0 = Debug|Any CPU
4549
{C2CD65DA-37A4-4A58-B450-C2AA7C8E8D2F}.Release|Any CPU.ActiveCfg = Release|Any CPU
4650
{C2CD65DA-37A4-4A58-B450-C2AA7C8E8D2F}.Release|Any CPU.Build.0 = Release|Any CPU
51+
{DBE9AA3E-AB4C-4FE3-915B-886CC6E6A88D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
52+
{DBE9AA3E-AB4C-4FE3-915B-886CC6E6A88D}.Debug|Any CPU.Build.0 = Debug|Any CPU
53+
{DBE9AA3E-AB4C-4FE3-915B-886CC6E6A88D}.Release|Any CPU.ActiveCfg = Release|Any CPU
54+
{DBE9AA3E-AB4C-4FE3-915B-886CC6E6A88D}.Release|Any CPU.Build.0 = Release|Any CPU
55+
{F5FD2EFD-D6EC-4735-BEE7-DE1A9A35A6FD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
56+
{F5FD2EFD-D6EC-4735-BEE7-DE1A9A35A6FD}.Debug|Any CPU.Build.0 = Debug|Any CPU
57+
{F5FD2EFD-D6EC-4735-BEE7-DE1A9A35A6FD}.Release|Any CPU.ActiveCfg = Release|Any CPU
58+
{F5FD2EFD-D6EC-4735-BEE7-DE1A9A35A6FD}.Release|Any CPU.Build.0 = Release|Any CPU
4759
EndGlobalSection
4860
GlobalSection(SolutionProperties) = preSolution
4961
HideSolutionNode = FALSE
@@ -52,5 +64,7 @@ Global
5264
{AD0B2860-9373-4BD9-906D-6D19F2F7DEE9} = {727FB2BE-A8C5-4537-9C87-7083346E2865}
5365
{524FCCB2-CEA4-402B-BF6E-EE659966C853} = {3A51AC71-D3EF-46DE-A7F0-E2B46370C6EE}
5466
{C2CD65DA-37A4-4A58-B450-C2AA7C8E8D2F} = {3A51AC71-D3EF-46DE-A7F0-E2B46370C6EE}
67+
{DBE9AA3E-AB4C-4FE3-915B-886CC6E6A88D} = {727FB2BE-A8C5-4537-9C87-7083346E2865}
68+
{F5FD2EFD-D6EC-4735-BEE7-DE1A9A35A6FD} = {727FB2BE-A8C5-4537-9C87-7083346E2865}
5569
EndGlobalSection
5670
EndGlobal

build.fsx

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ let project = "SwaggerProvider"
3737

3838
// Short summary of the project
3939
// (used as description in AssemblyInfo and as a short summary for NuGet package)
40-
let summary = "Type provider for Swagger.io"
40+
let summary = "F# Type Provider for Swagger"
4141

4242
// Longer description of the project
4343
// (used as a description for NuGet package; line breaks are automatically cleaned up)
44-
let description = "Type provider for Swagger.io"
44+
let description = "F# Type Provider for Swagger"
4545

4646
// List of author names (for NuGet package)
4747
let authors = [ "Sergey Tihon" ]
@@ -83,29 +83,13 @@ let (|Fsproj|Csproj|Vbproj|) (projFileName:string) =
8383

8484
// Generate assembly info files with the right version & up-to-date information
8585
Target "AssemblyInfo" (fun _ ->
86-
let getAssemblyInfoAttributes projectName =
87-
[ Attribute.Title (projectName)
88-
Attribute.Product project
89-
Attribute.Description summary
90-
Attribute.Version release.AssemblyVersion
91-
Attribute.FileVersion release.AssemblyVersion ]
92-
93-
let getProjectDetails projectPath =
94-
let projectName = System.IO.Path.GetFileNameWithoutExtension(projectPath)
95-
( projectPath,
96-
projectName,
97-
System.IO.Path.GetDirectoryName(projectPath),
98-
(getAssemblyInfoAttributes projectName)
99-
)
100-
101-
!! "src/**/*.??proj"
102-
|> Seq.map getProjectDetails
103-
|> Seq.iter (fun (projFileName, projectName, folderName, attributes) ->
104-
match projFileName with
105-
| Fsproj -> CreateFSharpAssemblyInfo (folderName @@ "AssemblyInfo.fs") attributes
106-
| Csproj -> CreateCSharpAssemblyInfo ((folderName @@ "Properties") @@ "AssemblyInfo.cs") attributes
107-
| Vbproj -> CreateVisualBasicAssemblyInfo ((folderName @@ "My Project") @@ "AssemblyInfo.vb") attributes
108-
)
86+
let fileName = "src/Common/AssemblyInfo.fs"
87+
CreateFSharpAssemblyInfo fileName
88+
[ Attribute.Title gitName
89+
Attribute.Product gitName
90+
Attribute.Description description
91+
Attribute.Version release.AssemblyVersion
92+
Attribute.FileVersion release.AssemblyVersion ]
10993
)
11094

11195
// Copies binaries from default VS location to exepcted bin folder
@@ -115,6 +99,9 @@ Target "CopyBinaries" (fun _ ->
11599
!! "src/**/*.??proj"
116100
|> Seq.map (fun f -> ((System.IO.Path.GetDirectoryName f) @@ "bin/Release", "bin" @@ (System.IO.Path.GetFileNameWithoutExtension f)))
117101
|> Seq.iter (fun (fromDir, toDir) -> CopyDir toDir fromDir (fun _ -> true))
102+
103+
// All Type Providers components should be in the same directory
104+
CopyDir "bin/SwaggerProvider" "bin/SwaggerProvider.DesignTime" (fun _ -> true)
118105
)
119106

120107
// --------------------------------------------------------------------------------------

paket.dependencies

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
source https://nuget.org/api/v2
22

3-
nuget Newtonsoft.Json
3+
nuget Newtonsoft.Json >= 7.0.1
44

55
github fsharp/FSharp.Data src/Net/UriUtils.fs
66
github fsharp/FSharp.Data src/Net/Http.fs
@@ -26,11 +26,11 @@ group Build
2626
nuget SourceLink.Fake
2727

2828
github fsharp/FAKE modules/Octokit/Octokit.fsx
29-
29+
3030
group OWIN
31-
31+
3232
source https://nuget.org/api/v2
33-
33+
3434
nuget Microsoft.AspNet.WebApi.OwinSelfHost
3535
nuget Swashbuckle.Core
3636

@@ -41,6 +41,5 @@ group Test
4141
nuget NUnit ~> 2
4242
nuget NUnit.Runners ~> 2
4343
nuget FSharp.Data
44-
nuget FSharp.Core
4544

4645
github fsprojects/FsUnit src/FsUnit.NUnit/FsUnit.fs

paket.lock

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ GROUP Test
8686
NUGET
8787
remote: https://nuget.org/api/v2
8888
specs:
89-
FSharp.Core (4.0.0.1)
9089
FSharp.Data (2.2.5)
9190
Zlib.Portable (>= 1.10.0) - framework: portable-net40+sl50+wp80+win80
9291
NUnit (2.6.4)

src/Common/AssemblyInfo.fs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace System
2+
open System.Reflection
3+
4+
[<assembly: AssemblyTitleAttribute("SwaggerProvider")>]
5+
[<assembly: AssemblyProductAttribute("SwaggerProvider")>]
6+
[<assembly: AssemblyDescriptionAttribute("F# Type Provider for Swagger")>]
7+
[<assembly: AssemblyVersionAttribute("0.2.0")>]
8+
[<assembly: AssemblyFileVersionAttribute("0.2.0")>]
9+
do ()
10+
11+
module internal AssemblyVersionInformation =
12+
let [<Literal>] Version = "0.2.0"
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/// [omit]
2+
module SwaggerProvider.Internal.Configuration
3+
4+
open System
5+
open System.IO
6+
open System.Reflection
7+
open System.Configuration
8+
open System.Collections.Generic
9+
10+
type Logging() =
11+
static member logf (s:string) =
12+
()//System.IO.File.AppendAllLines(@"c:\swaggerlog.txt", [|s|])
13+
14+
/// Returns the Assembly object of SwaggerProvider.Runtime.dll (this needs to
15+
/// work when called from SwaggerProvider.DesignTime.dll)
16+
let getSwaggerProviderRuntimeAssembly() =
17+
AppDomain.CurrentDomain.GetAssemblies()
18+
|> Seq.find (fun a -> a.FullName.StartsWith("SwaggerProvider,"))
19+
20+
/// Finds directories relative to 'dirs' using the specified 'patterns'.
21+
/// Patterns is a string, such as "..\foo\*\bar" split by '\'. Standard
22+
/// .NET libraries do not support "*", so we have to do it ourselves..
23+
let rec searchDirectories patterns dirs =
24+
match patterns with
25+
| [] -> dirs
26+
| "*"::patterns ->
27+
dirs |> List.collect (Directory.GetDirectories >> List.ofSeq)
28+
|> searchDirectories patterns
29+
| name::patterns ->
30+
dirs |> List.map (fun d -> Path.Combine(d, name))
31+
|> searchDirectories patterns
32+
33+
/// Returns the real assembly location - when shadow copying is enabled, this
34+
/// returns the original assembly location (which may contain other files we need)
35+
let getAssemblyLocation (assem:Assembly) =
36+
if System.AppDomain.CurrentDomain.ShadowCopyFiles then
37+
(new System.Uri(assem.EscapedCodeBase)).LocalPath
38+
else assem.Location
39+
40+
/// Reads the 'SwaggerProvider.dll.config' file and gets the 'ProbingLocations'
41+
/// parameter from the configuration file. Resolves the directories and returns
42+
/// them as a list.
43+
let getProbingLocations() =
44+
try
45+
let root = getSwaggerProviderRuntimeAssembly() |> getAssemblyLocation
46+
Logging.logf <| sprintf "Root %s" root
47+
let config = System.Configuration.ConfigurationManager.OpenExeConfiguration(root)
48+
let pattern = config.AppSettings.Settings.["ProbingLocations"]
49+
Logging.logf <| sprintf "Pattern %s" pattern.Value
50+
if pattern <> null then
51+
[ yield root
52+
let pattern = pattern.Value.Split(';', ',') |> List.ofSeq
53+
for pat in pattern do
54+
let roots = [ Path.GetDirectoryName(root) ]
55+
for dir in roots |> searchDirectories (List.ofSeq (pat.Split('/','\\'))) do
56+
if Directory.Exists(dir) then yield dir ]
57+
else []
58+
with :? ConfigurationErrorsException | :? KeyNotFoundException -> []
59+
60+
/// Given an assembly name, try to find it in either assemblies
61+
/// loaded in the current AppDomain, or in one of the specified
62+
/// probing directories.
63+
let resolveReferencedAssembly (asmName:string) =
64+
65+
// Do not interfere with loading FSharp.Core resources, see #97
66+
if asmName.StartsWith "FSharp.Core.resources" then null else
67+
68+
// First, try to find the assembly in the currently loaded assemblies
69+
let fullName = AssemblyName(asmName)
70+
let loadedAsm =
71+
System.AppDomain.CurrentDomain.GetAssemblies()
72+
|> Seq.tryFind (fun a -> AssemblyName.ReferenceMatchesDefinition(fullName, a.GetName()))
73+
match loadedAsm with
74+
| Some asm -> asm
75+
| None ->
76+
77+
// Otherwise, search the probing locations for a DLL file
78+
let libraryName =
79+
let idx = asmName.IndexOf(',')
80+
if idx > 0 then asmName.Substring(0, idx) else asmName
81+
82+
let locations = getProbingLocations()
83+
Logging.logf <| sprintf "Probing locations: %A" locations
84+
85+
let asm = locations |> Seq.tryPick (fun dir ->
86+
let library = Path.Combine(dir, libraryName+".dll")
87+
if File.Exists(library) then
88+
Logging.logf <| sprintf "Found assembly, checking version! (%s)" library
89+
// We do a ReflectionOnlyLoad so that we can check the version
90+
let refAssem = Assembly.ReflectionOnlyLoadFrom(library)
91+
// If it matches, we load the actual assembly
92+
if refAssem.FullName = asmName then
93+
Logging.logf "...version matches, returning!"
94+
Some(Assembly.LoadFrom(library))
95+
else
96+
Logging.logf "...version mismatch, skipping"
97+
None
98+
else None)
99+
100+
if asm = None then Logging.logf "Assembly not found!"
101+
defaultArg asm null

src/SwaggerProvider/DefinitionCompiler.fs renamed to src/SwaggerProvider.DesignTime/DefinitionCompiler.fs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,8 @@ type DefinitionCompiler (schema:SwaggerObject) =
1818
GetterCode = (fun [this] -> Expr.FieldGet (this, providedField)),
1919
SetterCode = (fun [this;v] -> Expr.FieldSet(this, providedField, v)))
2020
if name <> propertyName then
21-
let attribute =
22-
{ new Reflection.CustomAttributeData() with
23-
member __.Constructor = typeof<Newtonsoft.Json.JsonPropertyAttribute>.GetConstructor([|typeof<string>|])
24-
member __.ConstructorArguments = [|Reflection.CustomAttributeTypedArgument(typeof<string>, name)|] :> System.Collections.Generic.IList<_>
25-
member __.NamedArguments = [||] :> System.Collections.Generic.IList<_> }
26-
property.AddCustomAttribute(attribute)
21+
property.AddCustomAttribute
22+
<| SwaggerProvider.Internal.RuntimeHelpers.getPropertyNameAttribute name
2723
property
2824

2925
let rec compileDefinition (name:string) =

0 commit comments

Comments
 (0)