Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Free-form object with application/x-www-form-urlencoded not providing input field in Swagger UI #5072

Closed
mileusna opened this issue Dec 10, 2018 · 3 comments

Comments

@mileusna
Copy link

mileusna commented Dec 10, 2018

  • OS: MACOS
  • Browser: Safari, Chrome
  • Version: latest
  • Method of installation: web editor and swagger hub
  • Swagger-UI version: current editor on your site
  • Swagger/OpenAPI version: OpenAPI 3.0

I'm using so called "free form" objects in my posts. When I want to post with application/x-www-form-urlencoded with "free-form" object, your UI doesn't provide any form of input to insert "free-form" object. If the content-type is application/json then there is an input box to write down the object, but not with application/x-www-form-urlencoded.

screen shot 2018-12-10 at 19 45 01

Example Swagger/OpenAPI definition:

openapi: "3.0.0"
info:
  description: "A sample API for "
  version: "1.0.0"
  title: "Sample"
  contact:
    name: ""
    url: "http://website.com"
    email: "[email protected]"
servers:
  - url: https://api.website.com/api
    description: Development server
paths:
  /objects:
    post:
      summary: Create/modify object
      operationId: postObject
      parameters:
        - name: filterParams
          in: query
          description: Additional filter fields
          required: false
          schema:
            type: object
      requestBody:
        content:
          application/x-www-form-urlencoded:
            schema:
              type: object  
      responses:
        '200':
          description: Status message
          content:
            application/json:
              schema:
                  $ref: '#/components/schemas/Status'
components:
  schemas:
    Status:
      type: object
      properties:
        Error:
          description: Error information, if any
          type: object
          properties:
            Code:
              description: Error code
              type: integer
            Message:
              description: Error message
              type: string
        Success:
          description: Success message 
          type: object
          properties:
            Message:
              description: Success message
              type: string
@shockey
Copy link
Contributor

shockey commented Jan 4, 2019

This is a limitation on our part of the application/x-www-form-urlencoded form handling we have implemented - we expect properties to be defined and generate key/value pair inputs based on it.

@mileusna
Copy link
Author

You can use free-form in body if the type is application/json. And if your API call supports both application/json and application/x-www-form-urlencoded you can actually "hack" the Swagger interface.

  1. You select the application/json from drop down menu and it will ofer you to create free form object. Create your name/value object.
  2. Switch back to application/x-www-form-urlencoded. The input field for free-form object will disappear. But nevermind that and click Execute.
  3. Swagger will actually post your free-form object you have created with application/json as application/x-www-form-urlencoded with no problem.

So, the functionality is there, you just have to enable it, so we won't have to use tricks. ;)

@shockey
Copy link
Contributor

shockey commented Feb 14, 2019

Fixed 🙂 thanks for filing, @mileusna!

@lock lock bot locked and limited conversation to collaborators Feb 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants