Skip to content
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

sttp-apispec 0.9.0 #3677

Merged
merged 7 commits into from
Apr 18, 2024
Merged

sttp-apispec 0.9.0 #3677

merged 7 commits into from
Apr 18, 2024

Conversation

ghik
Copy link
Contributor

@ghik ghik commented Apr 12, 2024

Integrating changes from softwaremill/sttp-apispec#152

@ghik ghik requested a review from adamw April 12, 2024 12:30
@ghik ghik changed the title Updating to changes from (future) sttp-apispec 0.9 sttp-apispec 0.9.0 Apr 16, 2024
@ghik ghik marked this pull request as ready for review April 16, 2024 10:51
properties:
optionalObjField:
oneOf:
anyOf:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this the same? oneOf vs anyOf?

Copy link
Contributor Author

@ghik ghik Apr 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not the same, but I believe anyOf is the right one to use here.
oneOf requires that a value matches exactly one of the listed schemas, which I think is needlessly strict and may be problematic if there's an overlap between values accepted by both schemas (e.g. the referred schema is already nullable).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this impacts only optional object schemas? We might consider this, but I think I would move this to a separate PR, separating the "update dependency" and "change the way tapir works" changes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was already done in sttp-apispec changes (the Schema.nullable method which replaced the nullable keyword).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm maybe we need to fix this there then. If I have an Option[Bar], then the value must be either null or a Bar. It's a sealed type, after all.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's possible that we might make a better choice there as well. But in the end, apart from sticking to the specification, it would be good to see what people actually use, so that the generated specs are understandable and useful :)

Copy link
Contributor Author

@ghik ghik Apr 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would be good to see what people actually use

It's not clear to me what you mean here. We are currently generating schemas which are technically incorrect. Since nobody ever complained about this, it probably doesn't make any difference for the ways that OpenAPIs are used in the wild, i.e. for generating docs and code stubs.
But that's also why I think it shouldn't hurt anybody when we change oneOf to anyOf - the tools most likely treat these in the same way.
On the other hand, this change may be more impactful for implementing things like #3645, and it would probably take off some mental load from me.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean that if everybody uses oneOf in their schemas to represent hierarchies like this, it should also be an indication for us to follow suit. Specifications are great, if they are respected, otherwise you only have a living standard to follow.

Copy link
Contributor Author

@ghik ghik Apr 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that most of the time the schemas are actually disjoint (e.g. they have a discriminator field). In that case, it's completely fine and natural to use oneOf, and this is probably what "the world" does in most cases. I'm only suggesting a change for non-discriminated unions, which should be rare on its own.

I'll try to do some more research on that, though, to see how other similar frameworks handle this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, thanks - we can try, and see how much of an impact this has (starting with our tests)

@ghik ghik merged commit 59e48b9 into master Apr 18, 2024
28 checks passed
@ghik ghik deleted the sttp-apispec-0.9 branch April 18, 2024 07:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants