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

Common parameters are not handled #241

Open
mfodor opened this issue Sep 25, 2020 · 3 comments
Open

Common parameters are not handled #241

mfodor opened this issue Sep 25, 2020 · 3 comments

Comments

@mfodor
Copy link

mfodor commented Sep 25, 2020

Official docs:
https://swagger.io/docs/specification/describing-parameters/#common

My valid configuration:

paths:
  /posts/{id}:
    # This is considered as a request method then trows error
    parameters:
      - name: id
        in: path
        description: id
        required: true
        schema:
          type: integer
          format: int32
    get:
      # ...

Error on console:

TypeError: Cannot convert undefined or null to object
    at Function.entries (<anonymous>)
    at MethodGenerator.includesSuccessResponse (node_modules/swaxios/dist/generators/MethodGenerator.js:62:54)
    at new MethodGenerator (node_modules/swaxios/dist/generators/MethodGenerator.js:49:18)
    at new ResourceGenerator (node_modules/swaxios/dist/generators/ResourceGenerator.js:40:42)
    at node_modules/swaxios/dist/Swaxios.js:45:34
    at Generator.next (<anonymous>)
    at node_modules/swaxios/dist/Swaxios.js:8:71
    at new Promise (<anonymous>)
    at __awaiter (node_modules/swaxios/dist/Swaxios.js:4:12)
    at exportServices (node_modules/swaxios/dist/Swaxios.js:34:12)
// new MethodGenerator (node_modules/swaxios/dist/generators/MethodGenerator.js:49:18)
const postFix = parameterMatch ? `By${StringUtil.camelCase(parameterMatch.splice(1), true)}` : 'All';
this.parameterMethod = this.operation.operationId || `${this.method}${postFix}`;
if (this.includesSuccessResponse(this.responses)) {
// where
//  - postFix: ById
//  - parameterMethod: propertiesById
//  - this.responses: undefined

// MethodGenerator.includesSuccessResponse (node_modules/swaxios/dist/generators/MethodGenerator.js:62:54
includesSuccessResponse(responses) {
    for (const [successCode, response] of Object.entries(responses)) { // <- response is undefined here

So, common parameters should be added to parameters as well, and if common parameters are defined it should be skipped when trying to process methods (operations).

@ffflorian
Copy link
Member

ffflorian commented Sep 25, 2020

Hi @mfodor, your link refers to OpenAPI 3, Swaxios currently supports only OpenAPI 2.

We should maybe throw an error if a user tries to parse an OpenAPI 3 document.

edit: Created #242 for that.

@mfodor
Copy link
Author

mfodor commented Sep 25, 2020

Ah, I see. Thank you for pointing out.

@ffflorian
Copy link
Member

🤦 I just noticed that common parameters are also available in OpenAPI 2, see https://swagger.io/docs/specification/2-0/describing-parameters/.

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

No branches or pull requests

2 participants