Skip to content

$ref in parameters is not working #989

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
2 tasks done
axelhzf opened this issue Nov 14, 2022 · 3 comments
Closed
2 tasks done

$ref in parameters is not working #989

axelhzf opened this issue Nov 14, 2022 · 3 comments
Labels
bug Something isn't working

Comments

@axelhzf
Copy link
Contributor

axelhzf commented Nov 14, 2022

Description

Using $ref in the parameters section does not generate the type correctly

OpenAPI

{
  "openapi": "3.0.3",
  "info": {
    "title": "",
    "version": ""
  },
  "paths": {
    "/get": {
      "parameters": [
        {
          "$ref": "#/components/parameters/limit"
        }
      ]
    }
  },
  "components": {
    "parameters": {
      "limit": {
        "required": true,
        "in": "query",
        "name": "limit",
        "schema": {
          "type": "number"
        }
      }
    }
  }
}

Generated TS

export interface paths {
  "/get": {

  };
}

export interface components {
  schemas: never;
  responses: never;
  parameters: {
    limit: number;
  };
  requestBodies: never;
  headers: never;
  pathItems: never;
}

*Expected TS

export interface paths {
  "/get": {
     parameters: {
        query: {
           limit: components['parameters']['limit']
        }
     }
  };
}

Checklist

  • My OpenAPI schema passes a validator
  • I’m willing to open a PR for this (see CONTRIBUTING.md)
@axelhzf axelhzf added the bug Something isn't working label Nov 14, 2022
@axelhzf axelhzf changed the title $ref in parameters not working $ref in parameters is not working Nov 14, 2022
@axelhzf
Copy link
Contributor Author

axelhzf commented Nov 14, 2022

I think that the problem could be in this part of the code https://github.com/drwpow/openapi-typescript/blob/main/src/transform/operation-object.ts#L72-L74

This is expecting paramIn to be part of the ref like components["parameters"]["query"]["limit"] but it is actually components["parameters"]["limit"]

@wolfy1339
Copy link

I actually had opened #984 with this exact problem.

@axelhzf
Copy link
Contributor Author

axelhzf commented Nov 14, 2022

Ops, I didn't realize your issue is the same

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants