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

Duplicate Accept Headers #118

Closed
christianhelle opened this issue Aug 21, 2023 · 2 comments · Fixed by #119
Closed

Duplicate Accept Headers #118

christianhelle opened this issue Aug 21, 2023 · 2 comments · Fixed by #119
Assignees
Labels
bug Something isn't working

Comments

@christianhelle
Copy link
Owner

Description
Duplicate accept headers like [Headers("Accept: application/json, application/json")] are generated when an endpoint has multiple responses with a payload. In this case, an endpoint can respond with HTTP 200 or 203 and both responses include a application/json payload in the response body

Support Key: ptbddgt

OpenAPI Specifications

openapi: '3.0.0'
info:
  version: 'v1'
  title: 'Test API'
servers:
  - url: 'https://test.host.com/api/v1'
paths:
  /jobs/{job-id}:
    get:
      tags:
      - 'Jobs'
      summary: 'Get job details'
      description: 'Get the details of the specified job.'
      parameters:
        - in: 'path'
          name: 'job-id'
          description: 'Job ID'
          required: true
          schema:
            type: 'string'
      responses:
        '200':
          description: 'successful operation'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/JobResponse'
        '203':
          description: 'successful operation'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/JobResponse'
components:
  schemas:
    JobResponse:
      type: 'object'
      properties:
        job:
          type: 'object'
          properties:
            start-date:
              type: 'string'
              format: 'date-time'
            details:
              type: 'string'

Generated code:

public interface ITestAPI
{
    /// <summary>
    /// Get the details of the specified job.
    /// </summary>
    [Headers("Accept: application/json, application/json")]
    [Get("/jobs/{job-id}")]
    Task<JobResponse> Jobs([AliasAs("job-id")] string job_id);
}
@christianhelle christianhelle added the bug Something isn't working label Aug 21, 2023
@christianhelle christianhelle self-assigned this Aug 21, 2023
@christianhelle
Copy link
Owner Author

@guillaumeserale I found a case where [Headers("Accept: xxx. xxx")] was generated using duplicate values. A fix is on the way

@guillaumeserale
Copy link
Contributor

@christianhelle looks like I missed an edge case. Good catch! 👍

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

Successfully merging a pull request may close this issue.

2 participants