这是indexloc提供的服务,不要输入任何密码
Skip to content

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

@codecov
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
@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.

2 participants