Lanayx / Oxpecker

ASP.NET Core based F# framework
MIT License
256 stars 10 forks source link

openapi not working (tried both builder and slimbuilder) #25

Open jkone27 opened 6 days ago

jkone27 commented 6 days ago

maybe did smt wrong, but cannot see endpoints in /swagger with this script

// https://github.com/TheAngryByrd/IcedTasks/blob/master/generate-sdk-references.fsx
#nowarn "20" // for OOP/ignore values
#load "runtime-scripts/Microsoft.AspNetCore.App-latest-8.fsx"
#r "nuget: Oxpecker"
#r "nuget: Oxpecker.OpenApi"
#r "nuget: Swashbuckle.AspNetCore "

open Microsoft.AspNetCore.Builder
open Microsoft.Extensions.DependencyInjection
open Oxpecker
open Oxpecker.OpenApi
open Microsoft.Extensions.DependencyInjection
open Microsoft.Extensions.Configuration
open Swashbuckle.AspNetCore.SwaggerGen
open Microsoft.OpenApi.Models

let endpoints = [

    route "/hello" 
        ("Hello World!" |> text)
        |> configureEndpoint _.WithName("Hello")
        |> addOpenApiSimple<unit, string>

    route "/hello-json" 
        ("""{ "Hello": "World!" }""" |> json)
        |> configureEndpoint _.WithName("HelloJson")
        |> addOpenApiSimple<unit, {| Hello: string |}>
]

let configure (builder: WebApplicationBuilder) =
    builder.Services
        .AddRouting()
        .AddOxpecker()
        .AddEndpointsApiExplorer()
        .AddSwaggerGen()
    builder.Build()

let configureApp (app: WebApplication) =
    app.UseRouting()
        .UseOxpecker(endpoints)
        .UseSwagger() // for generating OpenApi spec
        .UseSwaggerUI() // for viewing Swagger UI
    app

let webApp = 
    WebApplication.CreateSlimBuilder()
    |> configure
    |> configureApp

webApp.Run()
Lanayx commented 6 days ago

@jkone27 Have you check the ASP.NET documentation? https://learn.microsoft.com/en-us/aspnet/core/tutorials/web-api-help-pages-using-swagger?view=aspnetcore-8.0 The url should be /swagger/v1/swagger.json, can you check if it works?

UPDATE: Ah, you are probably asking about UI. Not sure why it's not working at the moment, I probably never checked it, only the json

Lanayx commented 6 days ago

I've just updated Basic example, so Swagger works properly there, you can check. If it doesn't work with your script, it means that something is missing in yourruntime-scripts/Microsoft.AspNetCore.App-latest-8.fsx file

jkone27 commented 6 days ago

This is awesome! Thank you✨ what was wrong in my script, not sure I don't see results in /swagger that will open the UI..

I will try check better