Repository navigation
feat(datamodel/v3)!: model OAS 3.2 prefixEncoding, itemEncoding and nested Encoding fields #706
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,14 +20,15 @@ import ( | |
| // Each Media Type Object provides schema and examples for the media type identified by its key. | ||
| // - https://spec.openapis.org/oas/v3.1.0#media-type-object | ||
| type MediaType struct { | ||
| Schema *base.SchemaProxy `json:"schema,omitempty" yaml:"schema,omitempty"` | ||
| ItemSchema *base.SchemaProxy `json:"itemSchema,omitempty" yaml:"itemSchema,omitempty"` | ||
| Example *yaml.Node `json:"example,omitempty" yaml:"example,omitempty"` | ||
| Examples *orderedmap.Map[string, *base.Example] `json:"examples,omitempty" yaml:"examples,omitempty"` | ||
| Encoding *orderedmap.Map[string, *Encoding] `json:"encoding,omitempty" yaml:"encoding,omitempty"` | ||
| ItemEncoding *orderedmap.Map[string, *Encoding] `json:"itemEncoding,omitempty" yaml:"itemEncoding,omitempty"` | ||
| Extensions *orderedmap.Map[string, *yaml.Node] `json:"-" yaml:"-"` | ||
| low *low.MediaType | ||
| Schema *base.SchemaProxy `json:"schema,omitempty" yaml:"schema,omitempty"` | ||
| ItemSchema *base.SchemaProxy `json:"itemSchema,omitempty" yaml:"itemSchema,omitempty"` | ||
| Example *yaml.Node `json:"example,omitempty" yaml:"example,omitempty"` | ||
| Examples *orderedmap.Map[string, *base.Example] `json:"examples,omitempty" yaml:"examples,omitempty"` | ||
| Encoding *orderedmap.Map[string, *Encoding] `json:"encoding,omitempty" yaml:"encoding,omitempty"` | ||
| PrefixEncoding []*Encoding `json:"prefixEncoding,omitempty" yaml:"prefixEncoding,omitempty"` // OpenAPI 3.2+ | ||
| ItemEncoding *Encoding `json:"itemEncoding,omitempty" yaml:"itemEncoding,omitempty"` // OpenAPI 3.2+ | ||
| Extensions *orderedmap.Map[string, *yaml.Node] `json:"-" yaml:"-"` | ||
| low *low.MediaType | ||
| } | ||
|
|
||
| // NewMediaType will create a new high-level MediaType instance from a low-level one. | ||
|
|
@@ -44,8 +45,9 @@ func NewMediaType(mediaType *low.MediaType) *MediaType { | |
| m.Examples = base.ExtractExamples(mediaType.Examples.Value) | ||
| m.Extensions = high.ExtractExtensions(mediaType.Extensions) | ||
| m.Encoding = ExtractEncoding(mediaType.Encoding.Value) | ||
| m.PrefixEncoding = extractEncodingSlice(mediaType.PrefixEncoding) | ||
| if !mediaType.ItemEncoding.IsEmpty() { | ||
| m.ItemEncoding = ExtractEncoding(mediaType.ItemEncoding.Value) | ||
| m.ItemEncoding = NewEncoding(mediaType.ItemEncoding.Value) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [P2] Preserve specification extensions on the Encoding Object.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in 1f5ea31. The low Tests: |
||
| } | ||
| return m | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[P2] Preserve an explicitly empty
prefixEncodingarray. I parsed a multipart media type withschema: {type: array}andprefixEncoding: [].Render()omitted the field andCompareMediaTypesreturned nil against a document where the field was absent. The 3.2 schema allows an empty array. Carry field presence from the low node through conversion, rendering, hashing, and comparison, and cover both an empty array and an omitted field.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 1f5ea31. Whether the field is present is now carried all the way through:
extractEncodingSlicetakes theNodeReference. An absent field givesnilandprefixEncoding: []gives an empty slice, soRender()writes it back out.prefixEncodingis present, not just its entries.CompareEncoding/CompareMediaTypesreport adding or removing an empty array asPropertyAdded/PropertyRemoved, under the existingprefixEncodingbreaking rules.Tests:
TestEncoding_Hash_EmptyPrefixEncodingPresence,TestMediaType_OAS32Encoding_EmptyPrefixEncodingBuiltByCallerandTestCompareMediaTypes_EmptyPrefixEncodingPresence. Between them they cover an empty array against an omitted field, at both the media type anditemEncodinglevel.