OpenAPI or swagger.json auto discovery

前端 未结 3 1601
闹比i
闹比i 2021-01-13 07:57

Is there any spec or convention on URL where one should place swagger.json (or whatever name it is agreed) so that public API of my site can be automatically di

3条回答
  •  有刺的猬
    2021-01-13 08:14

    Okay. OpenAPI 3.0 still lacking auto-discovery mechanism, I try to propose a scheme based on some things that were already working:

    1. https://example.com/.well-known/schema-discovery is a JSON document pointing to array of available schemas:

      [
        {
          "schema_url": "/openapi.json",
          "schema_type": "openapi-3.0"
        },
        {
          "schema_url": "/v2/openapi.json",
          "schema_type": "openapi-3.0"
        }
      ]
      
    2. If there is only one version of API, then https://example.com/openapi.json should be enough.

    3. HTTP Headers. I remember somebody from Google proposed HTTP header for pointing to API. If you can find or remember it, please tell me.

提交回复
热议问题