GithubHelp home page GithubHelp logo

Comments (2)

pomeh avatar pomeh commented on September 26, 2024

Hello,

After following the getting started for Next.js, and customized for TypeScript, I am encoutering the same problem, running Directus v10.11.2 (through Docker).

I've found this issue as already been reported in #12921, and fixed by PR #12922, merged into main back in 2022.

It looks like the problem was on both operations read-all and read-one (aka. /items/global and /items/global/{id}), but has been fixed only on read-one.

Here is an extract of /server/specs/oas output, with a few JS comments:

    "/items/global": {
      "get": {
        "summary": "List Items",
        "description": "List the global items.",
        "operationId": "readItemsGlobal",
        "responses": {
          "200": {
            "description": "Successful request",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",           // <<<<<< data is an array, that's OK for collections but should be object for singleton (and "items" key removed)
                      "items": {
                        "type": "object",
                        "$ref": "#/components/schemas/ItemsGlobal"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },

    "/items/global/{id}": {
      "get": {
        "summary": "Retrieve an Item",
        "description": "Retrieve a single global item by unique identifier.",
        "operationId": "readSingleItemsGlobal",
        "responses": {
          "200": {
            "description": "Successful request",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",     // <<<<<< data is an object, that's OK for all (singleton and collections) 
                      "$ref": "#/components/schemas/ItemsGlobal"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },

And the corresponding API JSON output:

read-all: http://example.com/directus/items/global

{"data":{"id":1,"title":"foo","description":"bar"}}

read-one: http://example.com/directus/items/global/1

{"data":{"id":1,"title":"foo","description":"bar"}}

We can clearly see that in both API, the JSON response for singleton is the same, but it's not what's state in the OpenAPI Spec.

I guess it's the OAS spec which is incorrect.

from directus.

jscottsf avatar jscottsf commented on September 26, 2024

Seeing a similar issue with a M2A item. It's defined as an array in the spec, but really should be an object. That's what the REST API returns. e.g.

The endpoint returns the spec (snippet):

"ItemsStaticPagesSections":
{
    "properties":
    {
        "collection":
        {
            "nullable": true,
            "type": "string"
        },
        "id":
        {
            "nullable": false,
            "type": "integer"
        },
        "item":
        {
            "items":
            {
                "oneOf":
                [
                    {
                        "type": "string"
                    },
                    {
                        "$ref": "#/components/schemas/ItemsSectionHero"
                    },
                    {
                        "$ref": "#/components/schemas/ItemsSectionDifferentiators"
                    },
                    {
                        "$ref": "#/components/schemas/ItemsSectionCapabilities"
                    },
                    {
                        "$ref": "#/components/schemas/ItemsSectionTours"
                    },
                    {
                        "$ref": "#/components/schemas/ItemsSectionCaseStudies"
                    }
                ]
            },
            "nullable": true,
            "type": "array"
        },
        "sort":
        {
            "nullable": true,
            "type": "integer"
        },
        "static_pages_id":
        {
            "nullable": true,
            "oneOf":
            [
                {
                    "format": "uuid",
                    "type": "string"
                },
                {
                    "$ref": "#/components/schemas/ItemsStaticPages"
                }
            ]
        }
    },
    "type": "object",
    "x-collection": "static_pages_sections"
},

But the API returns (snippet):

NOTE: item is NOT an array.

{
    "collection": "section_hero",
    "id": 1,
    "item":
    {
        "background_image":
        {
        },
        "background_transformation": 1,
        "ctas":
        [
        ],
        "date_created": "2023-09-25T22:05:18.138Z",
        "date_updated": "2024-04-03T00:37:53.299Z",
        "id": 1,
        "paragraph": "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod",
        "status": "published",
        "title": "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod",
        "user_created": "c694c53f-161e-4340-98cf-f45e2fa3564b",
        "user_updated": "c694c53f-161e-4340-98cf-f45e2fa3564b"
    },
    "sort": 1,
    "static_pages_id": "49629f2a-4346-42b8-afd9-7977f78abe8d"
}

from directus.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.