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

Fix: Swagger Component Integration #14

Merged
merged 2 commits into from
Aug 17, 2023

Conversation

igrschmidt
Copy link
Contributor

This pull request addresses an issue where the Swagger plugin for ElysiaJS was not effectively merging custom components provided at the application level.

Example of the problem:

export const swaggerConfig: ElysiaSwaggerConfig = {
  documentation: {
    info: {
      title: "Endpoint Documentation",
      version: "1.0.0",
      description: "A very good description.",
    },
    components: {
      schemas: {
        User: {
          description: "string",
        },
      },
      securitySchemes: {
        JwtAuth: {
          type: "http",
          scheme: "bearer",
          bearerFormat: "JWT",
          description: "Enter JWT Bearer token **_only_**",
        },
      },
    },
  },
};
``;

Would result on a /swagger/json like this:

{
  "openapi": "3.0.3",
  "info": {
    "title": "Endpoint Documentation",
    "description": "A very good description.",
    "version": "1.0.0"
  },
  "components": {
    "schemas": {
    } ❌  Wheres our schema?
    ❌  Where's our securitySchemes?
  },
  "paths": {
  // rest of json
  },

With this fix, the plugin now correctly merges the user-defined components from the documentation configuration with the default schemas from app.meta.defs. This ensures that all user-defined Swagger components are accurately reflected in the generated documentation.

{
  "openapi": "3.0.3",
  "info": {
    "title": "Endpoint Documentation",
    "description": "A very good description.",
    "version": "1.0.0"
  "components": {
    "schemas": { ✅  Schema is present
      "User": {
        "description": "string"
      }
    },
    "securitySchemes": { ✅  securitySchemes is present
      "JwtAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "description": "Enter JWT Bearer token **_only_**"
      }
    }
  },
  "paths": {
  // rest of json
  },

@SaltyAom
Copy link
Member

Got it, it seems like this like I forgot user provided schema.
Thanks a lot!

@SaltyAom SaltyAom merged commit 103b041 into elysiajs:main Aug 17, 2023
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

Successfully merging this pull request may close these issues.

2 participants