mattpolzin / OpenAPIKit

Codable Swift OpenAPI implementation.
MIT License
276 stars 35 forks source link

Set Multiple OpenApi Files #354

Closed mayank50444 closed 2 months ago

mayank50444 commented 7 months ago

I wanna break my main file of openApi.json into different JSON Files. Can anyone help me how can I achieve that

mattpolzin commented 7 months ago

OpenAPIKit currently doesn't deal with files directly; that is, you read in a file and tell a some Decoder to use OpenAPIKit's Codable conformance to decode that data. Then to write a file out, you tell some Encoder to use OpenAPIKit's Codable conformance to encode a document as data and write that data to a file.

The only way to deal with multiple files on input is to use some other tool to combine the files and then pass the combined OpenAPI file to a Decoder with instructions to decode as an OpenAPI.Document. This process of combining OpenAPI files is often called "dereferencing" and it's quite common so there are a number of off the shelf tools that will perform it.

There is not really any trivial way to write something from OpenAPIKit to multiple output files that I can think of. You can take any part of the OpenAPIKit structure and encode it directly and write it to a file and in its place in the parent document put an external reference to that file, but this is a fairly involved and ad-hoc process.


All of that said, are you hoping to read in multiple files or write out multiple files? There are tentative plans to make working with multiple files easier so I may be able to use your needs to help shape some of that future work.

mattpolzin commented 2 months ago

I'll assume that this request was either to read in multiple files, which is now a feature available in the v4 alpha releases of OpenAPIKit (https://github.com/mattpolzin/OpenAPIKit/issues/279), or it was to write out multiple files, which is not a planned feature of OpenAPIKit at this time, but there is not anything that I can think of making it impossible to build such a thing in a third party codebase using OpenAPIKit.

Feel free to request I re-open this with a different interpretation than the above.