Skip to content

multipart/form-data - validation fails #949

@adabuleanu

Description

@adabuleanu

For the following openapi 3 multi-part:

openapi: 3.0.3
paths:
  /endpoint:
    post:
      operationId: create
      requestBody:
        content:
          multipart/form-data:
            schema:
              $ref: "#/components/schemas/Request"
components:
  schemas:
    Request:
      type: object
      properties:
        mystring:
          type: string
        myint:
          type: integer
        myobjj:
          type: object

And using the following curl command:

 curl -X 'POST' 'http://localhost/endpoint'  \
        -H 'accept: application/json' \
        -H 'Content-Type: multipart/form-data'   \
        -F 'mystring=test' \
        -F 'myint=0'
        -F 'myobj={"key1":"val1"}'  

The validation for the myint and myobj fails with

request body has an error: doesn't match schema #/components/schemas/Request: Error at "/myint": value must be an integer
request body has an error: doesn't match schema #/components/schemas/Request: Error at "/myobj": value must be an object

The failures comes from comparing these types with string because all the values are decoded as strings:

interface {}(map[string]interface {}) ["mystring": "...", "myint": "...", "myobj": "..." ]

Is this a valid bug or am I doing something wrong? The only thing I could find was these tickets: #793 and oapi-codegen/oapi-codegen#1169 which are closed without a fix or a workaround.

I am using github.com/deepmap/oapi-codegen/v2 v2.1.0 and github.com/getkin/kin-openapi v0.122.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions