-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
[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. |
@eriktim thanks for the PR, which has been included in the v4.2.1 release: https://twitter.com/oas_generator/status/1195339336922759168 |
@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: object
required:
- $eq
properties:
$eq:
type: string
format: date
- type: object
required:
- $ne
properties:
$ne:
type: string
format: date
[...] The generated union type is correct: export type DateSearch = DateSearchOneOf | DateSearchOneOf1 | [...] But export function DateSearchToJSON(value?: DateSearch | null): any {
if (value === undefined) {
return undefined;
}
if (value === null) {
return null;
}
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 |
Ok, it's worser, I have no idea how to check in this case 🍡 |
@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 }
)
public abstract class Foo {
@Schema(required = true)
private String type;
}
@Data
@EqualsAndHashCode(callSuper = true)
@SuperBuilder(toBuilder = true)
@Schema(type = "object")
@ApiModel(value = "Bar", parent = Foo.class)
public abstract class Bar extends Foo {
@Schema(required = true)
private String id;
}
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.sh
if 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
oneOf
s withtypescript-fetch
results 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