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

multipart/form-data - validation fails #949

Open
adabuleanu opened this issue May 15, 2024 · 0 comments
Open

multipart/form-data - validation fails #949

adabuleanu opened this issue May 15, 2024 · 0 comments

Comments

@adabuleanu
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant