stoplightio / prism

Turn any OpenAPI2/3 and Postman Collection file into an API server with mocking, transformations and validations.
https://stoplight.io/open-source/prism
Apache License 2.0
4.33k stars 350 forks source link

Support "encoding" keyword - Requests to Mocked API on postman results 422 error #1622

Open tiagomarto opened 3 years ago

tiagomarto commented 3 years ago

Describe Issue

I'm mocking a API that receives as input a x-www-form-urlencoded containing a key called request and a json as value (yaml below for reference).

openapi: "3.0.0"
info:
  description: "Example Documentation"
  version: "1.0.0"
  title: "Example"
servers:
  - url: http://myurl.com
tags:
  - name: "example"
    description: "example"
paths:
  /json:
    post:
      tags:
        - example
      summary: "this is my example"
      description: ""
      requestBody:
        required: true
        content:
          application/x-www-form-urlencoded:
            schema:
              type: object
              properties:
                request:
                  $ref: "#/components/schemas/request"
            encoding:
              request:
                contentType: application/json

      responses:
        "200":
          description: "OK"
          content:
            application/json:
              schema:
                type: object
                properties:
                  responseCode:
                    type: integer
                    example: 0
                  description:
                    type: string
                    example: "OK"
                  url:
                    type: string
                    example: "http://myurl.com/response"

components:
  schemas:
    request:
      type: object
      required:
        - amount
        - merchant_id
      properties:
        amount:
          type: integer
          example: 100
        merchant_id:
          type: string
          example: "merchant_id"

I'm running Prism in a docker container and running the yaml file to generate the mock.

The docker command i'm using is as below:

docker run --init --rm -v ${PWD}:/tmp -p 4010:4010 stoplight/prism mock -h 0.0.0.0 "/tmp/example.yaml"

Yet, when I make a request in postman at /json it returns me 422 error, as seen in the picture:

Postman Output

Expected Behavior

I Expect Prism to give me the 200 code output with the response examples

Is this a problem from my setup or Prism can't handle this input format?

philsturgeon commented 3 years ago

Correct, we do not support the encoding keyword just yet, that's a power user thing you don't often see in the wild.

Fancy rolling your sleeves up and giving us a hand? It looks like there's two of you interested, but we've got more features on our roadmap than we have developers to write them.

gabriel-bazan-pp commented 3 years ago

Hey team, do you have plans for adding support for application/x-www-form-urlencoded request bodies anytime soon?

ryotrellim commented 3 years ago

Removing points to re-groom and discuss with team.

chohmann commented 3 years ago

Hey team! Please add your planning poker estimate with ZenHub @Amjcraft @lukasz-kuzynski-11sigma @radzserg @rainum

philsturgeon commented 3 years ago
chohmann commented 2 years ago

Hey team! Please add your planning poker estimate with ZenHub @Amjcraft @daniel-white @EdVinyard @jasonmgillhub @rainum