Comments (6)
I agree with your proposal in the comment above @czechboy0 π
From my time working on CreateAPI, I donβt think that I ever saw a reason to want to opt out of this behaviour.
This is particularly useful for making properties to reference schemas nullable too π
from swift-openapi-generator.
Found that the k8s API is using this pattern all over the place, and not just for adding descriptions to properties, but also default fields, and I just realized that without this, deprecating individual properties will be difficult (as property values are plain old JSON schemas, not separate entities e.g. like a parameter, which has dedicated extra fields).
https://github.com/kubernetes/kubernetes/blob/v1.27.2/api/openapi-spec/v3/api__v1_openapi.json#L38
I'm starting to lean towards making flattening when N=1 the default behavior for single-child allOf's, due to how widespread this practice is, despite it being a workaround of a lacking feature in OpenAPI 3.0.x.
When considering the potential downsides of this approach, such as inconsistency with the 2+ allOfs, I see the upside of embracing the common practice as more valuable than to optimizing for the adopter who wants to evolve their allOf from N=1 to N=2+.
It all comes down to whether we believe that many OpenAPI authors evolve allOfs from having a single child schema to having 2+ child schemas. My hypothesis: no, I think most authors who put in an allOf with a single schema are doing it to work around the lack of description/default/deprecated/... on properties, rather than to represent any sort of composition at runtime. Looking at the k8s API schema above, all ~360 occurrences of allOf have N=1 schema, and a dedicated description.
This is different to e.g. OpenAPI docs with an allOf containing 2 child schemas, those I do believe that authors would reasonably want to go and add more child schemas, as the likely intent there is truly to get composition of multiple types.
To summarize my current proposal: always flatten for N=1 for allOf, don't even make it a configuration option, as I don't believe that anyone would complain about this and want to turn it off. If someone does come around needing an option, let's discuss then, but I wouldn't add a way to turn this off prematurely.
WDYT, folks?
from swift-openapi-generator.
Thinking about this a bit more, maybe we don't need this, here's an alternative idea:
as we embrace the design principles of this project outlined in Project scope and goals, we need to avoid bringing in functionality that doesn't have to be in the generator, and could be achieved by a tool that operates either on the source OpenAPI document, or on the generated Swift code.
In earlier comments above, I considered adding descriptions to object properties that are references as not covered by the default out of scope policy, because I was only thinking about OpenAPI 3.0.x, where it really is impossible, and the official recommendation as a workaround is to wrap the property in an allOf
. Unfortunately, that leads to an extra property access, going from 1 to 2, which is less than ideal.
However, OpenAPI 3.1 does support adding descriptions to reference schemas, so the natural recommendation should be: use OpenAPI 3.1.
Originally, I wasn't sure how quickly we would be able to get to supporting 3.1, but based on recent discussions in #39, and OpenAPIKit now having alpha8, which allows us to migrate piece-meal, I think we should just prioritize supporting OpenAPI 3.1 as a way to resolve this issue without additional changes.
from swift-openapi-generator.
Blocking on OpenAPI 3.1 support for now, after that's done, we'll be in a better position to decide what to do with this.
from swift-openapi-generator.
Ok, when this PR lands, this will get closed - in OpenAPI 3.1, one can attach description
(and other core properties, like deprecated
) directly to a $ref
schema as well, removing the need for this workaround.
Test here: e669276
from swift-openapi-generator.
Now that we support OpenAPI 3.1, descriptions on refs are supported. So the solution here is to migrate your document to 3.1, then descriptions will work.
from swift-openapi-generator.
Related Issues (20)
- How to send invalid data with the client to test negative scenarios? HOT 4
- Is it possible to write middleware to instrument decoding errors? HOT 14
- PlatformChecks emits error when compiling for MacCatalyst HOT 2
- Empty Dictionary fails to encode HOT 9
- How to calculate response length? HOT 6
- Issue with Executing Unit Tests via CLI with swift-openapi-generator added to the package. HOT 9
- registerHandlers should throw an error if serverURL doesn't match documentation HOT 2
- Allowing disabling percent encoding for some HTTP header fields HOT 10
- Default responses lead to invalid Swift code HOT 3
- Issue Enabling OpenAPIGenerator Plugin for Xcode Cloud Build HOT 1
- More config options, including pointing to spec file location HOT 5
- Expose internal symbols HOT 4
- Questions re: anyOf/allOf/oneOf, and one more thing HOT 5
- Swift tools version 5.9.2 but the installed version is 5.9.0 HOT 4
- Parsing ISO8601 date time from server fails due to milliseconds HOT 2
- How to send a file in multipart/form-data? HOT 3
- Convert the repsonse to an array of structs HOT 8
- Streamlining Use HOT 10
- Re-enable strict concurrency checking for swift-openapi-urlsession
- How to throw errors that won't get transformed to ServerError? HOT 9
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.