swagger-api / swagger-ui

Swagger UI is a collection of HTML, JavaScript, and CSS assets that dynamically generate beautiful documentation from a Swagger-compliant API.
https://swagger.io
Apache License 2.0
26.42k stars 8.93k forks source link

Add UI support for SEARCH HTTP verb/method #10085

Open doronguttman opened 2 months ago

doronguttman commented 2 months ago

Content & configuration

Swagger/OpenAPI definition:

openapi: 3.0.0
paths:
  /v1/my-api:
    search:
      operationId: MyApiControllerV1_find
      summary: Find a record ID
      parameters: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/RecordFindDto'
      responses:
        '200':
          description: The ID of the record
          content:
            text/plain:
              schema:
                type: string
        '403':
          description: >-
            Returned when your API key is invalid or you do not have the
            required scopes [my-api:read].
        '404':
          description: Record not found
      security:
        - bearer:
            - my-api:read
      tags:
        - 'scopes: [my-api:read]'
info:
  title: My API
  description: ''
  version: '1.0'
  contact: {}
tags: []
servers: []
components:
  securitySchemes:
    bearer:
      scheme: bearer
      type: http
      bearerFormat: myapi_{token}
  schemas:
    RecordFindDto:
      type: object
      properties:
        arg1:
          type: number
        arg2:
          type: string
        arg3:
          type: string
        arg4:
          type: string
        arg5:
          type: string
        arg6:
          type: number
        arg7:
          type: string
      required:
        - arg1
        - arg2
        - arg4
        - arg5
        - arg7

Swagger-UI configuration options:

SwaggerUIBundle({
    url: "https://localhost:3001/swagger-json",
    dom_id: "#swagger-ui",
    presets: [
      SwaggerUIBundle.presets.apis,
      SwaggerUIStandalonePreset
    ],
    plugins: [
      SwaggerUIBundle.plugins.DownloadUrl
    ],
    // requestSnippetsEnabled: true,
    layout: "StandaloneLayout"
  })
 ?yourQueryStringConfig
-> none

Is your feature request related to a problem?

Add UI support for SEARCH verb

Describe the solution you'd like

add the SEARCH verb to the list of supported methods. swagger itself already supports it

Describe alternatives you've considered

tried to see if there's a plugin available and did not find one

Additional context

we have an endpoint that is used to search for a record (does not mutate) and has multiple required arguments to be provided in the body of the request. GET with body is not supported by most frameworks. SARCH is becoming quite common

amiii123malviya commented 2 months ago

Would Like to work on this issue.. Let me work on this ..

doronguttman commented 2 months ago

Would Like to work on this issue.. Let me work on this ..

https://github.com/swagger-api/swagger-ui/pull/10086 🤷

JaredAAT commented 1 month ago

OpenAPI doesn't seem to support the SEARCH verb as part of the spec: https://spec.openapis.org/oas/latest.html#path-item-object

tuan-nguyen-wareflex commented 1 month ago

OpenAPI was last published on February 15, 2021, and is outdated due to daily technical changes. I use NestJS, which supports the Search method, but Swagger UI does not support it.

JaredAAT commented 1 month ago

@tuan-nguyen-wareflex You can help change the OpenAPI specification, there is a discussion here: https://github.com/OAI/OpenAPI-Specification/issues/1747 related to different HTTP verbs and whether they have massive support in the wild since SEARCH comes from WebDAV which is/was a Microsoft specific technology/RFC

doronguttman commented 1 month ago

@JaredAAT, please note that though the specs may not support is, OpenAPI actually DOES support it EXCEPT for the UI. The proposed fix is to align the UI with the generated definitions so it displays what the OpenAPI definitions already support

JaredAAT commented 1 month ago

@doronguttman well no... lots of confusion in that sentence there. OpenAPI does not support it, you may think that because you can add any verb to the specs that it does, but in actuality, until the issue i highlighted in my previous comment, OpenAPI does not support SEARCH or various other verbs that are not listed in the specs here: https://spec.openapis.org/oas/latest.html#path-item-object

There is no UI to OpenAPI. Swagger (which is what we're commenting on here) is a UI that can display OpenAPI documents/specs but is not the UI of OpenAPI, there are other UI's that you can get that display OpenAPI specs. If swagger were to support SEARCH as a verb, they'd be operating outside of the OpenAPI specification