diff --git a/.paket/Paket.Restore.targets b/.paket/Paket.Restore.targets new file mode 100644 index 00000000..1a326ea1 --- /dev/null +++ b/.paket/Paket.Restore.targets @@ -0,0 +1,249 @@ + + + + + + + $(MSBuildAllProjects);$(MSBuildThisFileFullPath) + + true + $(MSBuildThisFileDirectory) + $(MSBuildThisFileDirectory)..\ + $(PaketRootPath)paket-files\paket.restore.cached + $(PaketRootPath)paket.lock + /Library/Frameworks/Mono.framework/Commands/mono + mono + + $(PaketRootPath)paket.exe + $(PaketToolsPath)paket.exe + "$(PaketExePath)" + $(MonoPath) --runtime=v4.0.30319 "$(PaketExePath)" + $(PaketRootPath)paket.bootstrapper.exe + $(PaketToolsPath)paket.bootstrapper.exe + "$(PaketBootStrapperExePath)" + $(MonoPath) --runtime=v4.0.30319 "$(PaketBootStrapperExePath)" + + + + + true + true + + + + + + + true + $(NoWarn);NU1603 + + + + $([System.IO.File]::ReadAllText('$(PaketRestoreCacheFile)')) + $([System.IO.File]::ReadAllText('$(PaketLockFilePath)')) + true + false + true + + + + + + + + + $(MSBuildProjectDirectory)\obj\$(MSBuildProjectFile).paket.references.cached + + $(MSBuildProjectFullPath).paket.references + + $(MSBuildProjectDirectory)\$(MSBuildProjectName).paket.references + + $(MSBuildProjectDirectory)\paket.references + $(MSBuildProjectDirectory)\obj\$(MSBuildProjectFile).$(TargetFramework).paket.resolved + true + references-file-or-cache-not-found + + + + + $([System.IO.File]::ReadAllText('$(PaketReferencesCachedFilePath)')) + $([System.IO.File]::ReadAllText('$(PaketOriginalReferencesFilePath)')) + references-file + false + + + + + false + + + + + true + target-framework '$(TargetFramework)' + + + + + + + + + + + + + + + + + $([System.String]::Copy('%(PaketReferencesFileLines.Identity)').Split(',')[0]) + $([System.String]::Copy('%(PaketReferencesFileLines.Identity)').Split(',')[1]) + + + %(PaketReferencesFileLinesInfo.PackageVersion) + + + + + $(MSBuildProjectDirectory)/obj/$(MSBuildProjectFile).paket.clitools + + + + + + + + + $([System.String]::Copy('%(PaketCliToolFileLines.Identity)').Split(',')[0]) + $([System.String]::Copy('%(PaketCliToolFileLines.Identity)').Split(',')[1]) + + + %(PaketCliToolFileLinesInfo.PackageVersion) + + + + + $(MSBuildProjectDirectory)/obj/$(MSBuildProjectFile).NuGet.Config + + + + + + + false + + + + + + <_NuspecFilesNewLocation Include="$(BaseIntermediateOutputPath)$(Configuration)/*.nuspec"/> + + + + $(MSBuildProjectDirectory)/$(MSBuildProjectFile) + true + false + true + $(BaseIntermediateOutputPath)$(Configuration)/ + $(BaseIntermediateOutputPath) + + + + <_NuspecFiles Include="$(AdjustedNuspecOutputPath)*.nuspec"/> + + + + + + + + + + + + + + + diff --git a/.paket/paket.exe b/.paket/paket.exe index 5e476003..d5657f0a 100644 Binary files a/.paket/paket.exe and b/.paket/paket.exe differ diff --git a/paket.dependencies b/paket.dependencies index a39eac25..5d397a0a 100644 --- a/paket.dependencies +++ b/paket.dependencies @@ -15,12 +15,12 @@ github fsharp/FSharp.Data src/CommonRuntime/StructuralTypes.fs github fsharp/FSharp.Data src/Json/JsonValue.fs github fsharp/FSharp.Data src/Json/JsonConversions.fs github fsharp/FSharp.Data src/Json/JsonExtensions.fs -github fsprojects/FSharp.TypeProviders.StarterPack src/ProvidedTypes.fsi -github fsprojects/FSharp.TypeProviders.StarterPack src/ProvidedTypes.fs -github fsprojects/FSharp.TypeProviders.StarterPack src/ProvidedTypesTesting.fs +github fsprojects/FSharp.TypeProviders.SDK src/ProvidedTypes.fsi +github fsprojects/FSharp.TypeProviders.SDK src/ProvidedTypes.fs +github fsprojects/FSharp.TypeProviders.SDK src/ProvidedTypesTesting.fs group Build - framework: net45 + framework: net461 source https://nuget.org/api/v2 nuget FAKE diff --git a/paket.lock b/paket.lock index c99e4883..215a58a1 100644 --- a/paket.lock +++ b/paket.lock @@ -3,29 +3,29 @@ NUGET remote: https://www.nuget.org/api/v2 FSharp.Core (4.0.0.1) Newtonsoft.Json (10.0.3) - YamlDotNet (4.2.1) + YamlDotNet (4.2.2) GITHUB remote: fsharp/FSharp.Data - src/CommonRuntime/IO.fs (503ed03c0ab56dcd4938946d898df886a7c5a79c) - src/CommonRuntime/NameUtils.fs (503ed03c0ab56dcd4938946d898df886a7c5a79c) - src/CommonRuntime/Pluralizer.fs (503ed03c0ab56dcd4938946d898df886a7c5a79c) - src/CommonRuntime/StructuralTypes.fs (503ed03c0ab56dcd4938946d898df886a7c5a79c) - src/CommonRuntime/TextConversions.fs (503ed03c0ab56dcd4938946d898df886a7c5a79c) - src/Json/JsonConversions.fs (503ed03c0ab56dcd4938946d898df886a7c5a79c) - src/Json/JsonExtensions.fs (503ed03c0ab56dcd4938946d898df886a7c5a79c) - src/Json/JsonValue.fs (503ed03c0ab56dcd4938946d898df886a7c5a79c) - src/Net/Http.fs (503ed03c0ab56dcd4938946d898df886a7c5a79c) - src/Net/UriUtils.fs (503ed03c0ab56dcd4938946d898df886a7c5a79c) - remote: fsprojects/FSharp.TypeProviders.StarterPack - src/ProvidedTypes.fs (1dab4f94411500794342f61f877feab772e5a754) - src/ProvidedTypes.fsi (1dab4f94411500794342f61f877feab772e5a754) - src/ProvidedTypesTesting.fs (1dab4f94411500794342f61f877feab772e5a754) + src/CommonRuntime/IO.fs (b5df1ca30f5bb7749c4fd340b61f1b7fc43fb547) + src/CommonRuntime/NameUtils.fs (b5df1ca30f5bb7749c4fd340b61f1b7fc43fb547) + src/CommonRuntime/Pluralizer.fs (b5df1ca30f5bb7749c4fd340b61f1b7fc43fb547) + src/CommonRuntime/StructuralTypes.fs (b5df1ca30f5bb7749c4fd340b61f1b7fc43fb547) + src/CommonRuntime/TextConversions.fs (b5df1ca30f5bb7749c4fd340b61f1b7fc43fb547) + src/Json/JsonConversions.fs (b5df1ca30f5bb7749c4fd340b61f1b7fc43fb547) + src/Json/JsonExtensions.fs (b5df1ca30f5bb7749c4fd340b61f1b7fc43fb547) + src/Json/JsonValue.fs (b5df1ca30f5bb7749c4fd340b61f1b7fc43fb547) + src/Net/Http.fs (b5df1ca30f5bb7749c4fd340b61f1b7fc43fb547) + src/Net/UriUtils.fs (b5df1ca30f5bb7749c4fd340b61f1b7fc43fb547) + remote: fsprojects/FSharp.TypeProviders.SDK + src/ProvidedTypes.fs (b03aeb9b87c24559b99da3b3afdfcfdae0cc3ce0) + src/ProvidedTypes.fsi (b03aeb9b87c24559b99da3b3afdfcfdae0cc3ce0) + src/ProvidedTypesTesting.fs (b03aeb9b87c24559b99da3b3afdfcfdae0cc3ce0) GROUP Build -RESTRICTION: == net45 +RESTRICTION: == net461 NUGET remote: https://www.nuget.org/api/v2 - DotLiquid (2.0.168) - FAKE (4.63) + DotLiquid (2.0.227) + FAKE (4.63.2) FSharp.Compiler.Service (2.0.0.6) FSharp.Core (4.2.3) FSharp.Formatting (2.14.4) @@ -33,12 +33,12 @@ NUGET FSharpVSPowerTools.Core (>= 2.3 < 2.4) FSharpVSPowerTools.Core (2.3) FSharp.Compiler.Service (>= 2.0.0.3) - Octokit (0.24) + Octokit (0.28) Suave (2.2.1) FSharp.Core (>= 4.0.0.1) GITHUB remote: fsharp/FAKE - modules/Octokit/Octokit.fsx (291f58cc70aba6dd871cf18e66d2d88357e4f208) + modules/Octokit/Octokit.fsx (0341a2e614eb2a7f34607cec914eb0ed83ce9add) Octokit (>= 0.20) GROUP OWIN RESTRICTION: == net461 @@ -74,18 +74,18 @@ RESTRICTION: == net461 NUGET remote: https://www.nuget.org/api/v2 Argu (3.7) - Expecto (5.0) + Expecto (5.0.1) Argu (>= 3.7) FSharp.Core (>= 4.1.12) Mono.Cecil (>= 0.10.0-beta5) - FSharp.Compiler.Service (13.0) + FSharp.Compiler.Service (17.0.1) System.Collections.Immutable (>= 1.3.1) System.Reflection.Metadata (>= 1.4.2) FSharp.Core (4.2.3) - redirects: force - FSharp.Data (2.3.3) - Microsoft.NETCore.Platforms (2.0) - Mono.Cecil (0.10.0-beta6) - NETStandard.Library (2.0) + FSharp.Data (2.4.2) + Microsoft.NETCore.Platforms (2.0.1) + Mono.Cecil (0.10.0-beta7) + NETStandard.Library (2.0.1) Microsoft.NETCore.Platforms (>= 1.1) System.Collections.Immutable (1.4) NETStandard.Library (>= 1.6.1) diff --git a/src/SwaggerProvider.DesignTime/DefinitionCompiler.fs b/src/SwaggerProvider.DesignTime/DefinitionCompiler.fs index 068b1a42..b51fbed4 100644 --- a/src/SwaggerProvider.DesignTime/DefinitionCompiler.fs +++ b/src/SwaggerProvider.DesignTime/DefinitionCompiler.fs @@ -1,6 +1,7 @@ namespace SwaggerProvider.Internal.Compilers open ProviderImplementation.ProvidedTypes +open ProviderImplementation.ProvidedTypes.UncheckedQuotations open FSharp.Data.Runtime.NameUtils open SwaggerProvider.Internal open SwaggerProvider.Internal.Schema @@ -28,8 +29,8 @@ type DefinitionCompiler (schema:SwaggerObject) = let providedField = ProvidedField("_" + propertyName.ToLower(), ty) let providedProperty = ProvidedProperty(propertyName, ty, - GetterCode = (fun [this] -> Expr.FieldGet (this, providedField)), - SetterCode = (fun [this;v] -> Expr.FieldSet(this, providedField, v))) + getterCode = (fun [this] -> Expr.FieldGetUnchecked (this, providedField)), + setterCode = (fun [this;v] -> Expr.FieldSetUnchecked(this, providedField, v))) if propName <> propertyName then providedProperty.AddCustomAttribute <| SwaggerProvider.Internal.RuntimeHelpers.getPropertyNameAttribute propName @@ -69,8 +70,7 @@ type DefinitionCompiler (schema:SwaggerObject) = | File, _ -> typeof.MakeArrayType(1) | Enum _, _ -> typeof //TODO: find better type | Array eTy, _ -> (compileSchemaObject (uniqueName tyName "Item") eTy true).MakeArrayType() - | Dictionary eTy,_-> typedefof>.MakeGenericType( - [|typeof; compileSchemaObject (uniqueName tyName "Item") eTy false|]) + | Dictionary eTy,_-> ProvidedTypeBuilder.MakeGenericType(typedefof>, [typeof; compileSchemaObject (uniqueName tyName "Item") eTy false]) | Object properties, _ -> if properties.Length = 0 then typeof else @@ -81,13 +81,13 @@ type DefinitionCompiler (schema:SwaggerObject) = match providedTys.TryGetValue tyName with | true, Some(ty) -> ty :> Type | isExist, _ -> - let ty = ProvidedTypeDefinition(tyName, Some typeof, IsErased = false) + let ty = ProvidedTypeDefinition(tyName, Some typeof, isErased = false) if isExist then providedTys.[tyName] <- Some(ty) else providedTys.Add(tyName, Some(ty)) // Add default constructor - ty.AddMember <| ProvidedConstructor([], InvokeCode = fun _ -> <@@ () @@>) + ty.AddMember <| ProvidedConstructor([], invokeCode = fun _ -> <@@ () @@>) // Generate fields and properties let members = @@ -109,42 +109,41 @@ type DefinitionCompiler (schema:SwaggerObject) = (members |> Array.collect (fun (f,p) -> [|f :> MemberInfo; p:> MemberInfo|]) |> List.ofArray) // Override `.ToString()` - let toStr = ProvidedMethod("ToString", [], typeof, IsStaticMethod = false) - toStr.InvokeCode <- fun args -> - let this = args.[0] - let (pNames, pValues) = - members - |> Array.map (fun (pField, pProp) -> - let pValObj = Expr.FieldGet(this, pField) - pProp.Name, Expr.Coerce(pValObj, typeof) - ) - |> Array.unzip - let pValuesArr = Expr.NewArray(typeof, List.ofArray pValues) - <@@ - let values = (%%pValuesArr : array) - let rec formatValue (v:obj) = - if v = null then "null" - else - let vTy = v.GetType() - if vTy = typeof - then String.Format("\"{0}\"",v) - elif vTy.IsArray - then - let elements = - seq { - for x in (v :?> System.Collections.IEnumerable) do - yield formatValue x - } |> Seq.toArray - String.Format("[{0}]", String.Join("; ", elements)) - else v.ToString() - - let strs = values |> Array.mapi (fun i v -> - String.Format("{0}={1}",pNames.[i], formatValue v)) - String.Format("{{{0}}}", String.Join("; ",strs)) - @@> - toStr.SetMethodAttrs( - MethodAttributes.Public - ||| MethodAttributes.Virtual) + let toStr = + ProvidedMethod("ToString", [], typeof, isStatic = false, + invokeCode = fun args -> + let this = args.[0] + let (pNames, pValues) = + members + |> Array.map (fun (pField, pProp) -> + let pValObj = Expr.FieldGet(this, pField) + pProp.Name, Expr.Coerce(pValObj, typeof) + ) + |> Array.unzip + let pValuesArr = Expr.NewArray(typeof, List.ofArray pValues) + <@@ + let values = (%%pValuesArr : array) + let rec formatValue (v:obj) = + if v = null then "null" + else + let vTy = v.GetType() + if vTy = typeof + then String.Format("\"{0}\"",v) + elif vTy.IsArray + then + let elements = + seq { + for x in (v :?> System.Collections.IEnumerable) do + yield formatValue x + } |> Seq.toArray + String.Format("[{0}]", String.Join("; ", elements)) + else v.ToString() + + let strs = values |> Array.mapi (fun i v -> + String.Format("{0}={1}",pNames.[i], formatValue v)) + String.Format("{{{0}}}", String.Join("; ",strs)) + @@>) + toStr.SetMethodAttrs(MethodAttributes.Public ||| MethodAttributes.Virtual) let objToStr = (typeof).GetMethod("ToString",[||]) ty.DefineMethodOverride(toStr, objToStr) diff --git a/src/SwaggerProvider.DesignTime/OperationCompiler.fs b/src/SwaggerProvider.DesignTime/OperationCompiler.fs index a7b526e9..d21feb59 100644 --- a/src/SwaggerProvider.DesignTime/OperationCompiler.fs +++ b/src/SwaggerProvider.DesignTime/OperationCompiler.fs @@ -42,13 +42,7 @@ type OperationCompiler (schema:SwaggerObject, defCompiler:DefinitionCompiler) = | Some ty -> defCompiler.CompileTy methodName "Response" ty true | None -> typeof - let m = ProvidedMethod(methodName, parameters, retTy) - if not <| String.IsNullOrEmpty(op.Summary) - then m.AddXmlDoc(op.Summary) // TODO: Use description of parameters in docs - if op.Deprecated - then m.AddObsoleteAttribute("Operation is deprecated", false) - - m.InvokeCode <- fun args -> + let m = ProvidedMethod(methodName, parameters, retTy, invokeCode = fun args -> let thisTy = typeof let this = Expr.Coerce(args.[0], thisTy) let host = Expr.PropertyGet(this, thisTy.GetProperty("Host")) @@ -90,7 +84,7 @@ type OperationCompiler (schema:SwaggerObject, defCompiler:DefinitionCompiler) = |> Array.find (fun x -> niceCamelName x.Name = sVar.Name) // ??? param, expr | _ -> - failwithf "Function '%s' does not support functions as arguments." m.Name + failwithf "Function '%s' does not support functions as arguments." methodName ) @@ -186,7 +180,11 @@ type OperationCompiler (schema:SwaggerObject, defCompiler:DefinitionCompiler) = let value = <@@ SwaggerProvider.Internal.RuntimeHelpers.deserialize (%%result : string) retTy @@> Expr.Coerce(value, retTy) - + ) + if not <| String.IsNullOrEmpty(op.Summary) + then m.AddXmlDoc(op.Summary) // TODO: Use description of parameters in docs + if op.Deprecated + then m.AddObsoleteAttribute("Operation is deprecated", false) m /// Compiles the operation. diff --git a/src/SwaggerProvider.DesignTime/SwaggerProvider.DesignTime.fsproj b/src/SwaggerProvider.DesignTime/SwaggerProvider.DesignTime.fsproj index d999ff4c..7e747d42 100644 --- a/src/SwaggerProvider.DesignTime/SwaggerProvider.DesignTime.fsproj +++ b/src/SwaggerProvider.DesignTime/SwaggerProvider.DesignTime.fsproj @@ -43,15 +43,15 @@ - + True paket-files/ProvidedTypes.fsi - + True paket-files/ProvidedTypes.fs - + True paket-files/ProvidedTypesTesting.fs @@ -124,7 +124,7 @@ - + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets @@ -138,7 +138,7 @@ --> - + ..\..\packages\FSharp.Core\lib\net40\FSharp.Core.dll @@ -149,7 +149,7 @@ - + ..\..\packages\YamlDotNet\lib\net35\YamlDotNet.dll diff --git a/src/SwaggerProvider.DesignTime/SwaggerProvider.fs b/src/SwaggerProvider.DesignTime/SwaggerProvider.fs index ebe2c8ff..384c501b 100644 --- a/src/SwaggerProvider.DesignTime/SwaggerProvider.fs +++ b/src/SwaggerProvider.DesignTime/SwaggerProvider.fs @@ -7,7 +7,7 @@ open Microsoft.FSharp.Core.CompilerServices /// The Swagger Type Provider. [] type public SwaggerTypeProvider(cfg : TypeProviderConfig) as this = - inherit TypeProviderForNamespaces() + inherit TypeProviderForNamespaces(cfg) static do // When SwaggerProvider is installed via NuGet/Paket, the Newtonsoft.Json assembly and @@ -17,8 +17,11 @@ type public SwaggerTypeProvider(cfg : TypeProviderConfig) as this = AppDomain.CurrentDomain.add_AssemblyResolve(fun source args -> SwaggerProvider.Internal.Configuration.resolveReferencedAssembly args.Name) + + do this.RegisterRuntimeAssemblyLocationAsProbingFolder cfg + this.AddNamespace( SwaggerProviderConfig.NameSpace, - [SwaggerProviderConfig.typedSwaggerProvider cfg.RuntimeAssembly]) \ No newline at end of file + [SwaggerProviderConfig.typedSwaggerProvider this.TargetContext cfg.RuntimeAssembly]) \ No newline at end of file diff --git a/src/SwaggerProvider.DesignTime/SwaggerProviderConfig.fs b/src/SwaggerProvider.DesignTime/SwaggerProviderConfig.fs index 66fb1a88..2815df7c 100644 --- a/src/SwaggerProvider.DesignTime/SwaggerProviderConfig.fs +++ b/src/SwaggerProvider.DesignTime/SwaggerProviderConfig.fs @@ -1,6 +1,7 @@ namespace SwaggerProvider open System.Reflection +open ProviderImplementation open ProviderImplementation.ProvidedTypes open Microsoft.FSharp.Core.CompilerServices open Microsoft.FSharp.Quotations @@ -14,10 +15,9 @@ open SwaggerProvider.Internal.Compilers module private SwaggerProviderConfig = let NameSpace = "SwaggerProvider" - let internal typedSwaggerProvider runtimeAssemlby = - let asm = Assembly.LoadFrom runtimeAssemlby - - let swaggerProvider = ProvidedTypeDefinition(asm, NameSpace, "SwaggerProvider", Some typeof, IsErased = false) + let internal typedSwaggerProvider (ctx: ProvidedTypesContext) asmLocation = + let asm = Assembly.LoadFrom asmLocation + let swaggerProvider = ProvidedTypeDefinition(asm, NameSpace, "SwaggerProvider", Some typeof, isErased=false) let staticParams = [ ProvidedStaticParameter("Schema", typeof) @@ -34,6 +34,7 @@ module private SwaggerProviderConfig = swaggerProvider.DefineStaticParameters( parameters=staticParams, instantiationFunction = (fun typeName args -> + let tempAsm = ProvidedAssembly() let schemaPathRaw = args.[0] :?> string let ignoreOperationId = args.[2] :?> bool @@ -63,9 +64,8 @@ module private SwaggerProviderConfig = // Create Swagger provider type let baseTy = Some typeof - let ty = ProvidedTypeDefinition(asm, NameSpace, typeName, baseTy, IsErased = false) + let ty = ProvidedTypeDefinition(tempAsm, NameSpace, typeName, baseTy, isErased = false, hideObjectMethods = true) ty.AddXmlDoc ("Swagger.io Provider for " + schema.Host) - ty.HideObjectMethods <- true let protocol = match schema.Schemes with @@ -73,9 +73,8 @@ module private SwaggerProviderConfig = | array -> array.[0] let ctor = ProvidedConstructor( - [ProvidedParameter("host", typeof, - optionalValue = sprintf "%s://%s" protocol schema.Host)], - InvokeCode = fun args -> + [ProvidedParameter("host", typeof, optionalValue = sprintf "%s://%s" protocol schema.Host)], + invokeCode = fun args -> match args with | [] -> failwith "Generated constructors should always pass the instance as the first argument!" | _ -> <@@ () @@>) @@ -89,8 +88,6 @@ module private SwaggerProviderConfig = ty.AddMembers <| opCompiler.CompilePaths(ignoreOperationId) // Add all operations ty.AddMembers <| defCompiler.GetProvidedTypes() // Add all compiled types - let tempAsmPath = System.IO.Path.ChangeExtension(System.IO.Path.GetTempFileName(), ".dll") - let tempAsm = ProvidedAssembly tempAsmPath tempAsm.AddTypes [ty] ty diff --git a/src/SwaggerProvider.Runtime/SwaggerProvider.Runtime.fsproj b/src/SwaggerProvider.Runtime/SwaggerProvider.Runtime.fsproj index 370537e8..898a03a8 100644 --- a/src/SwaggerProvider.Runtime/SwaggerProvider.Runtime.fsproj +++ b/src/SwaggerProvider.Runtime/SwaggerProvider.Runtime.fsproj @@ -76,7 +76,7 @@ --> - + ..\..\packages\FSharp.Core\lib\net40\FSharp.Core.dll @@ -87,7 +87,7 @@ - + ..\..\packages\Newtonsoft.Json\lib\net45\Newtonsoft.Json.dll diff --git a/src/SwaggerProvider/SwaggerProvider.fsproj b/src/SwaggerProvider/SwaggerProvider.fsproj index fc121739..2667296f 100644 --- a/src/SwaggerProvider/SwaggerProvider.fsproj +++ b/src/SwaggerProvider/SwaggerProvider.fsproj @@ -79,7 +79,7 @@ --> - + ..\..\packages\FSharp.Core\lib\net40\FSharp.Core.dll diff --git a/tests/SwaggerProvider.ProviderTests/APIs.Guru.FSC.Tests.fs b/tests/SwaggerProvider.ProviderTests/APIs.Guru.FSC.Tests.fs index b1f5aa09..a11c6ba7 100644 --- a/tests/SwaggerProvider.ProviderTests/APIs.Guru.FSC.Tests.fs +++ b/tests/SwaggerProvider.ProviderTests/APIs.Guru.FSC.Tests.fs @@ -1,26 +1,35 @@ module APIsGuruFSCS -open Microsoft.FSharp.Compiler.SimpleSourceCodeServices +open Microsoft.FSharp.Compiler.SourceCodeServices open System open System.IO open Expecto +open ProviderImplementation.ProvidedTypesTesting +open Fake -let referencedAssemblies = +let assembliesList = let buildTarget name = Path.Combine(__SOURCE_DIRECTORY__, "../../bin/SwaggerProvider/", name) + |> Path.GetFullPath [ - Path.Combine(__SOURCE_DIRECTORY__, "../../packages/test/FSharp.Core/lib/net45/FSharp.Core.dll") - buildTarget "SwaggerProvider.Runtime.dll" - buildTarget "SwaggerProvider.dll" + //yield typeof.Assembly.Location + yield typeof.Assembly.Location + yield typeof.Assembly.Location + yield typeof.Assembly.Location + yield buildTarget "SwaggerProvider.Runtime.dll" + yield buildTarget "SwaggerProvider.dll" ] +let referencedAssemblies = + typeof.Assembly.Location + :: assembliesList |> List.collect (fun path -> if not <| File.Exists(path) then failwithf "File not found '%s'" path ["-r"; path]) -let scs = new System.Threading.ThreadLocal<_>(fun () -> SimpleSourceCodeServices()) +let scs = new System.Threading.ThreadLocal<_>(fun () -> FSharpChecker.Create()) -let compileTP url = +let testTemplate url testBodyFunc = let tempFile = Path.GetTempFileName() let fs = Path.ChangeExtension(tempFile, ".fs") let dll = Path.ChangeExtension(tempFile, ".dll") @@ -30,30 +39,71 @@ let compileTP url = open SwaggerProvider type ProvidedSwagger = SwaggerProvider<"%s"> let instance = ProvidedSwagger() + #if INTERACTIVE + System.Console.WriteLine("Hello from FSI: {0}", instance.Host) + #endif """ url) + try + testBodyFunc fs dll + finally + [tempFile; fs; dll] + |> List.filter File.Exists + |> List.iter File.Delete + +let compileTP fs dll = let errors, exitCode = scs.Value.Compile(Array.ofList (["fsc.exe"; "--noframework"; "-o"; dll; "-a"; fs ] @ referencedAssemblies)) - - [tempFile; fs; dll] - |> List.filter File.Exists - |> List.iter File.Delete + |> Async.RunSynchronously if exitCode <> 0 then failwithf "Compilation error:\n%s" (String.Join("\n", errors |> Array.map(fun x->x.ToString()) )) - [] let compilerTests = List.ofArray APIsGuru.JsonSchemas |> List.map (fun url -> testCase (sprintf "Compile schema %s" url) - (fun _ -> compileTP url) + (fun _ -> testTemplate url compileTP) ) |> testList "Integration/Compile TP" |> testSequenced + + +let referencedAssembliesFsi = + // FSI needs .optdata and .sigdata files near FSharp.Core.dll + Path.Combine(__SOURCE_DIRECTORY__, "../../packages/FSharp.Core/lib/net40/FSharp.Core.dll") + :: assembliesList + |> List.map (fun x -> sprintf "-r:%s" x) + +let fsiTest fs _ = + let args = "--noframework" :: referencedAssembliesFsi |> List.toArray + let isOk, msgs = + executeBuildScriptWithArgsAndFsiArgsAndReturnMessages + fs [||] args false + for msg in msgs do + printfn "%s" msg.Message + if not(isOk) + then failwithf "fsiTest failed" + +let testFsi = isNull <| Type.GetType("Mono.Runtime") +[] +let fsiTests = + APIsGuru.JsonSchemas + |> APIsGuru.shrink 30 + |> List.ofArray + |> List.choose (fun url -> + if testFsi then + testCase + (sprintf "Compile schema %s" url) + (fun _ -> testTemplate url fsiTest) + |> Some + else None + ) + |> testList "Integration/Load TP in FSI" + |> testSequenced \ No newline at end of file diff --git a/tests/SwaggerProvider.ProviderTests/App.config b/tests/SwaggerProvider.ProviderTests/App.config index 4907e91b..072761b1 100644 --- a/tests/SwaggerProvider.ProviderTests/App.config +++ b/tests/SwaggerProvider.ProviderTests/App.config @@ -15,14 +15,4 @@ - - True - - - - - True - - - \ No newline at end of file diff --git a/tests/SwaggerProvider.ProviderTests/SwaggerProvider.ProviderTests.fsproj b/tests/SwaggerProvider.ProviderTests/SwaggerProvider.ProviderTests.fsproj index 60b2c2d3..b6490ccf 100644 --- a/tests/SwaggerProvider.ProviderTests/SwaggerProvider.ProviderTests.fsproj +++ b/tests/SwaggerProvider.ProviderTests/SwaggerProvider.ProviderTests.fsproj @@ -10,6 +10,7 @@ SwaggerProvider.Tests SwaggerProvider.Tests v4.6.1 + true 4.3.0.0 SwaggerProvider.Tests @@ -96,6 +97,9 @@ + + ..\..\packages\build\FAKE\tools\FakeLib.dll + ..\..\bin\SwaggerProvider\SwaggerProvider.dll @@ -159,11 +163,8 @@ - - True - - ..\..\packages\test\FSharp.Data\lib\net40\FSharp.Data.dll + ..\..\packages\test\FSharp.Data\lib\net45\FSharp.Data.dll True True diff --git a/tests/SwaggerProvider.ProviderTests/thing.fsx b/tests/SwaggerProvider.ProviderTests/thing.fsx new file mode 100644 index 00000000..0b2d2caf --- /dev/null +++ b/tests/SwaggerProvider.ProviderTests/thing.fsx @@ -0,0 +1,22 @@ +let createQuote (id : string) = + printfn "Creating Quote %A" id + +let closeQuote (id : string) = + printfn "Closing Quote %A" id + + +let tryF before after f input = + before input + try + f input + finally + after input + +let forQuoteVerify = + tryF createQuote closeQuote + +let myAction id = + printfn "My action for Quote %A" id + id + +forQuoteVerify myAction "QUOTE_ID" \ No newline at end of file diff --git a/tests/SwaggerProvider.Tests/APIs.guru.fs b/tests/SwaggerProvider.Tests/APIs.guru.fs index 068adea3..3bcd6b1c 100644 --- a/tests/SwaggerProvider.Tests/APIs.guru.fs +++ b/tests/SwaggerProvider.Tests/APIs.guru.fs @@ -39,7 +39,7 @@ let private schemaUrls = let private ignoredPrefList = [ // Following schemas require additional investigation and fixes - "https://api.apis.guru/v2/specs/clarify.io/" // StackOverflowException during FCS compilation + //"https://api.apis.guru/v2/specs/clarify.io/" // StackOverflowException during FCS compilation ] let private skipIgnored (url:string) = ignoredPrefList @@ -47,10 +47,11 @@ let private skipIgnored (url:string) = |> not let private rnd = Random(int(DateTime.Now.Ticks)) +let shrink size (arr:'a[]) = + Array.init size (fun _ -> arr.[rnd.Next(size)]) let private shrinkOnMonoTo size arr = if isNull <| Type.GetType ("Mono.Runtime") - then arr - else Array.init size (fun _ -> arr.[rnd.Next(size)]) + then arr else arr |> shrink size let private filter = Array.filter skipIgnored >> shrinkOnMonoTo 80 diff --git a/tests/SwaggerProvider.Tests/SwaggerProvider.Tests.fsproj b/tests/SwaggerProvider.Tests/SwaggerProvider.Tests.fsproj index b2bf79b4..f009b77b 100644 --- a/tests/SwaggerProvider.Tests/SwaggerProvider.Tests.fsproj +++ b/tests/SwaggerProvider.Tests/SwaggerProvider.Tests.fsproj @@ -137,11 +137,8 @@ - - True - - ..\..\packages\test\FSharp.Data\lib\net40\FSharp.Data.dll + ..\..\packages\test\FSharp.Data\lib\net45\FSharp.Data.dll True True diff --git a/tests/SwaggerProvider.Tests/paket.references b/tests/SwaggerProvider.Tests/paket.references index 5bf4bbd4..9e021421 100644 --- a/tests/SwaggerProvider.Tests/paket.references +++ b/tests/SwaggerProvider.Tests/paket.references @@ -1,4 +1,5 @@ + group Test Expecto FSharp.Data - FSharp.Core \ No newline at end of file + FSharp.Core diff --git a/tests/Swashbuckle.OWIN.Server/App.config b/tests/Swashbuckle.OWIN.Server/App.config index 3a684fd6..8f28d31f 100644 --- a/tests/Swashbuckle.OWIN.Server/App.config +++ b/tests/Swashbuckle.OWIN.Server/App.config @@ -20,25 +20,5 @@ - - True - - - - - True - - - - - True - - - - - True - - - \ No newline at end of file