是否可以在 OpenApi 3 中创建特定于环境的路径?

Is it possible to create environment specific paths in OpenApi 3?

我的目标:

我正在处理应用程序中的一组端点,并且我有一个包含所有端点的 swagger 2.0 文件。他们正在我们的测试环境中工作,但我们还不会在产品中提供它们。

我的问题是:

如果我升级到 OpenApi 3,是否可以通过 servers 对象隐藏我不想在产品中可见的路径?

我不认为这是阅读文档的结果,但我很乐意在那里犯错,因为我更希望每个环境只有一个 api.yml 而不是一个。

谢谢!

我做了一些测试,答案是否定的。

  • 您可以选择用户可以运行 "try it out" 测试哪些服务器。这是一个很棒的功能
  • 但是,您不能根据从页面顶部的下拉列表中选择的服务器来隐藏端点。最初的目标是什么

下面是我用在线编辑器验证的OpenAPI yaml。我在这里使用在线编辑器:Swagger Editor and used the petstore.yaml example provided at the OpenAPI-Specification github repo as a starting point. I removed all but one endpoint to shorten things. If you are starting an open api document I would recommend visiting OpenAPI or Swagger 查找文档和完整示例。

openapi: "3.0.0"
info:
version: 1.0.0
title: Swagger Petstore
description: Try to not show get when prod server is chosen
license:
    name: MIT
servers:
- url: http://prod      
- url: http://test
- url: http://dev
paths:
/pets:
    get:
    summary: List all pets
    operationId: listPets
    tags:
        - pets
    parameters:
        - name: limit
        in: query
        description: How many items to return at one time (max 100)
        required: false
        schema:
            type: integer
            format: int32
    servers: 
        - url: http://test
        - url: http://dev
    responses:
        200:
        description: An paged array of pets
        headers:
            x-next:
            description: A link to the next page of responses
            schema:
                type: string
        content:
            application/json:    
            schema:
                $ref: "#/components/schemas/Pets"
        default:
        description: unexpected error
        content:
            application/json:
            schema:
                $ref: "#/components/schemas/Error"

components:
schemas:
    Pet:
    required:
        - id
        - name
    properties:
        id:
        type: integer
        format: int64
        name:
        type: string
        tag:
        type: string
    Pets:
    type: array
    items:
        $ref: "#/components/schemas/Pet"
    Error:
    required:
        - code
        - message
    properties:
        code:
        type: integer
        format: int32
        message:
        type: string