Skip to content

Commit

Permalink
Fix Julia template for binary string (#20355)
Browse files Browse the repository at this point in the history
* Fix Julia template for binary format

* Update julia samples

* fix missing check for the isBinary flag

Fix missing check for the isBinary flag in some places of the templates for julialang. The code would now be generated as Vector{UInt8} uniformly for binary strings. Binary strings that are also marked as files get generated as `String` data type on the client. That is because the Julia client expects a file name to be passed there.

* Fix Julia template for file

* Update julia samples

---------

Co-authored-by: tan <[email protected]>
  • Loading branch information
qiaojunfeng and tanmaykm authored Jan 11, 2025
1 parent 066a840 commit 1bc5eae
Show file tree
Hide file tree
Showing 13 changed files with 60 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const _returntypes_{{operationId}}_{{classname}} = Dict{Regex,Type}(
{{/responses}}
)

function _oacinternal_{{operationId}}(_api::{{classname}}{{#allParams}}{{#required}}, {{paramName}}::{{#dataType}}{{#isBinary}}Vector{UInt8}{{/isBinary}}{{^isBinary}}{{dataType}}{{/isBinary}}{{/dataType}}{{/required}}{{/allParams}};{{#allParams}}{{^required}} {{paramName}}=nothing,{{/required}}{{/allParams}} _mediaType=nothing)
function _oacinternal_{{operationId}}(_api::{{classname}}{{#allParams}}{{#required}}, {{paramName}}::{{#dataType}}{{#isBinary}}{{#isFile}}{{dataType}}{{/isFile}}{{^isFile}}Vector{UInt8}{{/isFile}}{{/isBinary}}{{^isBinary}}{{dataType}}{{/isBinary}}{{/dataType}}{{/required}}{{/allParams}};{{#allParams}}{{^required}} {{paramName}}=nothing,{{/required}}{{/allParams}} _mediaType=nothing)
{{#allParams}}
{{#hasValidation}}
{{#maxLength}}
Expand Down Expand Up @@ -61,7 +61,7 @@ function _oacinternal_{{operationId}}(_api::{{classname}}{{#allParams}}{{#requir
OpenAPI.Clients.set_param(_ctx.form, "{{#lambda.escapeDollar}}{{baseName}}{{/lambda.escapeDollar}}", {{paramName}}{{#isListContainer}}; collection_format="{{collectionFormat}}"{{/isListContainer}}) # type {{dataType}}
{{/isFile}}
{{#isFile}}
OpenAPI.Clients.set_param(_ctx.file, "{{#lambda.escapeDollar}}{{baseName}}{{/lambda.escapeDollar}}", {{paramName}}) # type {{#dataType}}{{#isBinary}}Vector{UInt8}{{/isBinary}}{{^isBinary}}{{dataType}}{{/isBinary}}{{/dataType}}
OpenAPI.Clients.set_param(_ctx.file, "{{#lambda.escapeDollar}}{{baseName}}{{/lambda.escapeDollar}}", {{paramName}}) # type {{#dataType}}{{#isBinary}}{{#isFile}}{{dataType}}{{/isFile}}{{^isFile}}Vector{UInt8}{{/isFile}}{{/isBinary}}{{^isBinary}}{{dataType}}{{/isBinary}}{{/dataType}}
{{/isFile}}
{{/formParams}}
OpenAPI.Clients.set_header_accept(_ctx, [{{#produces}}"{{{mediaType}}}", {{/produces}}])
Expand All @@ -74,17 +74,17 @@ end
{{/summary.length}}{{#notes.length}}{{{notes}}}

{{/notes.length}}Params:
{{#allParams}}- {{paramName}}::{{dataType}}{{#required}} (required){{/required}}
{{#allParams}}- {{paramName}}::{{#isBinary}}{{#isFile}}{{dataType}}{{/isFile}}{{^isFile}}Vector{UInt8}{{/isFile}}{{/isBinary}}{{^isBinary}}{{dataType}}{{/isBinary}}{{#required}} (required){{/required}}
{{/allParams}}

Return: {{#returnType}}{{returnType}}{{/returnType}}{{^returnType}}Nothing{{/returnType}}, OpenAPI.Clients.ApiResponse
"""
function {{operationId}}(_api::{{classname}}{{#allParams}}{{#required}}, {{paramName}}::{{dataType}}{{/required}}{{/allParams}};{{#allParams}}{{^required}} {{paramName}}=nothing,{{/required}}{{/allParams}} _mediaType=nothing)
function {{operationId}}(_api::{{classname}}{{#allParams}}{{#required}}, {{paramName}}::{{#isBinary}}{{#isFile}}{{dataType}}{{/isFile}}{{^isFile}}Vector{UInt8}{{/isFile}}{{/isBinary}}{{^isBinary}}{{dataType}}{{/isBinary}}{{/required}}{{/allParams}};{{#allParams}}{{^required}} {{paramName}}=nothing,{{/required}}{{/allParams}} _mediaType=nothing)
_ctx = _oacinternal_{{operationId}}(_api{{#allParams}}{{#required}}, {{paramName}}{{/required}}{{/allParams}};{{#allParams}}{{^required}} {{paramName}}={{paramName}},{{/required}}{{/allParams}} _mediaType=_mediaType)
return OpenAPI.Clients.exec(_ctx)
end

function {{operationId}}(_api::{{classname}}, response_stream::Channel{{#allParams}}{{#required}}, {{paramName}}::{{dataType}}{{/required}}{{/allParams}};{{#allParams}}{{^required}} {{paramName}}=nothing,{{/required}}{{/allParams}} _mediaType=nothing)
function {{operationId}}(_api::{{classname}}, response_stream::Channel{{#allParams}}{{#required}}, {{paramName}}::{{#isBinary}}{{#isFile}}{{dataType}}{{/isFile}}{{^isFile}}Vector{UInt8}{{/isFile}}{{/isBinary}}{{^isBinary}}{{dataType}}{{/isBinary}}{{/required}}{{/allParams}};{{#allParams}}{{^required}} {{paramName}}=nothing,{{/required}}{{/allParams}} _mediaType=nothing)
_ctx = _oacinternal_{{operationId}}(_api{{#allParams}}{{#required}}, {{paramName}}{{/required}}{{/allParams}};{{#allParams}}{{^required}} {{paramName}}={{paramName}},{{/required}}{{/allParams}} _mediaType=_mediaType)
return OpenAPI.Clients.exec(_ctx, response_stream)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ Method | HTTP request | Description
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**_api** | **{{classname}}** | API context | {{/-last}}{{/allParams}}{{#allParams}}{{#required}}
**{{paramName}}** | {{#isFile}}**{{dataType}}**{{/isFile}}{{#isPrimitiveType}}**{{dataType}}**{{/isPrimitiveType}}{{^isPrimitiveType}}{{^isFile}}[**{{dataType}}**]({{baseType}}.md){{/isFile}}{{/isPrimitiveType}}| {{description}} | {{#defaultValue}}[default to {{.}}]{{/defaultValue}}{{/required}}{{/allParams}}{{#hasOptionalParams}}
**{{paramName}}** | {{#isPrimitiveType}}**{{#isBinary}}{{#isFile}}{{dataType}}{{/isFile}}{{^isFile}}Vector{UInt8}{{/isFile}}{{/isBinary}}{{^isBinary}}{{dataType}}{{/isBinary}}**{{/isPrimitiveType}}{{^isPrimitiveType}}{{^isFile}}[**{{dataType}}**]({{baseType}}.md){{/isFile}}{{#isFile}}**{{#isBinary}}Vector{UInt8}{{/isBinary}}{{^isBinary}}{{dataType}}{{/isBinary}}**{{/isFile}}{{/isPrimitiveType}} | {{description}} |{{/required}}{{/allParams}}{{#hasOptionalParams}}

### Optional Parameters
{{#allParams}}{{#-last}}
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------{{/-last}}{{/allParams}}{{#allParams}}{{^required}}
**{{paramName}}** | {{#isFile}}**{{dataType}}**{{/isFile}}{{#isPrimitiveType}}**{{dataType}}**{{/isPrimitiveType}}{{^isPrimitiveType}}{{^isFile}}[**{{dataType}}**]({{baseType}}.md){{/isFile}}{{/isPrimitiveType}}| {{description}} | {{#defaultValue}}[default to {{.}}]{{/defaultValue}}{{/required}}{{/allParams}}{{/hasOptionalParams}}
**{{paramName}}** | {{#isPrimitiveType}}**{{#isBinary}}{{#isFile}}{{dataType}}{{/isFile}}{{^isFile}}Vector{UInt8}{{/isFile}}{{/isBinary}}{{^isBinary}}{{dataType}}{{/isBinary}}**{{/isPrimitiveType}}{{^isPrimitiveType}}{{^isFile}}[**{{dataType}}**]({{baseType}}.md){{/isFile}}{{#isFile}}**{{#isBinary}}Vector{UInt8}{{/isBinary}}{{^isBinary}}{{dataType}}{{/isBinary}}**{{/isFile}}{{/isPrimitiveType}} | {{description}} | {{^isBinary}}{{#defaultValue}}[default to {{.}}]{{/defaultValue}}{{/isBinary}}{{/required}}{{/allParams}}{{/hasOptionalParams}}

### Return type

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Method | HTTP request | Description
{{#operations}}
{{#operation}}
# **{{{operationId}}}**
> {{operationId}}(req::HTTP.Request{{#allParams}}{{#required}}, {{paramName}}::{{dataType}}{{/required}}{{/allParams}};{{#allParams}}{{^required}} {{paramName}}=nothing,{{/required}}{{/allParams}}) -> {{#returnType}}{{returnType}}{{/returnType}}{{^returnType}}Nothing{{/returnType}}
> {{operationId}}(req::HTTP.Request{{#allParams}}{{#required}}, {{paramName}}::{{#dataType}}{{#isBinary}}Vector{UInt8}{{/isBinary}}{{^isBinary}}{{dataType}}{{/isBinary}}{{/dataType}}{{/required}}{{/allParams}};{{#allParams}}{{^required}} {{paramName}}=nothing,{{/required}}{{/allParams}}) -> {{#returnType}}{{returnType}}{{/returnType}}{{^returnType}}Nothing{{/returnType}}

{{{summary}}}{{#notes}}

Expand All @@ -22,13 +22,13 @@ Method | HTTP request | Description
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**req** | **HTTP.Request** | The HTTP Request object | {{/-last}}{{/allParams}}{{#allParams}}{{#required}}
**{{paramName}}** | {{#isFile}}**{{dataType}}**{{/isFile}}{{#isPrimitiveType}}**{{dataType}}**{{/isPrimitiveType}}{{^isPrimitiveType}}{{^isFile}}[**{{dataType}}**]({{baseType}}.md){{/isFile}}{{/isPrimitiveType}}| {{description}} | {{#defaultValue}}[default to {{.}}]{{/defaultValue}}{{/required}}{{/allParams}}{{#hasOptionalParams}}
**{{paramName}}** | {{#isPrimitiveType}}**{{#isBinary}}Vector{UInt8}{{/isBinary}}{{^isBinary}}{{dataType}}{{/isBinary}}**{{/isPrimitiveType}}{{^isPrimitiveType}}{{^isFile}}[**{{dataType}}**]({{baseType}}.md){{/isFile}}{{#isFile}}**{{#isBinary}}Vector{UInt8}{{/isBinary}}{{^isBinary}}{{dataType}}{{/isBinary}}**{{/isFile}}{{/isPrimitiveType}}| {{description}} |{{/required}}{{/allParams}}{{#hasOptionalParams}}

### Optional Parameters
{{#allParams}}{{#-last}}
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------{{/-last}}{{/allParams}}{{#allParams}}{{^required}}
**{{paramName}}** | {{#isFile}}**{{dataType}}**{{/isFile}}{{#isPrimitiveType}}**{{dataType}}**{{/isPrimitiveType}}{{^isPrimitiveType}}{{^isFile}}[**{{dataType}}**]({{baseType}}.md){{/isFile}}{{/isPrimitiveType}}| {{description}} | {{#defaultValue}}[default to {{.}}]{{/defaultValue}}{{/required}}{{/allParams}}{{/hasOptionalParams}}
**{{paramName}}** | {{#isPrimitiveType}}**{{#isBinary}}Vector{UInt8}{{/isBinary}}{{^isBinary}}{{dataType}}{{/isBinary}}**{{/isPrimitiveType}}{{^isPrimitiveType}}{{^isFile}}[**{{dataType}}**]({{baseType}}.md){{/isFile}}{{#isFile}}**{{#isBinary}}Vector{UInt8}{{/isBinary}}{{^isBinary}}{{dataType}}{{/isBinary}}**{{/isFile}}{{/isPrimitiveType}}| {{description}} | {{^isBinary}}{{#defaultValue}}[default to {{.}}]{{/defaultValue}}{{/isBinary}}{{/required}}{{/allParams}}{{/hasOptionalParams}}

### Return type

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ The following server methods must be implemented:
{{#operation}}
- **{{operationId}}**
- *invocation:* {{httpMethod}} {{{path}}}
- *signature:* {{operationId}}(req::HTTP.Request{{#allParams}}{{#required}}, {{paramName}}::{{dataType}}{{/required}}{{/allParams}};{{#allParams}}{{^required}} {{paramName}}=nothing,{{/required}}{{/allParams}}) -> {{#returnType}}{{returnType}}{{/returnType}}{{^returnType}}Nothing{{/returnType}}
- *signature:* {{operationId}}(req::HTTP.Request{{#allParams}}{{#required}}, {{paramName}}::{{#isBinary}}Vector{UInt8}{{/isBinary}}{{^isBinary}}{{dataType}}{{/isBinary}}{{/required}}{{/allParams}};{{#allParams}}{{^required}} {{paramName}}=nothing,{{/required}}{{/allParams}}) -> {{#returnType}}{{returnType}}{{/returnType}}{{^returnType}}Nothing{{/returnType}}
{{/operation}}
{{/operations}}
{{/apis}}
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/julia/docs/FakeApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ test uuid default value
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**_api** | **FakeApi** | API context |
**uuid_parameter** | **String**| test uuid default value | [default to nothing]
**uuid_parameter** | **String** | test uuid default value |

### Return type

Expand Down
26 changes: 13 additions & 13 deletions samples/client/petstore/julia/docs/PetApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Add a new pet to the store
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**_api** | **PetApi** | API context |
**pet** | [**Pet**](Pet.md)| Pet object that needs to be added to the store |
**pet** | [**Pet**](Pet.md) | Pet object that needs to be added to the store |

### Return type

Expand Down Expand Up @@ -57,13 +57,13 @@ Deletes a pet
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**_api** | **PetApi** | API context |
**pet_id** | **Int64**| Pet id to delete | [default to nothing]
**pet_id** | **Int64** | Pet id to delete |

### Optional Parameters

Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**api_key** | **String**| | [default to nothing]
**api_key** | **String** | | [default to nothing]

### Return type

Expand Down Expand Up @@ -93,7 +93,7 @@ Multiple status values can be provided with comma separated strings
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**_api** | **PetApi** | API context |
**status** | [**Vector{String}**](String.md)| Status values that need to be considered for filter | [default to nothing]
**status** | [**Vector{String}**](String.md) | Status values that need to be considered for filter |

### Return type

Expand Down Expand Up @@ -123,7 +123,7 @@ Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**_api** | **PetApi** | API context |
**tags** | [**Vector{String}**](String.md)| Tags to filter by | [default to nothing]
**tags** | [**Vector{String}**](String.md) | Tags to filter by |

### Return type

Expand Down Expand Up @@ -153,7 +153,7 @@ Returns a single pet
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**_api** | **PetApi** | API context |
**pet_id** | **Int64**| ID of pet to return | [default to nothing]
**pet_id** | **Int64** | ID of pet to return |

### Return type

Expand Down Expand Up @@ -183,7 +183,7 @@ Update an existing pet
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**_api** | **PetApi** | API context |
**pet** | [**Pet**](Pet.md)| Pet object that needs to be added to the store |
**pet** | [**Pet**](Pet.md) | Pet object that needs to be added to the store |

### Return type

Expand Down Expand Up @@ -213,14 +213,14 @@ Updates a pet in the store with form data
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**_api** | **PetApi** | API context |
**pet_id** | **Int64**| ID of pet that needs to be updated | [default to nothing]
**pet_id** | **Int64** | ID of pet that needs to be updated |

### Optional Parameters

Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**name** | **String**| Updated name of the pet | [default to nothing]
**status** | **String**| Updated status of the pet | [default to nothing]
**name** | **String** | Updated name of the pet | [default to nothing]
**status** | **String** | Updated status of the pet | [default to nothing]

### Return type

Expand Down Expand Up @@ -250,14 +250,14 @@ uploads an image
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**_api** | **PetApi** | API context |
**pet_id** | **Int64**| ID of pet to update | [default to nothing]
**pet_id** | **Int64** | ID of pet to update |

### Optional Parameters

Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**additional_metadata** | **String**| Additional data to pass to server | [default to nothing]
**file** | **String****String**| file to upload | [default to nothing]
**additional_metadata** | **String** | Additional data to pass to server | [default to nothing]
**file** | **String** | file to upload |

### Return type

Expand Down
6 changes: 3 additions & 3 deletions samples/client/petstore/julia/docs/StoreApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ For valid response try integer IDs with value < 1000. Anything above 1000 or non
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**_api** | **StoreApi** | API context |
**order_id** | **String**| ID of the order that needs to be deleted | [default to nothing]
**order_id** | **String** | ID of the order that needs to be deleted |

### Return type

Expand Down Expand Up @@ -79,7 +79,7 @@ For valid response try integer IDs with value <= 5 or > 10. Other values will ge
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**_api** | **StoreApi** | API context |
**order_id** | **Int64**| ID of pet that needs to be fetched | [default to nothing]
**order_id** | **Int64** | ID of pet that needs to be fetched |

### Return type

Expand Down Expand Up @@ -109,7 +109,7 @@ Place an order for a pet
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**_api** | **StoreApi** | API context |
**order** | [**Order**](Order.md)| order placed for purchasing the pet |
**order** | [**Order**](Order.md) | order placed for purchasing the pet |

### Return type

Expand Down
18 changes: 9 additions & 9 deletions samples/client/petstore/julia/docs/UserApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ This can only be done by the logged in user.
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**_api** | **UserApi** | API context |
**user** | [**User**](User.md)| Created user object |
**user** | [**User**](User.md) | Created user object |

### Return type

Expand Down Expand Up @@ -57,7 +57,7 @@ Creates list of users with given input array
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**_api** | **UserApi** | API context |
**user** | [**Vector{User}**](User.md)| List of user object |
**user** | [**Vector{User}**](User.md) | List of user object |

### Return type

Expand Down Expand Up @@ -87,7 +87,7 @@ Creates list of users with given input array
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**_api** | **UserApi** | API context |
**user** | [**Vector{User}**](User.md)| List of user object |
**user** | [**Vector{User}**](User.md) | List of user object |

### Return type

Expand Down Expand Up @@ -117,7 +117,7 @@ This can only be done by the logged in user.
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**_api** | **UserApi** | API context |
**username** | **String**| The name that needs to be deleted | [default to nothing]
**username** | **String** | The name that needs to be deleted |

### Return type

Expand Down Expand Up @@ -147,7 +147,7 @@ Get user by user name
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**_api** | **UserApi** | API context |
**username** | **String**| The name that needs to be fetched. Use user1 for testing. | [default to nothing]
**username** | **String** | The name that needs to be fetched. Use user1 for testing. |

### Return type

Expand Down Expand Up @@ -177,8 +177,8 @@ Logs user into the system
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**_api** | **UserApi** | API context |
**username** | **String**| The user name for login | [default to nothing]
**password** | **String**| The password for login in clear text | [default to nothing]
**username** | **String** | The user name for login |
**password** | **String** | The password for login in clear text |

### Return type

Expand Down Expand Up @@ -234,8 +234,8 @@ This can only be done by the logged in user.
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**_api** | **UserApi** | API context |
**username** | **String**| name that need to be deleted | [default to nothing]
**user** | [**User**](User.md)| Updated user object |
**username** | **String** | name that need to be deleted |
**user** | [**User**](User.md) | Updated user object |

### Return type

Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/julia/src/apis/api_PetApi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ function _oacinternal_upload_file(_api::PetApi, pet_id::Int64; additional_metada
_ctx = OpenAPI.Clients.Ctx(_api.client, "POST", _returntypes_upload_file_PetApi, "/pet/{petId}/uploadImage", ["petstore_auth", ])
OpenAPI.Clients.set_param(_ctx.path, "petId", pet_id) # type Int64
OpenAPI.Clients.set_param(_ctx.form, "additionalMetadata", additional_metadata) # type String
OpenAPI.Clients.set_param(_ctx.file, "file", file) # type Vector{UInt8}
OpenAPI.Clients.set_param(_ctx.file, "file", file) # type String
OpenAPI.Clients.set_header_accept(_ctx, ["application/json", ])
OpenAPI.Clients.set_header_content_type(_ctx, (_mediaType === nothing) ? ["multipart/form-data", ] : [_mediaType])
return _ctx
Expand Down
2 changes: 1 addition & 1 deletion samples/server/petstore/julia/docs/FakeApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ test uuid default value
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**req** | **HTTP.Request** | The HTTP Request object |
**uuid_parameter** | **String**| test uuid default value | [default to nothing]
**uuid_parameter** | **String**| test uuid default value |

### Return type

Expand Down
Loading

0 comments on commit 1bc5eae

Please sign in to comment.