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

added support for specifying json convenience object #120

Merged
merged 5 commits into from
Jun 30, 2024

Conversation

blagerweij
Copy link
Contributor

Allows you to conveniently use json field for multipart forms:

        http:
          url: https://httpbin.org/post
          method: POST
          formData:
            myfield:
              json:
                foo: bar
                bar: foo

The YAML will be converted to JSON, and the content-type set to 'application/json'.

Copy link
Member

@mishushakov mishushakov left a comment

Choose a reason for hiding this comment

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

Overall looks good to me and I'd be happy to merge. Feel free to act on my comment.

src/steps/http.ts Outdated Show resolved Hide resolved
@mishushakov
Copy link
Member

Okay looks good to me now. Have you tested it?

@blagerweij
Copy link
Contributor Author

Yes, I have also added a 'jsonfield' in the mulltipart.yaml test-file.

@mishushakov
Copy link
Member

Do you actually use HTTPRequestPartJson type anywhere?

@blagerweij
Copy link
Contributor Author

@mishushakov nice catch! I had initially added that type, but later decided to combine the json field in the existing HttpRequestPart type. I've updated the PR (removed the unused code); Also added a testcase for JSON arrays. I've tested it locally, and for me it works.

@mishushakov
Copy link
Member

Very well done. One thing though: you can let the != null part out, I don't think it makes any difference.

@blagerweij
Copy link
Contributor Author

What happens if you use the following (valid) json:

          my_json_field:
              json: false

If I'm not wrong, then if (requestPart.json != null) works as expected, where if (requestPart.json) does not ?!?

@mishushakov
Copy link
Member

Yes, the problem here will be if I want my json to be null. What you actually need is if('json' in requestPart)

@mishushakov mishushakov merged commit 5fe6cdc into stepci:main Jun 30, 2024
@mishushakov
Copy link
Member

Thank you very much! We should also fix the same problem in other places.

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

Successfully merging this pull request may close these issues.

2 participants