Open mrclrchtr opened 1 week ago
You'd also need to be able to transform the generated types, right? What would the appropriate type be in your example?
Unfortunately, I don't quite understand the question.
I'll try to explain my idea again:
type: string
and e.g. format: localTime
(it's a custom format).In my WebApp I have defined the class LocalTime
myself:
export class LocalTime {
hour: number;
minute: number;
constructor(hour: string, minute: string) {
this.hour = Number.parseInt(hour, 10);
this.minute = Number.parseInt(minute, 10);
}
}
string
has the format
localTime
, that it should use a special transformer
to set the field in the generated types:proposal:
{
name: '@hey-api/transformers',
custom: {
type: string,
format: localTime,
parser: {
regex: "/^([01]?\d|2[0-3]):([0-5]\d)(?::([0-5]\d))?$/", # For demo only
},
target: {
pathToCass: "/calendar/LocalTime", # to be used for the import
constructor: ["$1", "$2"]
}
}
},
then the parser would know how to parse the string and the transformer would know which elemento to set where in the constructor.
I just thought of that quickly... there is certainly a better API for this.
I would like to define a
transformer
for a customformat
and this should be applied when a string has this format:e.g.
then I would like to be able to parse this string into
LocalTime
.Maybe, I could create my own plugin for this?
If this doesn't fit here, I'll open a separate topic or issue.
Originally posted by @mrclrchtr in https://github.com/hey-api/openapi-ts/discussions/1039#discussioncomment-11194255