You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
Our API requires the use of various json-like content types, including application/vc+ld+json and application/didcomm-plain+json. Regrettably, the typescript generator has a list of supported content types that is hardcoded, without the option to extend it.
const supportedMediaTypes: { [mediaType: string]: number } = {
"application/json": Infinity,
"application/json-patch+json": 1,
"application/merge-patch+json": 1,
"application/strategic-merge-patch+json": 1,
"application/octet-stream": 0,
"application/x-www-form-urlencoded": 0
}
This creates a challenge in generating clients, as we need to modify templates even though all json-like content types utilize the same parse/stringify implementation.
Describe the solution you'd like
Instead of hardcoding content types, we can implement several predicates that will check if we can serialize/parse the provided content type.
/** * Convert data to a string according the given media type */publicstaticstringify(data: any,mediaType: string): string {if(isTextLikeMimeType(mediaType)){returnString(data);}if(isJsonLikeMimeType(mediaType)){returnJSON.stringify(data);}thrownewError("The mediaType "+mediaType+" is not supported by ObjectSerializer.stringify.");}/** * Parse data from a string according to the given media type */publicstaticparse(rawData: string,mediaType: string |undefined){if(mediaType===undefined){thrownewError("Cannot parse content. No Content-Type defined.");}if(isTextLikeMimeType(mediaType)){returnrawData;}if(isJsonLikeMimeType(mediaType)){returnJSON.parse(rawData);}thrownewError("The mediaType "+mediaType+" is not supported by ObjectSerializer.parse.");}
Describe alternatives you've considered
The only viable alternative I found is to augment --additional-properties with a mapping of content types to parsers/serializers. This is a more scalable solution, but in my opinion, it should accompany this proposal.
Additional context
None
The text was updated successfully, but these errors were encountered:
Is your feature request related to a problem? Please describe.
Our API requires the use of various json-like content types, including
application/vc+ld+json
andapplication/didcomm-plain+json
. Regrettably, thetypescript
generator has a list of supported content types that is hardcoded, without the option to extend it.openapi-generator/modules/openapi-generator/src/main/resources/typescript/model/ObjectSerializer.mustache
Lines 25 to 32 in f834519
This creates a challenge in generating clients, as we need to modify templates even though all json-like content types utilize the same parse/stringify implementation.
Describe the solution you'd like
Instead of hardcoding content types, we can implement several predicates that will check if we can serialize/parse the provided content type.
These helpers could then be used as follows
Describe alternatives you've considered
The only viable alternative I found is to augment
--additional-properties
with a mapping of content types to parsers/serializers. This is a more scalable solution, but in my opinion, it should accompany this proposal.Additional context
None
The text was updated successfully, but these errors were encountered: