Skip to content

encoding/openapi: add support for paths section #386

@cueckoo

Description

@cueckoo

Originally opened by @proppy in cuelang/cue#386

Is your feature request related to a problem? Please describe.

Currently when doing --out openapi the paths section of the OpenAPI spec would be omitted in the generated output even if a paths value exist in the cue input.

Describe the solution you'd like

It would be nice if paths could be defined along side components.

Describe alternatives you've considered

One alternative could be layer a _path.cue file on top of the generated components.cue, but you have to resolve the components reference yourself.

Additional context

Example:

paths 🍡 cat foo.cue 
info: {
  title: "Foo API"
  version: "v1"
}

#Foo: bar: number

Paths: "/foo":  post: {
  operationId: "foo"
  summary: "foo it"
  responses: "200": content: "application/json": schema: #Foo
}

Currently generate:

{
    "openapi": "3.0.0",
    "info": {
        "title": "Foo API",
        "version": "v1"
    },
    "paths": {},
    "components": {
        "schemas": {
            "Foo": {
                "type": "object",
                "required": [
                    "bar"
                ],
                "properties": {
                    "bar": {
                        "type": "number"
                    }
                }
            }
        }
    }
}

While it would be nice to have something like this instead:

{
    "openapi": "3.0.0",
    "info": {
        "title": "Foo API",
        "version": "v1"
    },
    "paths": {
        "/foo": {
            "post": {
                "operationId": "foo,
                "summary": "foo it",
                "responses": {
                    "200": {
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/#Foo"
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    "components": {
        "schemas": {
            "Foo": {
                "type": "object",
                "required": [
                    "bar"
                ],
                "properties": {
                    "bar": {
                        "type": "number"
                    }
                }
            }
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions