Comments (10)
The generator doesn't have any special logic for the enum-of-one-case pattern and, for enums, it generates number-based symbol names.
In an ideal world, what would you like the code to look like? If this is a common pattern we can consider proposals for generating but it needs to be generalisable.
from swift-openapi-generator.
What does this give you over just this?
"InstanceState": {
"description": "The instance is being created.",
"type": "string",
"enum": [
"creating"
]
}
from swift-openapi-generator.
In an ideal world, what would you like the code to look like?
Ideally I'd be able to use the enum directly, e.g. run_state: .failed
. This is the same issue in a Rust type generator: oxidecomputer/typify#497
What does this give you over just this?
I should of provided more context, this has many oneOf
s with a single enum.
"InstanceState": {
"description": "Running state of an Instance (primarily: booted or stopped)\n\nThis typically reflects whether it's starting, running, stopping, or stopped, but also includes states related to the Instance's lifecycle",
"oneOf": [
{
"description": "The instance is being created.",
"type": "string",
"enum": [
"creating"
]
},
{
"description": "The instance is currently starting up.",
"type": "string",
"enum": [
"starting"
]
},
{
"description": "The instance is currently running.",
"type": "string",
"enum": [
"running"
]
},
{
"description": "The instance has been requested to stop and a transition to \"Stopped\" is imminent.",
"type": "string",
"enum": [
"stopping"
]
},
{
"description": "The instance is currently stopped.",
"type": "string",
"enum": [
"stopped"
]
},
{
"description": "The instance is in the process of rebooting - it will remain in the \"rebooting\" state until the VM is starting once more.",
"type": "string",
"enum": [
"rebooting"
]
},
{
"description": "The instance is in the process of migrating - it will remain in the \"migrating\" state until the migration process is complete and the destination propolis is ready to continue execution.",
"type": "string",
"enum": [
"migrating"
]
},
{
"description": "The instance is attempting to recover from a failure.",
"type": "string",
"enum": [
"repairing"
]
},
{
"description": "The instance has encountered a failure.",
"type": "string",
"enum": [
"failed"
]
},
{
"description": "The instance has been deleted.",
"type": "string",
"enum": [
"destroyed"
]
}
]
},
from swift-openapi-generator.
Why are they split this way? You can spell the same with a single string enum that contains all those cases. Is it a workaround to add the descriptions?
from swift-openapi-generator.
That's right: a simple enum
doesn't let us have descriptions for each value.
from swift-openapi-generator.
Yeah that's unfortunate, one way you can work around it is to add the description to the enum itself, and document each case there. That'll make the code much easier to work with. But otherwise there's not much we can do, the oneOf is there, so the generator emits code for it.
from swift-openapi-generator.
OOI, is this pattern of oneOf-of-enums-all-with-just-one-case entirely isomorphic to an enum when it comes to the HTTP representation?
I'm asking because we're not likely to change how oneOfs are generated, you could consider preprocessing the document here.
from swift-openapi-generator.
If I understand correctly, it sounds like the philosophy of this SDK generator is for simple and predictable transformations from, say, a oneOf
construction into an enum
rather than deeper inspection for idiomatic code generation. If that focus changes such that you're amenable to special cases for improved codegen, this might be a case you'd consider.
from swift-openapi-generator.
it sounds like the philosophy of this SDK generator is for simple and predictable transformations from, say, a oneOf construction into an enum rather than deeper inspection for idiomatic code generation.
Exactly, we even call out the tradeoffs in more detail here: https://swiftpackageindex.com/apple/swift-openapi-generator/1.2.1/documentation/swift-openapi-generator/project-scope-and-goals
Thanks for understanding 🙂
from swift-openapi-generator.
Nonetheless, thanks for considering. 👍🏻
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
- bug/regression: latest yams results in incomplete generation of types HOT 10
- Logging and HTTPBody HOT 3
- 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.