2

I have a file with the "$ref" and want that it will be resolved with the format for example:

spec:
 spaceDevelopers:
 $ref: '../someThing.yml'

I would like to resolve the $ref: '../spaceDevelopers.yml'

Inside the file in Java. I have searched for a library, but could not find a good example, how to do it.

My resources are: https://swagger.io/docs/specification/using-ref/ And https://github.com/kalaspuffar/swagger-reader/blob/master/src/main/java/org/ea/swagger/NewReader.java

I would appreciate if someone could give me a code snippet, because I can not imagine, how to do it.

Thank you

Schaumkuesschen
  • 139
  • 4
  • 18
  • It is rather unclear what you want to do. Do you want to reproduce swagger's `$ref` (i.e. create a YAML file with the `$ref` resolved)? Do you somehow want to replace `someThing.yml` with `spaceDevelopers.yml`? Please describe your expected output more clearly. – flyx May 08 '20 at 09:42
  • Adjusted, I want to reproduce swaggers ref, create a yml, even better it would be to adjust the current file and put the content inside it – Schaumkuesschen May 08 '20 at 09:51
  • Check out Swagger Parser's RefUtils for an example: https://github.com/swagger-api/swagger-parser/blob/master/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/RefUtils.java – Helen May 08 '20 at 10:13
  • Also see [How can I include a YAML file inside another?](https://stackoverflow.com/q/528281/113116) for other ideas of how to implement includes in YAML. – Helen May 08 '20 at 10:14
  • The code you're using seems to [quietly ignore non-local references](https://github.com/kalaspuffar/swagger-reader/blob/master/src/main/java/org/ea/swagger/Reader.java#L77). – flyx May 08 '20 at 10:20
  • @flyx what do you mean? – Schaumkuesschen May 09 '20 at 18:41
  • @Schaumkuesschen This is a sister file to the code file you linked. I looked around to find the part of the code that actually handles `$ref` keys and that seemed to be it. However, I don't really know the relation between Reader and NewReader though. – flyx May 09 '20 at 19:24
  • Yes, I gave up on it. OpenAPI would be a way to handle it, but I could not find any code examples, which would match my requirements. That it replace the ref with the file content. – Schaumkuesschen May 10 '20 at 15:11
  • @Schaumkuesschen have you find the solution? – Roshaan Farrukh Dec 07 '21 at 11:05

0 Answers0