【问题标题】:version appearing twice in url when using versioned api with Azure API Managment将版本化 api 与 Azure API 管理一起使用时,版本在 url 中出现两次
【发布时间】:2020-02-17 15:38:52
【问题描述】:

我已将我的版本化 API 与 swagger 和 Azure API 管理集成在一起。一旦我导入 swagger 定义 API 管理,版本号就会出现两次。有没有更好的方法可以通过 swagger 或 API 管理来做到这一点,这样第二个 V1 就不会出现?

API 管理网址https://my-apimgnt.azure-api.net/myapi-dev/v1/api/v1/user/Skills/get

直接网址/后端 https://jsdevsf.api.mydomain.com/api/v1/user/Skills

[ApiVersion("1.0")]
[Route("api/v{version:apiVersion}/user/[controller]")]
[ApiController]

大摇大摆的定义

{
"swagger": "2.0",
"info": {
"version": "2.0",
"title": "MyAPI 2.0",
"termsOfService": "None",
"contact": {
"name": "mySupport",
"email": "support@my.com"
}
},
"basePath": "/my.Application/my.WebAPI",
"paths": {

    "/api/v1/user/Skills/get/{ProductId}": {}
}

【问题讨论】:

    标签: azure swagger azure-api-management


    【解决方案1】:

    路径相对于 basePath 或 Base URI。

    看起来您只需要从您的招摇定义中删除 /api/v1 部分。所以你的定义应该是:

    {
    "swagger": "2.0",
    "info": {
    "version": "2.0",
    "title": "MyAPI 2.0",
    "termsOfService": "None",
    "contact": {
    "name": "mySupport",
    "email": "support@my.com"
    }
    },
    "basePath": "/my.Application/my.WebAPI",
    "paths": {
    
        "/user/Skills/get/{ProductId}": {}
    }
    

    要从 Azure 执行此操作,请转到设计 -> 前端 -> OpenAPI 规范编辑器

    从这里您应该会看到 basePath 和路径。 Swagger Editor 还应该显示并允许您配置这些值。

    【讨论】:

    • 不知道该怎么做。当生成 swagger.json 时,它带有 /api/v1。如何确保它不会出现在路径下。
    • 更新了我的答案。如果找不到,请说明您使用的编辑器。
    猜你喜欢
    • 2018-12-17
    • 1970-01-01
    • 2020-11-25
    • 1970-01-01
    • 1970-01-01
    • 2021-03-16
    • 2023-03-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多