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

Introduce --use-iso-date-format CLI tool argument #73

Merged
merged 11 commits into from
Jun 15, 2023

Conversation

christianhelle
Copy link
Owner

@christianhelle christianhelle commented Jun 15, 2023

This resolves #66 which was reported by @brease-colin

This introduces the --use-iso-date-format CLI tool argument that explicitly formats date query string parameters in ISO 8601 standard date format using delimiters (yyyy-MM-dd <-> 2023-06-15)

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
    refitter ./openapi.json --no-operation-headers
    refitter ./openapi.json --use-iso-date-format

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                                          
        --no-operation-headers                         Don't generate operation headers                                 
        --no-logging                                   Don't log errors or collect telemetry                            
        --use-iso-date-format                          Explicitly format date query string parameters in ISO 8601       
                                                       standard date format using delimiters (2023-06-15)               

The following example OpenAPI spec:

{
  "swagger": "2.0",
  "info": {
    "title": "XX",
    "version": "0.0.0"
  },
  "host": "x.io",
  "basePath": "/",
  "schemes": [
    "https"
  ],
  "paths": {
    "/t/dummy/{employee_id}": {
      "get": {
        "summary": "X",
        "description": "X",
        "operationId": "dummy",
        "parameters": [
          {
            "name": "employee_id",
            "in": "path",
            "description": "the specific employee",
            "required": true,
            "format": "int64",
            "type": "integer"
          },
          {
            "name": "valid_from",
            "in": "query",
            "description": "the start of the period",
            "required": true,
            "format": "date",
            "type": "string"
          },
          {
            "name": "valid_to",
            "in": "query",
            "description": "the end of the period",
            "required": true,
            "format": "date",
            "type": "string"
          }
        ],
        "responses": {
          "200": {
            "description": "No response was specified",
            "schema": {
              "$ref": "#/definitions/DummyList"
            }
          }
        },
        "produces": [
          "application/json",
          "application/xml"
        ]
      }
    },
  }
}

generates the following code when using the --use-iso-date-format CLI tool argument

public interface IXX
{
    /// <summary>
    /// X
    /// </summary>
    [Get("/t/dummy/{employee_id}")]
    Task Dummy(long employee_id, [Query(Format = "yyyy-MM-dd")] System.DateTimeOffset valid_from, [Query(Format = "yyyy-MM-dd")] System.DateTimeOffset valid_to);
}

@christianhelle christianhelle added the enhancement New feature, bug fix, or request label Jun 15, 2023
@christianhelle christianhelle merged commit b7b5bf9 into main Jun 15, 2023
@christianhelle christianhelle deleted the iso-date-format branch June 15, 2023 14:40
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.

String parameters with format 'date' get no Format in the QueryAttribute
1 participant