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

OpenAPI description is missing the default value of postgres columns(?) #1871

Closed
fjf2002 opened this issue Jun 11, 2021 · 7 comments · Fixed by #1928
Closed

OpenAPI description is missing the default value of postgres columns(?) #1871

fjf2002 opened this issue Jun 11, 2021 · 7 comments · Fixed by #1928

Comments

@fjf2002
Copy link
Contributor

fjf2002 commented Jun 11, 2021

Hello, great work! I'm currently getting to know postgrest, and considering it for my project as a slim "application server" replacement.

Environment

  • PostgreSQL version: docker image 13

  • PostgREST version: docker image v7.0.1

  • Operating system: ubuntu 20.04 on WSL2

Description of issue

Expected behavior vs actual behavior

When a postgres column has a default value, I would wish that the OpenAPI description reflects that (which currently does not seem to be the case?).

Steps to reproduce

CREATE TABLE t (i int DEFAULT 42)

See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.2.md : I would have expected the following:

default - The default value represents what would be assumed by the consumer of the input as the value of the schema if one is not provided. Unlike JSON Schema, the value MUST conform to the defined type for the Schema Object defined at the same level. For example, if type is string, then default can be "foo" but cannot be 1.

@laurenceisla
Copy link
Member

laurenceisla commented Jun 16, 2021

Hello! I've checked, and the default value can be found in the definitions section:

{
  "definitions": {
    "t": {
      "properties": {
        "i": {
          "default": 42,
          "format": "integer",
          "type": "integer"
        }
      },
      "type": "object"
    }
  }
}

Is this what you're looking for? If so, maybe the schema needed a reload before making the request again.

@fjf2002
Copy link
Contributor Author

fjf2002 commented Jun 17, 2021

Thanks. Sorry, that was my fault.

@fjf2002 fjf2002 closed this as completed Jun 17, 2021
@fjf2002
Copy link
Contributor Author

fjf2002 commented Jun 21, 2021

Wait a second...
defaults still seem to be missing for data types text, date and time:

CREATE TABLE pvz.newtable (
	name text NOT NULL DEFAULT 'Sepp'::text,
	anzahl int4 NULL DEFAULT 42,
	rate float4 NULL DEFAULT 1.34,
	isvalid bool NOT NULL DEFAULT true,
	datum date NULL DEFAULT '1900-01-01'::date,
	zeit time NULL DEFAULT '13:37:00'::time without time zone,
	CONSTRAINT newtable_pk PRIMARY KEY (name)
);

... yields the following spec:

"definitions": {
    "newtable": {
      "required": [
        "name",
        "isvalid",
        "famstand"
      ],
      "properties": {
        "name": {
          "format": "text",
          "type": "string",
          "description": "Note:\nThis is a Primary Key.<pk/>"
        },
        "anzahl": {
          "default": 42,
          "format": "integer",
          "type": "integer"
        },
        "rate": {
          "default": 1.34,
          "format": "real",
          "type": "number"
        },
        "isvalid": {
          "default": true,
          "format": "boolean",
          "type": "boolean"
        },
        "datum": {
          "format": "date",
          "type": "string"
        },
        "zeit": {
          "format": "time without time zone",
          "type": "string"
        }
      },
      "type": "object"
    },

@fjf2002
Copy link
Contributor Author

fjf2002 commented Jul 19, 2021

Any fixes or at least a confirmation of the problem here?
Thank You.

@laurenceisla
Copy link
Member

laurenceisla commented Jul 19, 2021

@fjf2002 I was checking, and the schema cache shows the default value as: 'Sepp'::text for the name column, for instance.

s =
(mempty :: Schema)
& default_ .~ (JSON.decode . toS =<< colDefault c)

Here, it's decoded, but it looks like it returns Nothing for that kind of default values (the ones with explicit casting), that's why it doesn't show when accessing the OpenApi endpoint.

That would be a starting point to solve the issue, but for now we are mostly concentrating our efforts on the next v8 release.

@fjf2002
Copy link
Contributor Author

fjf2002 commented Jul 20, 2021

@laurenceisla thank you for your investigation. I'm afraid my haskell knowledge probably does not suffice to solve it on my own. Good luck on v8 release.

@wolfgangwalther
Copy link
Member

Here, it's decoded, but it looks like it returns Nothing for that kind of default values (the ones with explicit casting), that's why it doesn't show when accessing the OpenApi endpoint.

I understand this is a bug then?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

3 participants