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

How to "merge" allOfs #94

Open
alexbt opened this issue May 24, 2017 · 5 comments
Open

How to "merge" allOfs #94

alexbt opened this issue May 24, 2017 · 5 comments

Comments

@alexbt
Copy link

alexbt commented May 24, 2017

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.

@casualjim
Copy link
Member

Doesn't the code generator merge them?

@alexbt
Copy link
Author

alexbt commented May 25, 2017

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.

@casualjim
Copy link
Member

casualjim commented May 26, 2017

You can take a look here: https://github.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://github.com/go-swagger/go-swagger/tree/markdown-gen

You would use it with swagger generate markdown --help

@casualjim
Copy link
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

@fredbi fredbi transferred this issue from go-openapi/spec Jan 9, 2024
@fredbi
Copy link
Member

fredbi commented Jan 9, 2024

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
Projects
None yet
Development

No branches or pull requests

4 participants