-
Notifications
You must be signed in to change notification settings - Fork 5
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
feat(oas): support application/x-www-form-urlencoded
OAS style serialization
#227
base: master
Are you sure you want to change the base?
feat(oas): support application/x-www-form-urlencoded
OAS style serialization
#227
Conversation
…alization closes #226
Code Climate has analyzed commit 3d5d570 and detected 0 issues on this pull request. The test coverage on the diff in this pull request is 96.2% (50% is the threshold). This pull request will bring the total coverage in the repository to 92.2% (0.1% change). View more on Code Climate. |
closes #226
…oded-oas-style-serialization
value: unknown, | ||
fields?: Record<string, OpenAPIV3.EncodingObject>, | ||
schema?: OpenAPIV3.SchemaObject | OpenAPIV2.SchemaObject |
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.
Convert args to an object and introduce interface
return this.findSerializer(style)?.serialize( | ||
{ | ||
key, | ||
value: stringifyObject ? JSON.stringify(val) : val |
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.
When dealing with complex values that are not arrays of primitive types or simple objects with primitive fields, you have to rely on the contentType
. It is not necessary a JSON
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.
Well, when contentType
is specified it has already handled in Oas3RequestBodyConverter.encodeProperties
and thus here we receive string
primitive.
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.
The contentMediaType
can be present in the schema itself, which is intended to be handled if there are no encodings or media type object keys. Even beyond this, the behavior for nested objects and arrays is undefined in the specification; it is better to simply ignore values in such cases to avoid API misbehaviour.
): value is null | undefined | string | boolean | number | bigint | symbol => | ||
// ADHOC: typeof null === 'object' | ||
value === null || | ||
value === undefined || |
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.
value === undefined || | |
typeof value === 'undefined' || |
] | ||
}) | ||
encoding.contentType | ||
? this.encodeValue({ |
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.
The encodeValue
should manage this scenario. Ensure it is able to accept undefined
as a valid contentType
.
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.
There is a possibility to encode some primitive or array to string
. See (#227 (comment)) which will prevent correct serialization due to loss of type info
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.
Makes sense. However, you should figure out how to handle the contentMediaType
in this case.
closes #226