Burgyn / MMLib.SwaggerForOcelot

This repo contains swagger extension for ocelot.
MIT License
351 stars 93 forks source link

OpenApi fails on reading file #268

Closed sirdawidd closed 1 year ago

sirdawidd commented 1 year ago

Hello, I've tried to publish my openapi.json When the file is read by library it throws an error:

[11:44:04 INF] Start processing HTTP request GET http://localhost:8080/camunda/swaggerui/openapi.json [11:44:04 INF] Sending HTTP request GET http://localhost:8080/camunda/swaggerui/openapi.json [11:44:04 INF] Received HTTP response headers after 17.694ms - 200 [11:44:04 INF] End processing HTTP request after 33.6067ms - 200 [11:44:04 ERR] An unhandled exception has occurred while executing the request. System.UriFormatException: Invalid URI: The hostname could not be parsed. at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind, UriCreationOptions& creationOptions) at System.Uri..ctor(String uriString, UriKind uriKind) at MMLib.SwaggerForOcelot.Transformation.SwaggerJsonTransformer.TransformOpenApi(JObject openApi, IEnumerable1 routes, String serverOverride, SwaggerEndPointOptions endPointOptions) at MMLib.SwaggerForOcelot.Transformation.SwaggerJsonTransformer.Transform(String swaggerJson, IEnumerable1 routes, String serverOverride, SwaggerEndPointOptions endPointOptions) at MMLib.SwaggerForOcelot.Middleware.SwaggerForOcelotMiddleware.Invoke(HttpContext context, ISwaggerEndPointProvider swaggerEndPointRepository, IDownstreamSwaggerDocsRepository downstreamSwaggerDocs) at Microsoft.AspNetCore.Builder.Extensions.MapMiddleware.InvokeCore(HttpContext context, PathString matchedPath, PathString remainingPath) at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.MiddlewareAnalysis.AnalysisMiddleware.Invoke(HttpContext httpContext) at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)

File is generated automatically via openapi lib. Don't throw any error on https://editor.swagger.io/

https://github.com/sirdawidd/cammundaOpenApi/blob/main/openapi.json

Burgyn commented 1 year ago

Hi @sirdawidd,

thanks for your issue. Unfortunately this package in this version does not support server definition like that:

{
  "url": "http://{host}:{port}/{contextPath}",
  "description": "The API server for the default process engine",
  "variables": {
    "host": {
      "default": "localhost"
    },
    "port": {
      "default": "8080"
    },
    "contextPath": {
      "default": "engine-rest"
    }
  }
}

If it's possible for you so replace url template for value http://localhost:8080/engine-rest or try open PR with fix. Problem is in the class SwaggerJsonTransformer, method TransformOpenApi line 106.

github-actions[bot] commented 1 year ago

Closing after 8 days of waiting for the additional info requested.