Uh oh!
There was an error while loading. Please reload this page.
[typescript-fetch] Add (de)serializers for oneOfs - #4387
Conversation
👍 Thanks for opening this issue! The team will review the labels and make any necessary changes. |
wing328
commented
Nov 15, 2019
@eriktim thanks for the PR, which has been included in the v4.2.1 release: https://twitter.com/oas_generator/status/1195339336922759168 |
Bessonov
commented
Nov 22, 2019
@eriktim I'm not sure that I understand how it supposed to work without a discriminator. I've some sort of MongoDb-Api description: DateSearch:
oneOf:
- type: objectrequired:
- $eqproperties:
$eq:
type: stringformat: date
- type: objectrequired:
- $neproperties:
$ne:
type: stringformat: date[...]The generated union type is correct: exporttypeDateSearch=DateSearchOneOf|DateSearchOneOf1|[...]But exportfunctionDateSearchToJSON(value?: DateSearch|null): any{if(value===undefined){returnundefined;}if(value===null){returnnull;}return{ ...DateSearchOneOfToJSON(value), ...DateSearchOneOf1ToJSON(value),[...]};}From logical point of view, the last line try to merge all properies, which isn't what for an union type should happens. Technically, From my point of view, a check should be generated, which, in sense of |
Bessonov
commented
Nov 22, 2019
Ok, it's worser, I have no idea how to check in this case 🍡 |
eriktim
commented
Nov 22, 2019
@Bessonov I currently do not have tsc at hand so I cannot reproduce your error (it would be nice to post that one as well). It looks like TypeScript does not take the spread operator as I had hoped. As stated in my description I would like to have this case tested as well, hence this PR should not have been merged in yet. But even if I would have had, using a |
Is this really resolved? I am still receiving the problem @Data@SuperBuilder(toBuilder = true)
@EqualsAndHashCode(callSuper = false)
@Schema(
type = "object",
oneOf = { First.class, Second.class }
)
publicabstractclassFoo {
@Schema(required = true)
privateStringtype;
}
@Data@EqualsAndHashCode(callSuper = true)
@SuperBuilder(toBuilder = true)
@Schema(type = "object")
@ApiModel(value = "Bar", parent = Foo.class)
publicabstractclassBarextendsFoo {
@Schema(required = true)
privateStringid;
}
The example above might be slightly off, I cannot copy my code directly due to NDA. Edit: Edit 2: |
PR checklist
./bin/(or Windows batch scripts under.\bin\windows) to update Petstore samples related to your fix. This is important, as CI jobs will verify all generator outputs of your HEAD commit, and these must match the expectations made by your contribution. You only need to run./bin/{LANG}-petstore.sh,./bin/openapi3/{LANG}-petstore.shif updating the code or mustache templates for a language ({LANG}) (e.g. php, ruby, python, etc).master,4.3.x,5.0.x. Default:master.Using
oneOfs withtypescript-fetchresults in union types, but lacks decoders and encoders for them. This PR patches that. I've also added support for the discriminator (resulting in tagged unions).@wing328 Is there already a YAML available for testing oneOfs/allOfs/discriminators? Otherwise I would like to add a generic one.
cc @TiFu@taxpon@sebastianhaas@kenisteward@Vrolijkx@macjohnny@nicokoenig@topce@akehir