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

fix: add nullable condition to multipart formdata for openapi3.1 #1646

Conversation

kosa3
Copy link
Contributor

@kosa3 kosa3 commented Sep 28, 2024

Status

READY

Description

OpenAPI 3.1 introduces support for jsonschema's 'null' type, however,
there is a problem in multipart/formdata where the generated code does not correctly determine null.
Specifically, the expected output from the following yaml is different.

https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-00#section-7.6.1

input.yaml

openapi: '3.1.0'
info:
  version: 1.0.0
  title: Swagger Petstore
paths:
  /pets:
    post:
      summary: Create a pet
      operationId: createPets
      tags:
        - pets
      requestBody:
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                name:
                  type: [ string, 'null' ]
      responses:
        '204':
          description: Created Pet
  • Expected
if(createPetsBody.name !== undefined && createPetsBody.name !== null) {
 formData.append('name', createPetsBody.name)
 }
  • Generated
if(createPetsBody.name !== undefined) {
 formData.append('name', createPetsBody.name)
 }

Related PRs

List related PRs against other branches:

branch PR
other_pr_production link
other_pr_master link

Todos

  • Tests
  • Documentation
  • Changelog Entry (unreleased)

Steps to Test or Reproduce

Outline the steps to test or reproduce the PR here.

> git pull --prune
> git checkout <branch>
> grunt jasmine

melloware
melloware previously approved these changes Sep 29, 2024
@melloware melloware added this to the 7.2.0 milestone Sep 29, 2024
@melloware melloware added the enhancement New feature or request label Sep 29, 2024
Copy link
Member

@soartec-lab soartec-lab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

@soartec-lab soartec-lab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kosa3
I added a comment.

@@ -62,3 +80,18 @@ components:
BlankEnum:
enum:
- ''
MultipartFormDataNullable:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I fixed it.
I also found a bug when oneOf, anyOf, allOf subschemas are attached and fixed it.

@kosa3 kosa3 requested a review from soartec-lab September 30, 2024 01:08
melloware
melloware previously approved these changes Sep 30, 2024
Copy link
Member

@soartec-lab soartec-lab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's good. I added some updated comments. Once you fix that, it's perfect!

packages/core/src/getters/res-req-types.ts Outdated Show resolved Hide resolved
Copy link
Member

@soartec-lab soartec-lab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for good work !

@soartec-lab soartec-lab merged commit b3b0306 into orval-labs:master Sep 30, 2024
2 checks passed
@kosa3 kosa3 deleted the fix/nullable_condition_for_multipart_formdata branch October 1, 2024 07:17
@soartec-lab soartec-lab linked an issue Oct 13, 2024 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

react-query: check for NULL skipped inside "anyOf" list of types
3 participants