Skip to content

Rendering the spec with internalized external references #222

Closed

Description

@yozel

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": {}
}

Activity

  1. daveshanley commented on Dec 18, 2023

    @daveshanley
    Member

    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.

  2. added
    enhancement
    on Dec 18, 2023
  3. yozel commented on Dec 21, 2023

    @yozel
    Author

    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.

  4. daveshanley commented on Jan 18, 2024

    @daveshanley
    Member

    This feature is coming in the next release of libopenapi.

  5. daveshanley commented on Jan 18, 2024

    @daveshanley
    Member
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions