sourcey / spectacle

Beautiful static documentation generator for OpenAPI/Swagger 2.0
https://sourcey.com/spectacle
Other
1.28k stars 337 forks source link

Examples should expand references? #166

Open ghost opened 6 years ago

ghost commented 6 years ago

I wonder if the example field should be allowed to have $refs in it.

In my app, there's a nested map type, let's call it FruitCartConfig:

type FruitCartConfig struct {
    fruits map[string]FruitConfig
}

type FruitConfig struct {
    values map[string]string
}

This allows me to make 1 API call that configures many fruits with many key-value pairs.

The example JSON I want to use is something like

{
    "definitions": {
        "FruitCartConfig": {
            ...
            "properties": {
                "fruits": {
                    ...
                    "example": {"apple": {"$ref": "#/definitions/FruitConfig"}}
                }
            }
        },
        "FruitConfig": {
            ...
            "properties": {
                "values": {
                    ...
                    "example": {"color": "red"}
                }
            }
        }
    }
}

which would end up generating the example shown in the output

{
    "fruits": {
        "apple": {
            "values": {
                "color": "red"
            }
        }
    }
}

Any thoughts on this?

auscaster commented 5 years ago

This would be a great feature to have. I'll mark it as a feature request and maybe somebody would like to pick it up.