-
Notifications
You must be signed in to change notification settings - Fork 125
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
Support OpenAPI 3.1 #39
Comments
I'd be curious to hear your thoughts on how close to the mark OpenAPIKit's new compatibility layer comes for this use-case. The idea (described in the release notes for Alpha 6 is that you would ideally have just one file that imported all of OpenAPI 3.0.x support, OpenAPI 3.1.x support, and OpenAPIKit compatibility layer -- that file would attempt to parse an OpenAPI Document as 3.0.x and convert the result to 3.1.x but then if it failed it would attempt to parse the same document as OpenAPI 3.1.x. In the release notes I give a low fidelity example w/r/t error handling because you'd probably want to give a better error if the document was supposed to be 3.0.x but failed to parse than just attempting the guaranteed failed parsing as 3.1.x. The big caveat to this approach: you need to migrate this codebase to use the Aside from that caveat, I think this approach would be well suited especially to this use-case where you are taking OpenAPI in but not then re-serializing a new OpenAPI Document because you won't be hurt by "losing" the information that the original document was imported as 3.0.x. [EDIT] RE handling of the parsing of the document as one version or another, I now see your code already takes a preemptive step of determining the document spec version prior to having OpenAPIKit parse the document, so that code would already be well equipped to decide whether to use OpenAPIKit's 3.0.x or 3.1.x module for parsing. |
Yeah I'd like us to take that approach, but I haven't played with the conversion enough yet to be confident that we won't lose fidelity in some cases, and wouldn't want to handle 3.0 and 3.1 differently in code generation. It'd be good for someone to prototype this approach and see what issues are hit. Contributions are always very welcome 🙂 |
Use case about OpenAPI 3.1: discourse_api_docs/openapi.json More info can be found at #72. |
For anyone eager to try OpenAPI 3.1 with swift-openapi-generator, you can give https://github.com/Kyle-Ye/swift-openapi-generator/tree/openapi_31x a try.
|
Looking at @Kyle-Ye's experimental converter branch, I'm concerned that we'd have to make such a large change atomically, in one go. The phases I'd like us to be able to add OpenAPI 3.1 support (while also continuing to support 3.0) in would instead look like:
But for this piecemeal approach to be possible, we'd need OpenAPIKit's |
Can we do the same like the upstream OpenAPIKit? Provide _OpenAPIGeneratorCore with dependency of OpenAPIKit and _OpenAPIGeneratorCore30 with dependency of OpenAPIKit30. Or even maintain 2 branch one for 3.0.x and one for 3.1.x. This way we'll make the implementation simpler but make the maintain harder. |
One reason of the extra adaptive code is due to the change between |
I'd like to avoid duplicating the whole generator logic module, as we want to fully migrate over to the |
I'm open to making the conversion logic public. I don't think I want to properly support them as public API, but this feels like a pretty reasonable request all things considered so I'll just think on how best to express that. It may just be documentation that indicates this as a valid piecemeal approach for now but I might make them private again in version 4.x of OpenAPIKit perhaps since that's a release I tentatively plan for code cleanup and minimum swift version bump anyway. I would advise against the multiple module strategy (which was already sounding like an unlikely option in comments above). OpenAPIKits logic and/or code structure would have been drastically more complicated if I had tried to make the same code handle both OpenAPI 3.0 and 3.1, but two modules has definitely had a high cost as well. It still might have been the right move for me, but it would be very unfortunate if that move resulted in downstream projects bifurcating their codebases as well. |
Thanks @mattpolzin, totally understood. Yeah, we would use the piecemeal compat APIs only during the transition period, so you could even consider only making them public for a single alpha release, and remove them before 3.0 goes out of alpha. |
OpenAPIKit https://github.com/mattpolzin/OpenAPIKit/releases/tag/3.0.0-alpha.8 |
So I have a PR ready, took only about 30mins to migrate the codebase to use the I do have one question, @mattpolzin though - one of the drivers of us adding 3.1 support is the ability to have |
Specifically, I'm looking for this to work (properties in object schemas):
I need to get |
Interesting. It turns out that when I first wrote my JSONSchema implementation it was not permitted to specify annotations like description next to $refs (well, it was stated that any annotations would be ignored) but now the newer versions do allow it. Even more interestingly, even the newer versions say that any given application can choose to use those annotations however it wants (it may choose to ignore them in favor of annotations within the referenced schema). However, given that OpenAPI is explicit about its support for overriding description and title alongside references, I think it is certainly the right move to carry that behavior forward into JSONSchema. Hopefully doing so will be as simple as swapping the JSONReference out for an OpenAPI.Reference (as you suggested above). I'll look into that soon. If you get a chance to throw a ticket on OpenAPIKit that would help me remember, but I think I'll get to it soon enough. |
Tracking need for overriding reference descriptions within schemas here: mattpolzin/OpenAPIKit#298 |
Ok, a new release has been cut with a few bug fixes and improvements including the ability to hang properties like I'm happy to answer questions or field suggestions regarding the changes: https://github.com/mattpolzin/OpenAPIKit/releases/tag/3.0.0-beta.2 |
@mattpolzin I just tried it out and it works great, thank you for the quick turnaround! 🙏 |
Support OpenAPI 3.1 in addition to 3.0 ### Motivation Fixes #39. We need to start accepting 3.1 documents in addition to 3.0. It also has useful features, like being able to add descriptions to references. ### Modifications Migrated the codebase to use the `OpenAPIKit` instead of the `OpenAPIKit30` module, and updated the parser to handle both 3.0 and 3.1, and convert 3.0 to 3.1 documents in memory transparently. ### Result OpenAPI 3.1 documents are now accepted, instead of rejected. Any 3.1 specific features can be addressed separately, this is the MVP support. ### Test Plan Updated the file-based reference test to use version 3.1.0, and the parser tests that 3.0.x documents are loaded and converted successfully. So no need to duplicate our reference tests or anything. Reviewed by: Kyle-Ye, glbrntt Builds: ✔︎ pull request validation (5.8) - Build finished. ✔︎ pull request validation (5.9) - Build finished. ✔︎ pull request validation (docc test) - Build finished. ✔︎ pull request validation (integration test) - Build finished. ✔︎ pull request validation (nightly) - Build finished. ✔︎ pull request validation (soundness) - Build finished. #219
Today, we assume OpenAPI 3.0.x, but we should explore how we can also support 3.1, and continue to support both in parallel for some time, as 3.0.x is still the most adopted one out in the wild.
The text was updated successfully, but these errors were encountered: