Skip to content
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

Option to resolve $ref style references #217

Closed
jakobkmar opened this issue Dec 20, 2021 · 6 comments
Closed

Option to resolve $ref style references #217

jakobkmar opened this issue Dec 20, 2021 · 6 comments

Comments

@jakobkmar
Copy link

jakobkmar commented Dec 20, 2021

Describe the problem you'd like to solve

image
I want to resolve references like this one.
The reference points to another node in the same file.

I don't know how I would do this with the normal kotlinx.serialization api, but for the yaml parser itself this should be possible.

Describe the solution you'd like

Could there be an option to enable that these references get resolved automatically?

Describe alternatives you've considered

No response

Additional context

No response

@charleskorn
Copy link
Owner

Hi @jakobkmar, given this isn't a standard YAML feature, I'm not keen to add it to kaml.

kaml does already support YAML's anchors and aliases feature, which you could use to achieve the same result.

If you can't change the format of the file, I'd suggest either resolving the references in your application, or look at using a lower-level library like SnakeYAML.

@jakobkmar
Copy link
Author

thank you for the quick reply

I'd suggest either resolving the references in your application

do you have a suggestion how this can be done? the problem in my case is that this parameter property does not always contain a reference, sometimes it is a reference, sometimes the values are inlined

@charleskorn
Copy link
Owner

You could deserialise into a polymorphic type that represents either a concrete value or a reference, then go through and resolve the references to the concrete values

@jakobkmar
Copy link
Author

I will have a look into that, thank you!

@jakobkmar
Copy link
Author

If the content (in my example) can be either this:

parameters:
 - in: query
   name: index
   schema:
     type: string
     enum:
       - relevance
       - downloads
       - follows
       - newest
       - updated
     default: relevance
     example: downloads

or this (with $ref):

parameters:
 - $ref: "#/components/parameters/ProjectIdentifier"

then how could this be represented using polymorphism?
And which polymorphism style of kaml should I use in this case?

@jakobkmar
Copy link
Author

jakobkmar commented Dec 20, 2021

Oh just read about content based polymorphic deserialization, thats what I need.
Thank you for pointing me in the right direction :)

From my side, this issue is resolved now! (However I have to convert to JSON, because this is a json only feature)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants