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

Error starting glued server due to suspect schema error #70

Closed
schulz3000 opened this issue Apr 22, 2020 · 2 comments
Closed

Error starting glued server due to suspect schema error #70

schulz3000 opened this issue Apr 22, 2020 · 2 comments

Comments

@schulz3000
Copy link
Contributor

Hi,
I struggled a bit to get fastify running with openapi glue.

If I start the fastify server I get following error:
FST_ERR_SCH_BUILD: Failed building the schema for POST: /MyPath, due error undefined unsupported

I created a minimum repro with the attached swagger file:

  • MySwagger.txt (Please rename file after download to MySwagger.yaml. Github is not supporting upload of yaml files.)
  • npx github:seriousme/fastify-openapi-glue MySwagger.yaml
  • cd generatedProject
  • npm install
  • npm run start
    -> results in described error

Maybe something is wrong with my swagger file but the online swagger editor mentioned no errors.

Can someone give me a hint what is going wrong here?

@seriousme
Copy link
Owner

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

@schulz3000
Copy link
Contributor Author

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

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

No branches or pull requests

2 participants