Git Product home page Git Product logo

sitelets's People

Contributors

btamas2000 avatar jand42 avatar jooseppi12 avatar mrtank avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

btamas2000 mrtank

sitelets's Issues

Add OpenApi Middleware for SwaggerUI support

Using Sitelet's Endpoint's type it's possible to generate an OpenAPI documentation for simple cases. The documentation for OpenAPI documentation can be found here. With SwaggerUI it's possible to provide a documentation endpoint and offer test calls against the API.

.UseOpenApi(endpointsType: Type, config: OpenApiIntegration.GenerateOpenApiConfig)

is an extension method on IEndpointRouteBuilder, which configures the site to route /swagger.json calls to provide the generated OpenAPI documentation for the user.

    type GenerateOpenApiConfig = {
            Version: string
            Title: string
            ServerUrls: string []
            SerializerOptions: JsonSerializerOptions
        }

config contains the required Info Object's Version and Title fields, ServerUrls and JsonSerializerOptions for ISerializerDataContractResolver. JsonSerializerOptions requires https://github.com/Tarmil/FSharp.SystemTextJson.

To set up SwaggerUI .UseSwaggerUI needs to point to /swagger.json.

Example code on an IApplicationBuilder to setup /swagger endpoint for SwaggerUI

open System.Text.Json
open System.Text.Json.Serialization
open Microsoft.AspNetCore.Builder
...
let servers = [| "http://localhost:5000"; "https://localhost:5001" |]
let serializerOptions = 
    let options = JsonSerializerOptions (PropertyNamingPolicy=JsonNamingPolicy.CamelCase)
    options.Converters.Add( JsonStringEnumConverter())
    options.Converters.Add(
        JsonFSharpConverter(
            JsonUnionEncoding.ExternalTag
            ||| JsonUnionEncoding.NamedFields
            ||| JsonUnionEncoding.UnwrapFieldlessTags
            ||| JsonUnionEncoding.UnwrapOption))
    options
...
app
    .UseRouting()
    .UseEndpoints(fun e ->
        e.UseOpenApi(typeof<MyEndpoint>, {
            Version = "1.0.0.0"
            Title = "Title"
            ServerUrls = servers
            SerializerOptions = serializerOptions
            }))
    .UseSwaggerUI(fun c -> c.SwaggerEndpoint("/swagger.json", "My API V1"))
    ...

Documentation generation is restricted to an Endpoint type of Discriminated Union, with primitive system type union fields. int, float, string.

Example Endpoint type:

type Endpoint =
    | [<EndPoint "GET /echo">] Data of msg:string * value:int
    | [<EndPoint "GET /actionresult">] ActionResult
    | [<EndPoint "GET /task/str">] Task1
    | [<EndPoint "GET /task/actionresult">] Task2
    | [<EndPoint "GET /task/enumerable">] Task3
    | [<EndPoint "GET /enum">] Enumerable1
    | [<EndPoint "GET /enum/async">] Enumerable2
    | Test1
    | Test2

Where no annotation defines the Operation (for example Get/Post), the default is Get.
Parameter name defaults to it's Type's .Name.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.