Comments (10)
I was able to work around this just by post-processing the schema to handle removing those anyOf types 👍
from swift-openapi-generator.
Also having this issue. I'm using the schema directly from a django-ninja backend and it writes nullable types in the anyOf
style. I'm getting dozens of warnings like Schema "null" is not supported, reason: "schema type"
when generating. I'd like to not have to go trough and rewrite those optionals every time I update the schema.
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 anyOf
style instead of the type
style:
image_large_url:
anyOf:
- type: string
- type: 'null'
needs to be this ⬇️
image_large_url:
type: [string, 'null']
Update 3: Seems either is correct according to the OpenAPI maintainers: OAI/OpenAPI-Specification#3148
from swift-openapi-generator.
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 anyOf
where one of the cases is just null
. In Swift, it's not necessary to have that explicit null, because the fact that phoneNumber
already is omitted from required
in the Account
schema, we'll already treat it as optional.
So in your case, if you edit:
"phoneNumber": {
"description": "phone number",
"anyOf": [
{
"$ref": "#/components/schemas/PhoneNumber"
},
{
"type": "null"
}
]
},
to:
"phoneNumber": {
"description": "phone number",
"$ref": "#/components/schemas/PhoneNumber"
},
It should start working again. Please let me know if that fixed it 🙂
from swift-openapi-generator.
Hi @czechboy0 ,
To answer your question, it partially fixes it but not super friendly.
With your suggested change and yams 5.1.X, phoneNumber does indeed appear; however, it is of type OpenAPIValueContainer?
and not type PhoneNumber
as I would have expected.
In the original example (unmodified) with yams 5.0.X, phoneNumber is of type Components.Schemas.NewAccount.phoneNumberPayload?
which is not ideal (would be nicest to just be PhoneNumber
directly), but still easier to work with than OpenAPIValueContainer?
.
Regards.
from swift-openapi-generator.
That's strange, I would expect it to be of the PhoneNumber
type. Can you post your updated OpenAPI doc here again please?
from swift-openapi-generator.
@czechboy0 - as requested - openapi.json with the change you suggested applied in 2 places:
openapi.json
from swift-openapi-generator.
@dpasirst Your OpenAPI JSON file seemed malformed, in both places you had:
"phoneNumber": {
"#/components/schemas/PhoneNumber",
"description": "phone number"
},
but should be:
"phoneNumber": {
"$ref": "#/components/schemas/PhoneNumber",
"description": "phone number"
},
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.
from swift-openapi-generator.
@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:
"phoneNumber": {
"$ref": "#/components/schemas/PhoneNumber",
"description": "phone number"
},
does appear to work with both yams 5.0.X and 5.1.X.
In this case, the original posted json containing the anyOf
is generated from a Rust project using Aide...and as already demonstrated manual editing is error-prone and less than ideal. Is this something that needs to be fixed upstream in that project or here on the client side?
In reviewing, #553 , it seems the Aide generated openapi.json might be valid as it is generating with the "null" as quoted.
from swift-openapi-generator.
👋 I think I'm running into something similar with these warnings: Schema "null" is not supported, reason: "schema type", skipping
With something like this schema:
"Cursors": {
"properties": {
"next": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"title": "Next"
},
"previous": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"title": "Previous"
}
},
"type": "object",
"required": [
"next",
"previous"
],
"title": "Cursors"
},
I understand from reading a couple issues that the recommendation is to not include {"type": "null"}
but I don't have direct control over this. This is a side effect of using pydantic + fastapi and dumping the openapi schema. In this specific case, I'm also relying on returning "null" although I could work around it if need be.
from swift-openapi-generator.
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.
from swift-openapi-generator.
Related Issues (20)
- Null property type with quotes not generated HOT 14
- Support for XML request body and response body HOT 7
- Support schemas.type: string, format: uri generates URL property not String HOT 3
- How to support OAuth2 Password flows? HOT 3
- allOf plus properties HOT 2
- OpenAPI shared components HOT 4
- Logging and HTTPBody HOT 3
- Merging oneOf with many compatible enums of a single value HOT 10
- anyOf encoder does not include discriminator's `parameterName` leading to incorrect encoding HOT 2
- Is there a workaround to deal with slow compilation times for a very large openapi file? HOT 3
- Empty arrays are omitted from query params HOT 5
- Support for `multipart/mixed`? HOT 1
- When a delete path do not have responses content an error generated HOT 2
- Add ability to attach protocols to generated models HOT 9
- Protocol where each `Output` conforms to HOT 3
- Make the generator usable on very big specs HOT 3
- Old and new examples HOT 3
- visionOS can't use HOT 4
- How to convert the binary obtained from the server into a playable Data type? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from swift-openapi-generator.