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

Rendering the spec with internalized external references #222

Closed
yozel opened this issue Dec 18, 2023 · 4 comments
Closed

Rendering the spec with internalized external references #222

yozel opened this issue Dec 18, 2023 · 4 comments
Labels
enhancement New feature or request

Comments

@yozel
Copy link

yozel commented Dec 18, 2023

I'm trying to migrate https://github.com/deepmap/oapi-codegen into libopenapi and I just need to implement one last functionality. Is it possible to render a document as a yaml/json with internalized external references so it would not have any external dependencies? kin-api has swagger.InternalizeRefs function for that (example usage). I was wondering if there's such a thing exist in libopenapi?

Example:
From

{
    "openapi": "3.0.0",
    "info": {},
    "paths": {},
    "components": {
        "schemas": {
            "Container": {
                "properties": {
                    "object_a": {
                        "$ref": "./packageA/spec.yaml#/components/schemas/ObjectA"
                    },
                    "object_b": {
                        "$ref": "./packageB/spec.yaml#/components/schemas/ObjectB"
                    },
                    "object_c": {
                        "$ref": "./object_c.json"
                    }
                }
            }
        }
    }
}

to

{
    "components": {
        "schemas": {
            "Container": {
                "properties": {
                    "object_a": {
                        "$ref": "#/components/schemas/ObjectA"
                    },
                    "object_b": {
                        "$ref": "#/components/schemas/ObjectB"
                    },
                    "object_c": {
                        "$ref": "#/components/schemas/object_c"
                    }
                }
            },
            "ObjectA": {
                "properties": {
                    "name": {
                        "type": "string"
                    },
                    "object_b": {
                        "$ref": "#/components/schemas/ObjectB"
                    }
                }
            },
            "ObjectB": {
                "properties": {
                    "name": {
                        "type": "string"
                    }
                }
            },
            "object_c": {
                "additionalProperties": true,
                "type": "object"
            }
        }
    },
    "info": {
        "title": "",
        "version": ""
    },
    "openapi": "3.0.0",
    "paths": {}
}
@daveshanley
Copy link
Member

daveshanley commented Dec 18, 2023

Would this be the same request as this? - daveshanley/vacuum#368

It currently cannot do this at the moment. It CAN render inline, but it won't restructure the document to create a single spec. This would be a new feature. Seems like it would be very useful.

@daveshanley daveshanley added the enhancement New feature or request label Dec 18, 2023
@yozel
Copy link
Author

yozel commented Dec 21, 2023

I think that would be the same request, yes.

As a proof-of-concept, I created this: https://github.com/yozel/libopenapi-internalize

I used index.Rolodex and index.Index, but not low-level or high-level models since I couldn't find a way to properly use them. Let me know if you have suggestions so I can work on the idea/feature.

@daveshanley
Copy link
Member

This feature is coming in the next release of libopenapi.

@daveshanley
Copy link
Member

This feature is now available in v0.15.0

https://pb33f.io/libopenapi/bundling/

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

No branches or pull requests

2 participants