stoplightio / http-spec

Utilities to normalize OpenAPI v2 and v3 objects for the Stoplight ecosystem.

Home Page:https://stoplight.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

OpenAPI security definition "key" is not transformed

lottamus opened this issue · comments

Describe the bug
The "key" is a very valuable piece of information since most schemes don't have a "name" property. We need to use this property to display information in docs and to address this issue: https://github.com/stoplightio/studio/issues/257

To Reproduce

  1. Create an OpenAPI file in Studio and add some security schemes
  2. Grab the active node's data in the console: __SL.activeProjectStore.studioStore.uiStore.activeNode.children[3].data
  3. Notice the HttpService doesn't include security scheme's key property

Example OpenAPI V2

{
  "swagger": "2.0",
  "info": {
    "title": "OAS2",
    "version": "1.0"
  },
  "host": "localhost:3000",
  "schemes": [
    "http"
  ],
  "produces": [
    "application/json",
    "application/xml"
  ],
  "consumes": [
    "application/json"
  ],
  "paths": {
    "/path": {
      "$ref": "../test-api/openapi.yaml#/paths/~1path"
    }
  },
  "definitions": {
    "Embedded-Model": {
      "type": "object",
      "title": "User",
      "enum": [
        "foo",
        "bar"
      ],
      "properties": {
        "foo": {
          "type": "object"
        }
      }
    }
  },
  "securityDefinitions": {
    "API Key - 1": {
      "type": "oauth2",
      "flows": {
        "implicit": {
          "refreshUrl": "foo",
          "scopes": []
        },
        "clientCredentials": {
          "tokenUrl": "",
          "refreshUrl": "",
          "scopes": []
        }
      },
      "scopes": {
        "scope_1": "bar"
      },
      "flow": "password"
    }
  }
}

Actual HttpService

{
  "id": "?http-service-id?",
  "name": "OAS2",
  "title": "OAS2",
  "version": "1.0",
  "servers": [
    {
      "name": "OAS2",
      "url": "http://localhost:3000"
    }
  ],
  "tags": [],
  "security": [],
  "securitySchemes": [
    {
      "type": "oauth2",
      "flows": {
        "password": {
          "scopes": {
            "scope_1": "bar"
          }
        }
      }
    }
  ]
}

Expected HttpService

{
  "id": "?http-service-id?",
  "name": "OAS2",
  "title": "OAS2",
  "version": "1.0",
  "servers": [
    {
      "name": "OAS2",
      "url": "http://localhost:3000"
    }
  ],
  "tags": [],
  "security": [],
  "securitySchemes": [
    {
      "key": "API Key - 1",
      "type": "oauth2",
      "flows": {
        "password": {
          "scopes": {
            "scope_1": "bar"
          }
        }
      }
    }
  ]
}

Additional Context

  1. We should update ISecurityScheme to include a key property: https://github.com/stoplightio/types/blob/d2401b0c69c23e5164fe8ce4e811be10958f74ad/src/http-spec.ts#L166
interface ISecurityScheme {
  key: string;
  description?: string;
}
  1. We should add a test to make sure the "key" property is being added to both oas2 and oas3 for each scheme type:

Closed with #48