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

encoding/openapi: add support for paths section #386

Open
cueckoo opened this issue Jul 3, 2021 · 1 comment · May be fixed by #1727
Open

encoding/openapi: add support for paths section #386

cueckoo opened this issue Jul 3, 2021 · 1 comment · May be fixed by #1727
Labels
FeatureRequest New feature or request

Comments

@cueckoo
Copy link
Collaborator

cueckoo commented Jul 3, 2021

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"
                    }
                }
            }
        }
    }
}
@andrew-womeldorf
Copy link

Updating the original issue, for current inputs/outputs on 0.4.2:

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
}
$ cue export --out openapi foo.cue 
openapi: unsupported top-level field "Paths":
    ./foo.cue:8:1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FeatureRequest New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants