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

Parameter description doesn't take into account enum inside schema #820

Open
alexeyr-ci opened this issue Aug 7, 2024 · 2 comments
Open

Comments

@alexeyr-ci
Copy link

alexeyr-ci commented Aug 7, 2024

In OpenAPI/Swagger 2.0, enum parameters are described using

        - in: query
          name: sort
          description: Sort order
          type: string
          enum: [asc, desc]

In 3.0, it should be

        - in: query
          name: sort
          description: Sort order
          schema:
            type: string
            enum: [asc, desc]

and the 2.0 style description fails to validate.

But the converter only supports the first option:

getParameterDescription: function(parameter) {
if (!_.isObject(parameter)) {
return '';
}
return (parameter.required ? '(Required) ' : '') + (parameter.description || '') +
(parameter.enum ? ' (This can only be one of ' + parameter.enum + ')' : '');
},

I believe this changes should fix it:

    const enum = parameter.enum ?? parameter.schema?.enum;
    return (parameter.required ? '(Required) ' : '') + (parameter.description || '') +
      (enum ? ' (This can only be one of ' + enum + ')' : '');

There's also a more minor issue that if the parameter description is empty, but the other two parts aren't, there are two spaces between (Required) and (This can only be...).

When debugging, I see lib/schemaUtils.js being hit, and not the equivalent in libV2/schemaUtils.js

getParameterDescription = (parameter) => {
if (!_.isObject(parameter)) {
return '';
}
return (parameter.required ? '(Required) ' : '') + (parameter.description || '') +
(parameter.enum ? ' (This can only be one of ' + parameter.enum + ')' : '');
},
I don't know why, but maybe that needs to be updated similarly.

@sahalbelam
Copy link

enum can only be used in typescript right???

@alexeyr-ci
Copy link
Author

@sahalbelam No, why? It just means that a request/response passing something else is invalid, the language used in the OpenAPI client/server doesn't matter.

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

2 participants