Comments (9)
This is similar to #383, where could conceivably attach arbitrary conformances or macros that are stated in the config file and it be up to the adopter to ensure these are available in their project.
It wouldn't be too different from the ability we have know to express additionalImports
.
from swift-openapi-generator.
That's true, @simonjbeaumont, and the macro itself would contain the logic for how to e.g. implement Identifiable
, instead of the generator having to know how to do it. I like that.
from swift-openapi-generator.
Hi @armintelker,
all generated types already conform to Equatable
, as we generate the Hashable
conformance (which includes Equatable
).
Identifiable
, on the other hand, is tricky, as it's not clear what the id
property should return for arbitrary schemas. What would be your expectation?
from swift-openapi-generator.
Hey, thanks for the quick response.
I have overseen that the DTO is already conforming to Hashable. This makes, of course, everything a lot easier. So my request gets kind of needless.
Indeed the Identifiable
protocol suggestion would be more like a "nice to have".
I could imagine that the generator could add the Identifiable
to the model as soon it sees a property id
exists that also conforms to the constraint of the protocol.
from swift-openapi-generator.
I could imagine that the generator could add the Identifiable to the model as soon it sees a property id exists that also conforms to the constraint of the protocol.
In theory yes, but my first instinct is that this would be considered out of scope of an OpenAPI generator. I think a separate build plugin that processes your Swift code and adds Identifiable
to any struct that has an id
property would be more appropriate, and more maintainable. This is a feature that would be useful outside of the OpenAPI context.
from swift-openapi-generator.
+1 to this. In my use case it would also be useful to have ability to add Identifiable conformance to some types. There is literally no other way to do this - I have a library that uses swift-openapi-generator to generate the type and expose them publicly.
It would be nice if Swift allowed to add public conformance to a protocol in an extension:
public extension Components.Schemas.SortType: Identifiable { // compiler error: 'public' modifier cannot be used with extensions that declare protocol conformances
public var id: String { rawValue }
}
Unfortunately this is not possible in Swift, so the only solution I can see is to solve it in the openapi generator.
from swift-openapi-generator.
Hi @shadone,
does this work?
extension Components.Schemas.SortType: Identifiable {
public var id: String { rawValue }
}
(without the public modifier on the extension, only on the id property).
from swift-openapi-generator.
<deleted previous content> I completely misunderstood what czechboy0 was saying
That work indeed, thanks @czechboy0 ! To be honest I had no idea this is possible, despite years of writing Swift code. And to be honest I do not understand why this works (does the SortType publicly conform to the protocol here or just the "shape" of the protocol)
But it works great, thanks!
from swift-openapi-generator.
does the SortType publicly conform to the protocol here or just the "shape" of the protocol
I believe the visibility of the conformance is always derived from the visibility of the extended type and the protocol, i.e. there is no way to privately conform a public type to a public protocol.
But to get more details, starting a thread on the Swift Forums might be a good next step, if you're interested in the lower level compiler details.
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
- 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
- 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.