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

An empty object as the request body generates an invalid TS definition #1174

Closed
1 of 2 tasks
vojty opened this issue Jun 16, 2023 · 2 comments
Closed
1 of 2 tasks

An empty object as the request body generates an invalid TS definition #1174

vojty opened this issue Jun 16, 2023 · 2 comments
Labels
bug Something isn't working good first issue Straightforward problem, solvable for first-time contributors without deep knowledge of the project openapi-ts Relevant to the openapi-typescript library PRs welcome PRs are welcome to solve this issue!

Comments

@vojty
Copy link

vojty commented Jun 16, 2023

Description

An empty object as the request body generates an invalid TS definitionL

export interface operations {

  /**
   * Test 
   * @description Body is ignored
   */
  test: {
    requestBody?: "*/*": never; // <-------------------------------
    responses: {
      /** @description No Content */
      204: never;
      /** @description Bad Request */
      400: never;
    };
  };
}

Name Version
openapi-typescript 6.2.8
Node.js 18.6.0

Reproduction

Example YAML:

openapi: 3.0.1
info:
  title: Test
  version: 1.0.0
  license:
    name: MIT
    url: https://opensource.org/licenses/MIT
servers:
  - url: http://localhost:8080
security:
  - api_keys: []
paths:
  /api/v1/test:
    post:
      operationId: test
      summary: Test
      description: Body is ignored
      requestBody:
        required: false
        content: {}
      responses:
        204:
          description: No Content
        400:
          description: Bad Request
components:
  securitySchemes:
    api_keys:
      description: |
        Generate your secret API key in the app settings.
      name: secret-key
      type: apiKey
      in: header

The problem can be mitigated by removing requestBody completely in this case, but still it shouldn't generate invalid TS syntax.

Expected result

(in case it’s not obvious)

Checklist

@vojty vojty added bug Something isn't working openapi-ts Relevant to the openapi-typescript library labels Jun 16, 2023
@drwpow drwpow added good first issue Straightforward problem, solvable for first-time contributors without deep knowledge of the project PRs welcome PRs are welcome to solve this issue! labels Jul 25, 2023
@drwpow
Copy link
Contributor

drwpow commented Jul 25, 2023

Thanks for the great example! This should be an easy find & fix.

@drwpow
Copy link
Contributor

drwpow commented Aug 1, 2023

Related: #1109

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Straightforward problem, solvable for first-time contributors without deep knowledge of the project openapi-ts Relevant to the openapi-typescript library PRs welcome PRs are welcome to solve this issue!
Projects
None yet
Development

No branches or pull requests

2 participants