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

referencing #/components/schema when they don't exist #780

Open
2 tasks done
mariusflorescu opened this issue Jan 19, 2024 · 0 comments
Open
2 tasks done

referencing #/components/schema when they don't exist #780

mariusflorescu opened this issue Jan 19, 2024 · 0 comments

Comments

@mariusflorescu
Copy link

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the issue has not already been raised

Issue

I'm using a TS to JSON schema generator that basically creates JSON files with definitions of various API responses.
When running the script to generate the OpenAPI file, some reference #/components/schema/*, which doesn't exist since the schema is empty.

I don't know honestly if this is because of #675.

export const options: RouteShorthandOptions = {
  schema: {
    summary: "Some Summary",
    description: "Returns a list of items",
    params: GetItemsParamsSchema,
    response: {
      200: ItemListResponseSchema,
    },
  },
}

Where ItemListReponseSchema.json looks like this:

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$ref": "#/definitions/ItemListResponse",
  "definitions": {
    "ItemListResponse": {
      "type": "array",
      "items": {
        "$ref": "#/definitions/Item"
      }
    },
    "Item": {
      "type": "object",
      "properties": {
        // some properties
      },
      "required": [
        // some required properties
      ],
      "additionalProperties": false
    }
  }
}

The generated openAPI spec file:

components:
  schemas: {}
# ... other things
 responses:
        "200":
          description: Default Response
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: "#/components/schemas/Item"
                definitions:
                  Item:
                    type: object
                    properties:
                      # some properties

The workaround I found is to manually add the components: {schema: {}}, but this is quite inconvenient.

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

1 participant