Burgyn / MMLib.SwaggerForOcelot

This repo contains swagger extension for ocelot.
MIT License
353 stars 94 forks source link

Schema Invalid : http port not valid #93

Closed ThiyagarajanVellaichamy closed 4 years ago

ThiyagarajanVellaichamy commented 4 years ago

everything has been rendered in view, when trying to execute API through Swagger, getting invalid schema. find the configuration and screen shot below, please help me out, if there I missed anything from my end.

ocelot.json: { "ReRoutes": [ { "DownstreamPathTemplate": "/api/{everything}", "DownstreamScheme": "https", "DownstreamHostAndPorts": [ { "Host": "localhost", "Port": 5001 } ], "UpstreamPathTemplate": "/auth-service/{everything}", "UpstreamHttpMethod": [ "Get", "Post" ], "SwaggerKey": "authswagger", "VirtualDirectory": "/authswagger" } ], "SwaggerEndPoints": [ { "Key": "gateway", "TransformByOcelotConfig": false, "Config": [ { "Name": "Gateway", "Version": "v1", "Url": "https://localhost:5003/swagger/v1/swagger.json" } ] }, { "Key": "authswagger", "Config": [ { "Name": "Authentication API", "Version": "v1", "Url": "https://localhost:5001/api/swagger/v1/swagger.json" } ] } ], "GlobalConfiguration": { "BaseUrl": "https://localhost" } } Screenshot 2020-05-03 at 23 12 28

Burgyn commented 4 years ago

Hi, I try to figure out where the problem is, but without success.

I don't know why he create the wrong address. localhost://5003. You do not have a special value filled in baseUrl in downstream service swagger?

And one question? Need you really VirtualDirectory? VirtualDirectory is necessary only if you host your service as virtual app in IIS.

ThiyagarajanVellaichamy commented 4 years ago

Hi, I try to figure out where the problem is, but without success.

I don't know why he create the wrong address. localhost://5003. You do not have a special value filled in baseUrl in downstream service swagger?

And one question? Need you really VirtualDirectory? VirtualDirectory is necessary only if you host your service as virtual app in IIS.

Thanks for the valuable Answer,

I have removed virtual directory too, but it gives same result.

  1. I have used API Gate way which is running under 5003 port.
  2. It has ocelot configuration, and ran the application then navigated to swagger page.
  3. It has two option I. Gate Way API - port: 5003 ii. Authentication API -port: 5001
  4. when I'm choosing Authentication API, it's rendered with API in swagger page, but url comes like localhost://5003, Is there anyway to get resolved or Am I done anything wrong in the configuration.

Kindly help me out.

Burgyn commented 4 years ago

For further investigation, Can you provide your AuthorizationApi downstream swagger (original, before transforming by this library).

Thanks.

ThiyagarajanVellaichamy commented 4 years ago

For further investigation, Can you provide your AuthorizationApi downstream swagger (original, before transforming by this library).

Thanks. services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "Authentication Services", Version = "v1", Description = "Authentication service" }); c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme { In = ParameterLocation.Header, Description = "Please enter into field the word 'Bearer' following by space and JWT", Name = "Authorization", Type = SecuritySchemeType.ApiKey, Scheme = "Bearer" }); c.AddSecurityRequirement(new OpenApiSecurityRequirement() { { new OpenApiSecurityScheme { Reference = new OpenApiReference { Type = ReferenceType.SecurityScheme, Id = "Bearer" }, Scheme = "oauth2", Name = "Bearer", In = ParameterLocation.Header }, new List() } }); });

Burgyn commented 4 years ago

sorry but i meant swagger.json.

ThiyagarajanVellaichamy commented 4 years ago

sorry but i meant swagger.json.

{ "openapi": "3.0.1", "info": { "title": "Authentication Services", "description": "Authentication service", "version": "v1" }, "servers": [ { "url": "/api" } ], "paths": { "/v{version}/Authentication": { "post": { "tags": [ "Authentication" ], "parameters": [ { "name": "version", "in": "path", "required": true, "schema": { "type": "string" } } ], "requestBody": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/PostAuth" } }, "text/json": { "schema": { "$ref": "#/components/schemas/PostAuth" } }, "application/*+json": { "schema": { "$ref": "#/components/schemas/PostAuth" } } } }, "responses": { "200": { "description": "Success", "content": { "text/plain": { "schema": { "$ref": "#/components/schemas/LoginResponseResult" } }, "application/json": { "schema": { "$ref": "#/components/schemas/LoginResponseResult" } }, "text/json": { "schema": { "$ref": "#/components/schemas/LoginResponseResult" } } } } } }, "get": { "tags": [ "Authentication" ], "parameters": [ { "name": "version", "in": "path", "required": true, "schema": { "type": "string" } } ], "responses": { "200": { "description": "Success", "content": { "text/plain": { "schema": { "type": "string" } }, "application/json": { "schema": { "type": "string" } }, "text/json": { "schema": { "type": "string" } } } } } } } }, "components": { "schemas": { "PostAuth": { "required": [ "password", "userName" ], "type": "object", "properties": { "userName": { "type": "string" }, "password": { "type": "string" } }, "additionalProperties": false }, "LoginResponse": { "type": "object", "properties": { "id": { "type": "integer", "format": "int64" }, "name": { "type": "string", "nullable": true }, "token": { "type": "string", "nullable": true }, "refreshToken": { "type": "string", "nullable": true } }, "additionalProperties": false }, "Status": { "enum": [ 0, 1, 2, 3 ], "type": "integer", "format": "int32" }, "LoginResponseResult": { "type": "object", "properties": { "data": { "$ref": "#/components/schemas/LoginResponse" }, "status": { "$ref": "#/components/schemas/Status" }, "message": { "type": "string", "nullable": true, "readOnly": true } }, "additionalProperties": false } }, "securitySchemes": { "Bearer": { "type": "apiKey", "description": "Please enter into field the word 'Bearer' following by space and JWT", "name": "Authorization", "in": "header" } } }, "security": [ { "Bearer": [ ] } ] }

Burgyn commented 4 years ago

Hi,

thanks for sharing your settings, they helped me understand the issue.

Problem description

You have (I don't know why) in your swagger this setting:

"servers": [
  {
    "url": "/api"
  }
]

See swagger documentation

Workaround

If you really need this settings, than you can change it in ocelot config.

{
  "Key": "authswagger",
  "HostOverride": "",
  "Config": [
    {
      "Name": "Authentication API",
      "Version": "v1",
      "Url": "http://localhost:5300/swagger.json"
    }
  ]
}

The key is "HostOverride": "",

I hope I helped.

ThiyagarajanVellaichamy commented 4 years ago

Hi,

thanks for sharing your settings, they helped me understand the issue.

Problem description

You have (I don't know why) in your swagger this setting:

"servers": [
  {
    "url": "/api"
  }
]

See swagger documentation

Workaround

If you really need this settings, than you can change it in ocelot config.

{
  "Key": "authswagger",
  "HostOverride": "",
  "Config": [
    {
      "Name": "Authentication API",
      "Version": "v1",
      "Url": "http://localhost:5300/swagger.json"
    }
  ]
}

The key is "HostOverride": "",

I hope I helped.

Yes, You resolved the issue, thanks.

Burgyn commented 4 years ago

I am glad to hear that