-
Notifications
You must be signed in to change notification settings - Fork 122
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
Latest yams results in incomplete generation of types #565
Comments
Hi @dpasirst, this sounds very similar to #553. I looked at your doc, and I think the problem is that we're not handling the case of So in your case, if you edit:
to:
It should start working again. Please let me know if that fixed it 🙂 |
Hi @czechboy0 , With your suggested change and yams 5.1.X, phoneNumber does indeed appear; however, it is of type In the original example (unmodified) with yams 5.0.X, phoneNumber is of type Regards. |
That's strange, I would expect it to be of the |
@czechboy0 - as requested - openapi.json with the change you suggested applied in 2 places: |
@dpasirst Your OpenAPI JSON file seemed malformed, in both places you had:
but should be:
When the generator runs, it emits warning and error diagnostics, can you check if it caught the malformed JSON? It's possible it didn't regenerate, showed an error, so your generated files would still be the old ones. |
@czechboy0 - great catch. I see that was caused by my manual edit to change the json per a few comments back, I seem to have been a little too aggressive in removing the "anyOf"... I was not sure where to look for the generator error diagnostic. With the errored json, the Xcode build screen does not seem to indicate such a diagnostic, instead, it lists "- Diagnostics output path: <none - logs to stderr>". Indeed, this:
does appear to work with both yams 5.0.X and 5.1.X. In this case, the original posted json containing the In reviewing, #553 , it seems the Aide generated openapi.json might be valid as it is generating with the "null" as quoted. |
👋 I think I'm running into something similar with these warnings: With something like this schema:
I understand from reading a couple issues that the recommendation is to not include |
I was able to work around this just by post-processing the schema to handle removing those anyOf types 👍 |
for me, I can move forward for now thanks to @czechboy0 , but given the openapi.json is server generated, I'm hoping the fix to properly support the schema will not be too complicated and hopefully can be resolved quickly. |
Also having this issue. I'm using the schema directly from a django-ninja backend and it writes nullable types in the Update: Forced Yams v5.0.6 in my Package.swift and generation is working now Update 2: Generation worked, but now the app crashes when trying to parse the values that are defined in that
needs to be this ⬇️
Update 3: Seems either is correct according to the OpenAPI maintainers: OAI/OpenAPI-Specification#3148 |
I want to work with an API that returns So, in their case, when they use response schema: text:
type: [string, "null"]
words:
type: [array, "null"]
items:
$ref: "#/components/schemas/TranscriptWord" returns {
"text": null,
"words": null
} update: I think this is the relevant issue: #419 update_2: It's already decoded actually. |
@atacan just confirming: you're not currently blocked by this issue? |
@simonjbeaumont Hi, I removed the |
Hi there, I'm still unclear on whether there is a fix or legitimate workaround for this issue, as it's causing a high amount of frustration not being able to declare/ use any nullable API types in our app. Here's an example of a very contrived schema / route that returns a nullable string. The generated
In this form, the generated Swift schema type completely misses the
Trying what was suggested in this thread, to replace the
results in runtime errors when my API actually returns an null response. For clarity, here's the response I get using curl
Apologies if I've missed something in these comments, is there a recommended path or workaround here? Once again, it's making this borderline unusable if we can't support a nullable field. Our janky solution right now is using array type almost everywhere. |
We're still having similar issues in our app. We have had to write scripts to convert the yaml before we feed it into the OpenAPI generator which is not ideal. We don't have any control over what Django Ninja outputs so we need to tackle massaging the formatting from the Swift side of things |
@IanHoar just out of curiosity, can I ask what you're doing for conversion that is getting around the issue? |
Here's the script we are using to strip the invalid nullables: https://gist.github.com/IanHoar/7960d3598c718c831636b1a07e817d39 |
@IanHoar Thank you so much for sharing! Hope we can get some clarity from maintainers soon. |
@toliv if you remove the property name from the Right now the problem is that the schema is marked as required but null - this is not a combination we support. Hopefully the workaround will bridge you over until we have a chance to take another look here. |
Description
I'm not exactly sure where this bug is arising from (e.g. swift-openapi-generator or one of its dependencies like OpenAPIKit).
In short, using
swift-openapi-generator
with when theyams
version is 5.0.X, the correct swift code (Types) is generated as part of generating types and client. When yams is 5.1.X, the generated code is missing fields. This is with an OpenAPI 3.1 json.Reproduction
I have attached an example openapi.json along with the difference in the resulting generated swift code. Specifically, in looking at
Components.Schemas.NewAccount
andComponents.Schemas.Account
you will see that the one created with yams 5.0.X contains aphoneNumberPayload
as part of each. There is also a definedPhoneNumber
struct and curiously it is not linked or used instead ofphoneNumberPayload
but that is perhaps a different improvement. For now, thephoneNumberPayload
is usable with yams 5.0.X.However, when building with yams 5.1.X, the generated
NewAccount
andAccount
do not containphoneNumberPayload
. It is dropped but should be there.I have attached the example openapi.json and the example generated outputs.
openapi.json
generated_types_yams5.0.swift.txt
generated_types_yams5.1.swift.txt
I'm not sure if this is related but Yams 5.1.0 release notes the following breaking change:
If it is helpful, the openapi.json was generated via Rust using Aide with Axum.
Rust struct definition
Package version(s)
OpenAPIKit 3.1.3
swift-algorithms 1.2.0
swift-argument-parser 1.3.1
swift-collections 1.1.0
swift-http-types 1.0.3
swift-numerics 1.0.2
swift-openapi-generator 1.2.1
swift-openapi-runtime 1.4.0
swift-openapi-urlsession 1.0.1
Yams 5.0.6 or 5.1.0 as described resulting in the problem
Expected behavior
The generated types for
Account
andNewAccount
should containphoneNumberPayload
respectively (or even better if it directly containedPhoneNumber
) for any version of Yams.Environment
Additional information
No response
The text was updated successfully, but these errors were encountered: