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 support for using Cancellation Tokens #23

Merged
merged 11 commits into from
Apr 28, 2023
Merged

Conversation

christianhelle
Copy link
Owner

The changes here are requested by @kirides and will resolve #19

USAGE:
    refitter [URL or input file] [OPTIONS]

EXAMPLES:
    refitter ./openapi.json
    refitter https://petstore3.swagger.io/api/v3/openapi.yaml
    refitter ./openapi.json --namespace "Your.Namespace.Of.Choice.GeneratedCode" --output ./GeneratedCode.cs
    refitter ./openapi.json --namespace "Your.Namespace.Of.Choice.GeneratedCode" --internal
    refitter ./openapi.json --output ./IGeneratedCode.cs --interface-only
    refitter ./openapi.json --use-api-response
    refitter ./openapi.json --cancellation-tokens

ARGUMENTS:
    [URL or input file]    URL or file path to OpenAPI Specification file

OPTIONS:
                                      DEFAULT                                                                    
    -h, --help                                         Prints help information                                   
    -n, --namespace                   GeneratedCode    Default namespace to use for generated types              
    -o, --output                      Output.cs        Path to Output file                                       
        --no-auto-generated-header                     Don't add <auto-generated> header to output file          
        --interface-only                               Don't generate contract types                             
        --use-api-response                             Return Task<IApiResponse<T>> instead of Task<T>           
        --internal                                     Set the accessibility of the generated types to 'internal'
        --cancellation-tokens                          Use cancellation tokens                                   

Using the following OpenAPI spec:

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'
components:
  schemas:
    JobResponse:
      type: 'object'
      properties:
        job:
          type: 'object'
          properties:
            start-date:
              type: 'string'
              format: 'date-time'
            details:
              type: 'string'

Setting the --cancellation-tokens argument will generate code for the following interface:

using Refit;
using System.Threading;
using System.Threading.Tasks;
using System.Collections.Generic;

namespace GeneratedCode
{
    internal interface ITestAPI
    {
        /// <summary>
        /// Get the details of the specified job.
        /// </summary>
        [Get("/jobs/{job-id}")]
        Task<JobResponse> Jobs([AliasAs("job-id")] string job_id, CancellationToken cancellationToken = default);
    }
}

@christianhelle christianhelle added the enhancement New feature, bug fix, or request label Apr 28, 2023
@christianhelle christianhelle merged commit 3e084b8 into main Apr 28, 2023
@christianhelle christianhelle deleted the cancellation-tokens branch May 1, 2023 20:05
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.

Add CancellationToken cancellationToken = default to generated Methods
1 participant