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

Add contentMediaType field to generated schema when format is binary #422

Merged
merged 1 commit into from
Apr 29, 2024

Conversation

lsdch
Copy link
Contributor

@lsdch lsdch commented Apr 29, 2024

This PR adds the contentMediaType property to the generated schema spec for binary field. This is mainly for the purpose of compatibility with API documentation tools such as Stoplight Elements (see #397).

Note that #415 sets contentType property in the schema, but that is not sufficient for Stoplight to show the file upload UI component, event though the OpenAPI spec says contentMediaType is not required when contentType is defined.
Although that may rather be an issue in Stoplight, in my understanding it does not hurt to add this redundancy to Huma.

Thus, this PR can be considered independently from #415. I hope I'm not mistaken about what the OpenAPI specs say, let me know if you think this rather belongs to Stoplight issues.

Example schema:

{
  "requestBody": {
	"content": {
		"multipart/form-data": {
			"schema": {
				"properties": {
					"filename": {
						"contentMediaType": "application/octet-stream",
						"description": "filename of the file being uploaded",
						"format": "binary",
						"type": "string"
					},
					"name": {
						"description": "general purpose name for multipart form value",
						"type": "string"
					}
				},
				"type": "object"
			}
		}
	},
	"required": true
}

Sample UI screenshot:
image

Copy link

codecov bot commented Apr 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.74%. Comparing base (a93ebe6) to head (a1757e6).
Report is 5 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #422      +/-   ##
==========================================
+ Coverage   92.72%   92.74%   +0.02%     
==========================================
  Files          21       21              
  Lines        3546     3556      +10     
==========================================
+ Hits         3288     3298      +10     
  Misses        220      220              
  Partials       38       38              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Owner

@danielgtaylor danielgtaylor left a comment

Choose a reason for hiding this comment

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

Thanks!

@danielgtaylor danielgtaylor merged commit 3abb70d into danielgtaylor:main Apr 29, 2024
2 of 3 checks passed
@lsdch lsdch deleted the content-media-type branch April 29, 2024 17:21
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.

None yet

2 participants