You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When generating Swift code from the API spec, path variables that contain a “-” are not recognized as path variables and are instead generated as fixed URL parameters/paths. However the path variable is generated correctly, its just not used:
/// - Remark: Generated from `#/paths/testresult/{qrcode-uuid}/GET/path`.
publicstructPath:Sendable,Hashable{
/// UUID associated with the specific test result
///
/// - Remark: Generated from `#/paths/testresult/{qrcode-uuid}/GET/path/qrcode-uuid`.
publicvarqrcode_hyphen_uuid:Swift.String
/// Creates a new `Path`.
///
/// - Parameters:
/// - qrcode_hyphen_uuid: UUID associated with the specific test result
publicinit(qrcode_hyphen_uuid:Swift.String){self.qrcode_hyphen_uuid = qrcode_hyphen_uuid
}}
Reproduction
openapi: 3.0.3info:
title: Exampledescription: This is the API definition for the example-appcontact:
email: [email protected]license:
name: Apache 2.0url: http://www.apache.org/licenses/LICENSE-2.0.htmlversion: 1.0.11servers:
- url: http://localhost:8080/api/v1tags:
- name: Test-Resultpaths:
/testresult/{qrcode-uuid}:
get:
tags:
- Test-Resultsummary: "Retrieves a specific test result by UUID as an encrypted ZIP file"operationId: "get_test_result"x-openapi-router-controller: openapi_server.controllers.test_result_controllerparameters:
- in: pathname: qrcode-uuidrequired: trueschema:
type: stringdescription: "UUID associated with the specific test result"responses:
'200':
description: "Successful operation, encrypted test result retrieved"content:
application/zip:
schema:
type: stringformat: binarydescription: "Encrypted ZIP file containing the test result"'404':
description: "Test result not found"'500':
description: "Server error"/testresult/upload/{qrcodeuuid}:
put:
tags:
- Test-Resultsummary: "Uploads a test result zip file"x-openapi-router-controller: openapi_server.controllers.test_result_controllerparameters:
- in: pathname: qrcodeuuidrequired: trueschema:
type: stringdescription: "UUID associated with the QR code"
- in: queryname: study-secretrequired: trueschema:
type: stringdescription: "the study secret for auth"responses:
'200':
description: "Successful operation"content:
application/json:
schema:
$ref: '#/components/schemas/ApiResponse''409':
description: "Testresult already exists"content:
application/json:
schema:
$ref: '#/components/schemas/ApiResponse'requestBody:
required: truedescription: "Encrypted ZIP file containing test results"content:
application/zip:
schema:
type: stringformat: binarydescription: "Encrypted ZIP file"/health:
get:
tags:
- Health Checksummary: "Health Check Endpoint"description: "Returns the health status of the API server"operationId: "get_health_status"x-openapi-router-controller: openapi_server.controllers.health_check_controllerresponses:
'200':
description: "API server is up and running"content:
application/json:
schema:
type: objectproperties:
status:
type: stringexample: "healthy"timestamp:
type: stringformat: date-timeexample: "2024-05-29T12:34:56Z"components:
schemas:
ApiResponse:
type: objectproperties:
code:
type: integerformat: int32type:
type: stringmessage:
type: stringxml:
name: ApiResponse
Hi @ChipCracker, thank you for this great bug report!
You are correct, the bug is caused by the hyphen in the parameter name. It isn't getting correctly parsed by the regular expression that splits the path into components.
I have a fix ready locally, let me open a PR shortly.
### Motivation
Fixes#601, check out the issue for details.
### Modifications
Adds hyphen to the regular expression that parses out params from the
URL template.
### Result
Correctly handle path params with hyphens in the name.
### Test Plan
Added a unit test.
Description
When generating Swift code from the API spec, path variables that contain a “-” are not recognized as path variables and are instead generated as fixed URL parameters/paths. However the path variable is generated correctly, its just not used:
Example:
/testresult/upload/{qrcode-uuid}:
Becomes (Client.swift):
However, the expected behavior would be:
Types.swift:
Reproduction
Package version(s)
Expected behavior
Environment
Additional information
Currently generated code:
The text was updated successfully, but these errors were encountered: