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

[Generator] Add support of deepObject style in query params #659

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

arthurcro
Copy link
Contributor

Motivation

The generator changes for: #259

Depends on apple/swift-openapi-runtime#100 landing first and getting released, and the version dependency being bumped here.

Modifications

Added deepObject style to serializer & parser in order to support nested keys on query parameters.

Result

Support nested keys on query parameters.

Test Plan

Adapted snippet tests (SnippetBasedReferenceTests)

@czechboy0
Copy link
Contributor

We discussed this offline, this is the PR #538 reopened again, so that we can finish it up even while the original author is busy 🙂 Thanks @arthurcro for adding you both to the commit, it's important that we give credit to @kstefanou52 for the work already done!

@czechboy0
Copy link
Contributor

Kicked off CI to see what state we're in.

Copy link
Contributor

@czechboy0 czechboy0 left a comment

Choose a reason for hiding this comment

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

Added a few comments of the next things to fix up, but we're almost there.

Comment on lines +133 to +136
switch style {
case .form, .deepObject:
break
default:
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
switch style {
case .form, .deepObject:
break
default:
switch style {
case .form:
break
case .deepObject where explode:
break
default:

Copy link
Contributor

Choose a reason for hiding this comment

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

style: deepObject + explode: true is supported, but not with explode: false, so let's catch it here and provide a descriptive error.

See in the runtime changes that we only support explode: true: https://github.com/apple/swift-openapi-runtime/pull/100/files#diff-a382c8525d6209dfbc3e90daaf0262692d9df73f1b7a914b9eebe143f04c287dR76

public init(
single: Swift.String? = nil,
manyExploded: [Swift.String]? = nil,
manyUnexploded: [Swift.String]? = nil
manyUnexploded: [Swift.String]? = nil,
sort: Operations.get_sol_foo.Input.Query.sortPayload
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
sort: Operations.get_sol_foo.Input.Query.sortPayload
sort: Operations.get_sol_foo.Input.Query.sortPayload = nil

This should end up being defaulted to nil as well. It's possible it'll require improvements in inspecting the nested object and whether it can be initialized with .init().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That parameter has required: true though, I don't think it should be defaulted tonil. It should be defaulted to .init() instead I think?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh that's interesting! What does it mean for a query parameter of type object to be required, when all properties are optional?

On the wire, it won't look any different to the whole parameter being optional.

Maybe we should just change the sample to have an optional parameter? I think that's more common. Alternatively, make one of the properties required. Either is fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, that's interesting. Updating the sample to have an optional parameter would resolve the issues you highlighted in the review with this test.

What if all the properties of the object have default values though? I tried getting an idea of what it would look like by updating the tests but I can get any default value to show in the generated swift types.

}
}
public var query: Operations.get_sol_foo.Input.Query
public init(query: Operations.get_sol_foo.Input.Query = .init()) {
public init(query: Operations.get_sol_foo.Input.Query) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
public init(query: Operations.get_sol_foo.Input.Query) {
public init(query: Operations.get_sol_foo.Input.Query = .init()) {

Yeah this should not go away, since all the query items are still optional, so it should be possible to init the Input with just .init().

@arthurcro
Copy link
Contributor Author

Thank you for the review @czechboy0! I'll start taking a look at those changes asap! 🙂

@kstefanou52
Copy link

Sorry, I couldn’t find the time to complete this PR yet. I made some progress, but there seems to be an issue with the unit tests—possibly something with the runtime library. I’ll have some time this weekend, so if @arthurcro would like any help, please let me know.

@arthurcro
Copy link
Contributor Author

Sorry, I couldn’t find the time to complete this PR yet. I made some progress, but there seems to be an issue with the unit tests—possibly something with the runtime library. I’ll have some time this weekend, so if @arthurcro would like any help, please let me know.

Thanks for the update @kstefanou52! I've got some availability this weekend too and would be happy to help . If you'd prefer to complete it yourself given the progress you've made, that's completely fine - just let me know what works best for you!

@kstefanou52
Copy link

Sorry, I couldn’t find the time to complete this PR yet. I made some progress, but there seems to be an issue with the unit tests—possibly something with the runtime library. I’ll have some time this weekend, so if @arthurcro would like any help, please let me know.

Thanks for the update @kstefanou52! I've got some availability this weekend too and would be happy to help . If you'd prefer to complete it yourself given the progress you've made, that's completely fine - just let me know what works best for you!

Thank you so much for the understanding @arthurcro. I'm just giving it a try and I will let you know about the outcome until Sunday end of the day.

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.

3 participants