GithubHelp home page GithubHelp logo

Comments (2)

seriousme avatar seriousme commented on August 19, 2024

Hi,

I had a look and the error is from fastify, not fastify-openapi-glue.

Putting in a console.log(JSON.stringify(item,null,2)); in just before fastify route registration in generatedProject/node-modules/fastify-openapi-glue/index.js shows the config passed to fastify.

{
  "method": "POST",
  "url": "/MyPath",
  "schema": {
    "summary": "My Test Path",
    "response": {
      "200": {
        "allOf": [
          {
            "allOf": [
              {
                "type": "object",
                "x-abstract": true,
                "properties": {
                  "Identifier": {
                    "type": "string",
                    "description": "Identifier of response",
                    "minLength": 1
                  }
                }
              }
            ]
          },
          {
            "type": "object",
            "required": [
              "myPayload"
            ],
            "properties": {
              "myPayload": {
                "type": "string"
              }
            }
          }
        ]
      }
    }
  },
  "operationId": "MyPath",
  "openapiSource": {
    "summary": "My Test Path",
    "responses": {
      "200": {
        "description": "Success",
        "x-nullable": false,
        "schema": {
          "allOf": [
            {
              "allOf": [
                {
                  "type": "object",
                  "x-abstract": true,
                  "properties": {
                    "Identifier": {
                      "type": "string",
                      "description": "Identifier of response",
                      "minLength": 1
                    }
                  }
                }
              ]
            },
            {
              "type": "object",
              "required": [
                "myPayload"
              ],
              "properties": {
                "myPayload": {
                  "type": "string"
                }
              }
            }
          ]
        }
      }
    }
  }
}

The openapiSource property is ignored by fastify.

This config can easily be fed to a very simple fastify server, e.g. see:
test-fastify.js.txt

As far as I can see the schema is valid JSON schema, but somehow fastify doesn't correctly process it. One thing that might be missing is a body parameter, it could be that fastify requires an input parameter on a POST operation. I checked by changing the method to GET but still got the same schema error :-(

Looking at a minimal doc that satisfies your schema

{
  "myPayload": "ABCDEFGH",
  "Identifier": "ABCDEFGHIJKLMNOPQRSTU"
}

it might be an option to simplify your schema, although I suspect that your original schema is bigger than this.

I'm out of ideas for now, and I would suggest taking the simple fastify server code attached to the fastify project for feedback.

Kind regards,
Hans

from fastify-openapi-glue.

schulz3000 avatar schulz3000 commented on August 19, 2024

Thanks for the fast reply. You point me in the right direction.
If I add type: object to the schema node in my yaml it works.

responses:
        '200':
          description: Success
          x-nullable: false
          schema:
            type: object
            allOf:
              - $ref: '#/definitions/MyResponse'
              - type: object
                required:
                - myPayload
                properties:
                  myPayload:
                    type: string

from fastify-openapi-glue.

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.