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

Add injecting header parameters #24

Merged
merged 3 commits into from
May 1, 2023

Conversation

guillaumeserale
Copy link
Contributor

I've added the generation of http headers in src/Refitter.Core/ParameterExtractor.cs.
This can be disabled by setting RefitGeneratorSettings.GenerateOperationHeaders to false.

@christianhelle christianhelle self-assigned this May 1, 2023
@christianhelle christianhelle added the enhancement New feature, bug fix, or request label May 1, 2023
@christianhelle
Copy link
Owner

@guillaumeserale Thank you for this contribution

If it's not too much trouble, can you please provide some example OpenAPI specifications with header parameters in a request? Like how it is done in #7

@guillaumeserale
Copy link
Contributor Author

guillaumeserale commented May 1, 2023

@christianhelle Sure!
There's already an example in the unit tests:
I've trimmed it down to only the delete operation that uses a header:

info:
  title: Swagger Petstore
  description: |-
    This is a sample Pet Store Server based on the OpenAPI 3.0 specification.  You can find out more about
    Swagger at [http://swagger.io](http://swagger.io). In the third iteration of the pet store, we've switched to the design first approach!
    You can now help us improve the API whether it's by making changes to the definition itself or to the code.
    That way, with time, we can improve the API in general, and expose some of the new features in OAS3.

    Some useful links:
    - [The Pet Store repository](https://github.com/swagger-api/swagger-petstore)
    - [The source API definition for the Pet Store](https://github.com/swagger-api/swagger-petstore/blob/master/src/main/resources/openapi.yaml)
  termsOfService: 'http://swagger.io/terms/'
  contact:
    email: apiteam@swagger.io
  license:
    name: Apache 2.0
    url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
  version: 1.0.5
externalDocs:
  description: Find out more about Swagger
  url: 'http://swagger.io'
tags:
  - name: pet
    description: Everything about your Pets
    externalDocs:
      description: Find out more
      url: 'http://swagger.io' 
paths:  
  '/pet/{petId}':
    delete:
      tags:
        - pet
      summary: Deletes a pet
      description: ''
      operationId: deletePet
      parameters:
        - name: api_key
          in: header
          description: ''
          required: false
          schema:
            type: string
        - name: petId
          in: path
          description: Pet id to delete
          required: true
          schema:
            type: integer
            format: int64
      responses:
        '400':
          description: Invalid pet value
      security:
        - petstore_auth:
            - 'write:pets'
            - 'read:pets'
components:  
  securitySchemes:
    petstore_auth:
      type: oauth2
      flows:
        implicit:
          authorizationUrl: 'https://petstore3.swagger.io/oauth/authorize'
          scopes:
            'write:pets': modify pets in your account
            'read:pets': read your pets
    api_key:
      type: apiKey
      name: api_key
      in: header

@christianhelle christianhelle merged commit 669eb7c into christianhelle:main May 1, 2023
@christianhelle
Copy link
Owner

This feature is now released as v0.5.1 at nuget.org

Thanks again @guillaumeserale

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature, bug fix, or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants