Skip to content

"parameters" is a required property even if all parameters are optional #1334

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
denisw opened this issue Sep 8, 2023 · 0 comments · Fixed by #1335
Closed
2 tasks done

"parameters" is a required property even if all parameters are optional #1334

denisw opened this issue Sep 8, 2023 · 0 comments · Fixed by #1335
Labels
bug Something isn't working openapi-ts Relevant to the openapi-typescript library

Comments

@denisw
Copy link

denisw commented Sep 8, 2023

Description

When an operation has only optional parameters are defined, the generated operation typings still output parameters as a required property, even though all properties within are optional. This means that when using the schema with openapi-fetch, I have to pass { parameters: {} } instead of just {} if I don't want to pass any of the optional parameters.

Name Version
openapi-typescript 6.5.5
Node.js 18.17.0
OS + version macOS 13.5.1

Reproduction

Generate typings for a path with only optional parameters, e.g.:

paths:
  /foo:
    operationId: foo
    parameters:
      - in: header
        name: optional-header
        required: false
    responses:
      200:
        description: Success

Expected result

I would expect parameters to be optional in the generated operation type, like this:

export interface operations {
  // ...
  foo: {
    parameters?: {
      header?: {
        "optional-header"?: string;
      };
    };
    // ...
  };
}

Instead, parameters is defined as a required property.

Checklist

@denisw denisw added bug Something isn't working openapi-ts Relevant to the openapi-typescript library labels Sep 8, 2023
@denisw denisw changed the title "parameters" is required property even if all parameters are optional "parameters" is a required property even if all parameters are optional Sep 8, 2023
duncanbeevers added a commit to duncanbeevers/openapi-typescript that referenced this issue Sep 11, 2023
duncanbeevers added a commit to duncanbeevers/openapi-typescript that referenced this issue Sep 11, 2023
drwpow pushed a commit that referenced this issue Sep 12, 2023
* feat: parameters is optional when every parameter is optional

Closes #1334

* fixup! feat: parameters is optional when every parameter is optional
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working openapi-ts Relevant to the openapi-typescript library
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant