kubernetes / kube-openapi

Kubernetes OpenAPI spec generation & serving
Apache License 2.0
319 stars 208 forks source link

Support defining a custom schema from raw json #456

Closed ryantxu closed 8 months ago

ryantxu commented 8 months ago

The ability to add OpenAPIV3Definition() is essential when trying to integrate existing complex types, however it requires importing this library.

For simple types, this can be avoided using:

    func (_ Time) OpenAPISchemaType() []string { return []string{"string"} }
    func (_ Time) OpenAPISchemaFormat() string { return "date-time" }

This PR proposes adding a new function that lets you return a raw spec directly

func (FooV3Raw) OpenAPISchemaJSON() json.RawMessage {
    return json.RawMessage(`{
        "description": "something custom",
        "type": "object",
        "required": ["type", "value"],
        "properties": {
            "type": {
                "type": "string"
            },
            "value": {
                "type": "string"
            }
        }
    }`)
}

TODO:

k8s-ci-robot commented 8 months ago

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: ryantxu Once this PR has been reviewed and has the lgtm label, please assign sttts for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files: - **[OWNERS](https://github.com/kubernetes/kube-openapi/blob/master/OWNERS)** Approvers can indicate their approval by writing `/approve` in a comment Approvers can cancel approval by writing `/approve cancel` in a comment
ryantxu commented 8 months ago

For context -- we are aiming to include values from https://github.com/grafana/grafana-plugin-sdk-go in apis exposed using kube-openapi.

Any better suggestions for function naming?

ryantxu commented 8 months ago

this is not working as i hoped it might... will think some more and revist if it still makes sense