Skip to content

swagger-to-ts considers components mandatory #262

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

Closed
henhal opened this issue May 26, 2020 · 2 comments
Closed

swagger-to-ts considers components mandatory #262

henhal opened this issue May 26, 2020 · 2 comments
Labels
question Further information is requested

Comments

@henhal
Copy link
Contributor

henhal commented May 26, 2020

When running swagger-to-ts on a specification without components, it immediately fails.
However, components is an optional part of the api schema and I can think of at least two scenarios where it would not be present:

  1. All schemas are inline in paths
  2. All schemas are put in separate file(s) such as schemas.yml

My specifications are quite large and I tend to split them up into separate files as per 2). This means that operations reference schemas such as {$ref: './schemas/foo.yml#/Foo'}.
Neither of these two approaches seem to work with swagger-to-ts since it requires components to be present (and, I assume, also ignores any schemas outside of components)?

  1. Would it be possible to invoke swagger-to-ts with a raw schema file, i.e., one that simply contains the schemas instead of requiring a full OpenAPI document?
  2. Would it be possible to properly support OpenAPI documents without components? It should be possible to fetch all externally referenced schemas using standard json-ref-parser etc?
@henhal henhal changed the title Components is mandatory swagger-to-ts considers components mandatory May 26, 2020
@drwpow drwpow added the question Further information is requested label Aug 8, 2020
@hasparus
Copy link

hasparus commented Sep 30, 2020

I encountered the same problem with OpenAPI schema with `paths` on top level.
{
  "openapi": "3.0.2",
  "paths": {
    "/v1/crowd/users/": {
      "get": {
        "operationId": "listUsers",
        "description": "",
        "parameters": [],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "properties": {
                      "first_name": {
                        "type": "string",
                        "maxLength": 150
                      },
                      "last_name": {
                        "type": "string",
                        "maxLength": 150
                      },
                      "locale": {
                        "type": "string",
                        "maxLength": 20
                      },
                      "auth0_id": {
                        "type": "string",
                        "maxLength": 255
                      },
                      "username": {
                        "type": "string",
                        "description": "Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.",
                        "pattern": "^[\\w.@+-]+\\Z",
                        "maxLength": 150
                      },
                      "uuid": {
                        "type": "string",
                        "format": "uuid",
                        "readOnly": true
                      },
                      "email": {
                        "type": "string",
                        "format": "email",
                        "readOnly": true
                      },
                      "date_joined": {
                        "type": "string",
                        "format": "date-time",
                        "readOnly": true
                      },
                      "last_login": {
                        "type": "string",
                        "format": "date-time",
                        "readOnly": true
                      }
                    },
                    "required": [
                      "username"
                    ]
                  }
                }
              }
            },
            "description": ""
          }
        }
      },

// ...

What's the status of this issue and #236? Is there any work requiring external help to make schemas without components work?

@drwpow
Copy link
Contributor

drwpow commented Oct 8, 2020

Just merged #236, so this will go out with the next release!

@drwpow drwpow closed this as completed Oct 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants