1
votes

Is there a way to split a swaggerfile / OpenAPI specs file, either JSON or YAML, encoding every $ref into a separate file? Because I found a lot of solutions to achieve the opposite (multiple files -> single file), but none for this.

What I'd like to achieve is the following: I have a huge JSON swaggerfile that contains internal $refs. I'd like to have a single file for each and every object or path definition, and, in the root file, references (local or absolute) to these files. This way I can edit the root file to easily obtain a minimal subset of the paths and objects that I need.

{
"in": "inputField",
"required": true,
"schema": {
    "$ref": "#/components/schemas/MyObject"
},
"components": {
    "schemas": {
        "MyObject": {
            "type": "object",
            "properties": {
                "value": {
                    "type": "string"
                }
            }
        }
    }
},
"____comment": "I want MyObject definition in MyObject.json file and the $ref to that file"

}

1

1 Answers

-1
votes

Yeah, its possible, you must only use regex, and detect depedencies etc.

regex example from my project
new Regex("\"#/definitions/(.*)\"");
new Regex("#\\/definitions\\/(.*?)\\\"");
new Regex("\"" + key + "\": ");

etc. You must replace elements with dependencies, and save to file. I do sth like that to recive jschema from model. Your case,is a little diffrent, but smilar.