-
-
Notifications
You must be signed in to change notification settings - Fork 50
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
What is the expected way to load extensions as complex types? #8
Comments
I left this open-ended to see how people would prefer to consume these extensions. This use case has come up in another project as well. There are two ways we can currently do this. You're already using the first method (which is fine if you already have the dependency in the project), or you can use I like your idea of 'registering extensions' with a type. It makes a lot of sense. It would be a nice feature to add once the library's core is in place. I'm working on a 'what-changed' feature right now and then validation after that., perhaps this would be a good follow-up feature. mainly because extensions are so crucial for custom development. |
Can I maybe suggest until a feature targeted at extensions is made, that the current options are documented instead? |
I'll update the README with a blurb and some examples and add some sample code to the docs. |
The more in-depth we use extensions, the more likely is is that we need custom extensions. New `UnpackExtensions` function in the high package makes this easy. Low level models have been updated to support feature fully and docs added in README and examples as well. Signed-off-by: Dave Shanley <dave@quobix.com>
Ok, so I went a step further and created the first step toward a register types function. To begin, there is a new There is an example available: https://github.com/pb33f/libopenapi#loading-extensions-using-complex-types It should make working with complex types and extensions much easier and reduce a lot of code. It should work until a more powerful, auto-magic version of this feature can exist, but that's more work than I have time for right now. The README has been updated, and the docs with working sample code. Available in |
Updated docs are available here: |
Extensions now arrive as Closing this as answered. |
I have an extension
x-cli-config
that enables client auto-configuration given an Open API 3 document (think stuff like security set up, additional headers to always send, and an ability to prompt users for information). This configuration object is somewhat complex with a number of nested fields/objects.It looks like libopenapi loads extensions as
interface{}
while kin-openapi loaded them asjson.RawMessage
. You can unmarshal the raw message into your struct fairly easily, but there is no stdlib way to unmarshal from already existing Go maps. For now I'm trying to use mapstructure to do something similar going frominterface{}
-> my struct, like so:Is this the right way to do it? Is there some other way you expect users of the library to load their extensions? Some kind of way to register an extension with a type before loading might be nice, and then during loading it could instantiate that type, though maybe that's overkill for this library.
Part of danielgtaylor/restish#115.
The text was updated successfully, but these errors were encountered: