fix: core: recognize OAS 3.1 contentMediaType for binary classification#23850
Closed
erichasinternet wants to merge 1 commit into
Closed
fix: core: recognize OAS 3.1 contentMediaType for binary classification#23850erichasinternet wants to merge 1 commit into
erichasinternet wants to merge 1 commit into
Conversation
Extend ModelUtils.isBinarySchema to recognize contentMediaType: application/octet-stream alongside the existing format: binary check. OpenAPI 3.1 / JSON Schema 2020-12 uses contentMediaType as the binary-content signal, but openapi-generator only matched format: binary, so 3.1 specs failed to classify file fields and were routed through plain form params rather than multipart binary parts. format: binary remains valid in 3.1 and continues to match.
c575e29 to
24df88b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR checklist
master(additive, non-breaking).Description
Problem. OpenAPI 3.1 declares binary string fields with JSON Schema 2020-12's
contentMediaTypekeyword:ModelUtils.isBinarySchema()only recognized the 3.0 idiom (format: binary), so 3.1 specs (e.g. anything emitted by FastAPI ≥0.99) failed to classify file fields. Downstream, parameters were routed through_form_params(plain text) rather than_files(binary multipart).Change. Extend
isBinarySchema()to also matchcontentMediaType: application/octet-stream.format: binaryremains valid in 3.1 (deprecated but not removed) and continues to match. The fix is additive at the single chokepoint used by twelveisFile = truesites inDefaultCodegenand eleven other language targets, so every consumer picks up correct 3.1 handling without target-specific changes.Tests.
testIsBinarySchemaOAS30FormatBinaryguards the existing 3.0 path;testIsBinarySchemaOAS31ContentMediaTypecovers the new 3.1 path and asserts a non-octet-streamcontentMediaType(e.g.image/png) does not false-positive. Paired3_0/binary-schema.yamland3_1/binary-schema.yamlfixtures show the same upload body in both dialects.Validation. Full
ModelUtilsTestpasses (38 cases).bin/generate-samples.sh ./bin/configs/*.yamlandbin/utils/export_docs_generators.shboth produce zero diff — no existing spec usescontentMediaType.fixes #23095
refs #13083, #9083