fix cast exception in uuid default value (julia) (#16438)

This commit is contained in:
William Cheng
2023-08-29 20:42:49 +08:00
committed by GitHub
parent b1564d8002
commit 611a60411b
16 changed files with 220 additions and 7 deletions

View File

@@ -422,7 +422,7 @@ public abstract class AbstractJuliaCodegen extends DefaultCodegen {
} else if (ModelUtils.isIntegerSchema(schema) || ModelUtils.isLongSchema(schema) || ModelUtils.isNumberSchema(schema)) {
return schema.getDefault().toString();
} else if (ModelUtils.isStringSchema(schema)) {
String _default = (String) schema.getDefault();
String _default = String.valueOf(schema.getDefault());
return "\"" + _default + "\"";
}
}

View File

@@ -569,6 +569,26 @@ paths:
description: User not found
security:
- api_key: []
/fake/uuid_default_value_test:
get:
tags:
- fake
summary: test uuid default value
description: test uuid default value
operationId: uuid_default_value
parameters:
- name: uuid_parameter
in: header
description: test uuid default value
required: true
schema:
type: string
format: uuid
responses:
'400':
description: Invalid username supplied
'404':
description: User not found
externalDocs:
description: Find out more about Swagger
url: 'http://swagger.io'
@@ -746,3 +766,7 @@ components:
another_property:
type: integer
format: int32
uuid_default_value:
type: string
format: uuid
default: 1111-2222-3333-4444

View File

@@ -1,6 +1,7 @@
README.md
docs/ApiResponse.md
docs/Category.md
docs/FakeApi.md
docs/MappedModel.md
docs/Order.md
docs/Pet.md
@@ -10,6 +11,7 @@ docs/Tag.md
docs/User.md
docs/UserApi.md
src/OpenAPIGenPetStoreClient.jl
src/apis/api_FakeApi.jl
src/apis/api_PetApi.jl
src/apis/api_StoreApi.jl
src/apis/api_UserApi.jl

View File

@@ -20,6 +20,7 @@ Documentation is also embedded in Julia which can be used with a Julia specific
Class | Method
------------ | -------------
*FakeApi* | [**uuid_default_value**](docs/FakeApi.md#uuid_default_value)<br/>**GET** /fake/uuid_default_value_test<br/>test uuid default value
*PetApi* | [**add_pet**](docs/PetApi.md#add_pet)<br/>**POST** /pet<br/>Add a new pet to the store
*PetApi* | [**delete_pet**](docs/PetApi.md#delete_pet)<br/>**DELETE** /pet/{petId}<br/>Deletes a pet
*PetApi* | [**find_pets_by_status**](docs/PetApi.md#find_pets_by_status)<br/>**GET** /pet/findByStatus<br/>Finds Pets by status

View File

@@ -0,0 +1,39 @@
# FakeApi
All URIs are relative to *http://petstore.swagger.io/v2*
Method | HTTP request | Description
------------- | ------------- | -------------
[**uuid_default_value**](FakeApi.md#uuid_default_value) | **GET** /fake/uuid_default_value_test | test uuid default value
# **uuid_default_value**
> uuid_default_value(_api::FakeApi, uuid_parameter::String; _mediaType=nothing) -> Nothing, OpenAPI.Clients.ApiResponse <br/>
> uuid_default_value(_api::FakeApi, response_stream::Channel, uuid_parameter::String; _mediaType=nothing) -> Channel{ Nothing }, OpenAPI.Clients.ApiResponse
test uuid default value
test uuid default value
### Required Parameters
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**_api** | **FakeApi** | API context |
**uuid_parameter** | **String**| test uuid default value | [default to nothing]
### Return type
Nothing
### Authorization
No authorization required
### HTTP request headers
- **Content-Type**: Not defined
- **Accept**: Not defined
[[Back to top]](#) [[Back to API list]](../README.md#api-endpoints) [[Back to Model list]](../README.md#models) [[Back to README]](../README.md)

View File

@@ -5,6 +5,7 @@
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**mappedProperty** | **Int64** | | [optional] [default to nothing]
**uuid_default_value** | **String** | | [optional] [default to nothing]
[[Back to Model list]](../README.md#models) [[Back to API list]](../README.md#api-endpoints) [[Back to README]](../README.md)

View File

@@ -11,6 +11,7 @@ const API_VERSION = "1.0.0"
include("modelincludes.jl")
include("apis/api_FakeApi.jl")
include("apis/api_PetApi.jl")
include("apis/api_StoreApi.jl")
include("apis/api_UserApi.jl")
@@ -25,6 +26,7 @@ export Tag
export User
# export operations
export FakeApi
export PetApi
export StoreApi
export UserApi

View File

@@ -0,0 +1,46 @@
# This file was generated by the Julia OpenAPI Code Generator
# Do not modify this file directly. Modify the OpenAPI specification instead.
struct FakeApi <: OpenAPI.APIClientImpl
client::OpenAPI.Clients.Client
end
"""
The default API base path for APIs in `FakeApi`.
This can be used to construct the `OpenAPI.Clients.Client` instance.
"""
basepath(::Type{ FakeApi }) = "http://petstore.swagger.io/v2"
const _returntypes_uuid_default_value_FakeApi = Dict{Regex,Type}(
Regex("^" * replace("400", "x"=>".") * "\$") => Nothing,
Regex("^" * replace("404", "x"=>".") * "\$") => Nothing,
)
function _oacinternal_uuid_default_value(_api::FakeApi, uuid_parameter::String; _mediaType=nothing)
_ctx = OpenAPI.Clients.Ctx(_api.client, "GET", _returntypes_uuid_default_value_FakeApi, "/fake/uuid_default_value_test", [])
OpenAPI.Clients.set_param(_ctx.header, "uuid_parameter", uuid_parameter) # type String
OpenAPI.Clients.set_header_accept(_ctx, [])
OpenAPI.Clients.set_header_content_type(_ctx, (_mediaType === nothing) ? [] : [_mediaType])
return _ctx
end
@doc raw"""test uuid default value
test uuid default value
Params:
- uuid_parameter::String (required)
Return: Nothing, OpenAPI.Clients.ApiResponse
"""
function uuid_default_value(_api::FakeApi, uuid_parameter::String; _mediaType=nothing)
_ctx = _oacinternal_uuid_default_value(_api, uuid_parameter; _mediaType=_mediaType)
return OpenAPI.Clients.exec(_ctx)
end
function uuid_default_value(_api::FakeApi, response_stream::Channel, uuid_parameter::String; _mediaType=nothing)
_ctx = _oacinternal_uuid_default_value(_api, uuid_parameter; _mediaType=_mediaType)
return OpenAPI.Clients.exec(_ctx, response_stream)
end
export uuid_default_value

View File

@@ -7,20 +7,24 @@ to test mapping features
MappedModel(;
mappedProperty=nothing,
uuid_default_value=nothing,
)
- mappedProperty::Int64
- uuid_default_value::String
"""
Base.@kwdef mutable struct MappedModel <: OpenAPI.APIModel
mappedProperty::Union{Nothing, Int64} = nothing
uuid_default_value::Union{Nothing, String} = nothing
function MappedModel(mappedProperty, )
function MappedModel(mappedProperty, uuid_default_value, )
OpenAPI.validate_property(MappedModel, Symbol("another_property"), mappedProperty)
return new(mappedProperty, )
OpenAPI.validate_property(MappedModel, Symbol("uuid_default_value"), uuid_default_value)
return new(mappedProperty, uuid_default_value, )
end
end # type MappedModel
const _property_types_MappedModel = Dict{Symbol,String}(Symbol("another_property")=>"Int64", )
const _property_types_MappedModel = Dict{Symbol,String}(Symbol("another_property")=>"Int64", Symbol("uuid_default_value")=>"String", )
OpenAPI.property_type(::Type{ MappedModel }, name::Symbol) = Union{Nothing,eval(Base.Meta.parse(_property_types_MappedModel[name]))}
function check_required(o::MappedModel)
@@ -31,4 +35,7 @@ function OpenAPI.validate_property(::Type{ MappedModel }, name::Symbol, val)
if name === Symbol("another_property")
OpenAPI.validate_param(name, "MappedModel", :format, val, "int32")
end
if name === Symbol("uuid_default_value")
OpenAPI.validate_param(name, "MappedModel", :format, val, "uuid")
end
end

View File

@@ -2,6 +2,7 @@ README.md
docs/AnotherModel.md
docs/ApiResponse.md
docs/Category.md
docs/FakeApi.md
docs/Order.md
docs/Pet.md
docs/PetApi.md
@@ -10,6 +11,7 @@ docs/Tag.md
docs/User.md
docs/UserApi.md
src/OpenAPIGenPetStoreServer.jl
src/apis/api_FakeApi.jl
src/apis/api_PetApi.jl
src/apis/api_StoreApi.jl
src/apis/api_UserApi.jl

View File

@@ -41,6 +41,7 @@ The following server methods must be implemented:
Class | Method | HTTP request | Description
------------ | ------------- | ------------- | -------------
*FakeApi* | [**uuid_default_value**](docs/FakeApi.md#uuid_default_value) | **GET** /fake/uuid_default_value_test | test uuid default value
*PetApi* | [**add_pet**](docs/PetApi.md#add_pet) | **POST** /pet | Add a new pet to the store
*PetApi* | [**delete_pet**](docs/PetApi.md#delete_pet) | **DELETE** /pet/{petId} | Deletes a pet
*PetApi* | [**find_pets_by_status**](docs/PetApi.md#find_pets_by_status) | **GET** /pet/findByStatus | Finds Pets by status

View File

@@ -5,6 +5,7 @@
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**another_property** | **Int64** | | [optional] [default to nothing]
**uuid_default_value** | **String** | | [optional] [default to nothing]
[[Back to Model list]](../README.md#models) [[Back to API list]](../README.md#api-endpoints) [[Back to README]](../README.md)

View File

@@ -0,0 +1,38 @@
# FakeApi
All URIs are relative to *http://petstore.swagger.io/v2*
Method | HTTP request | Description
------------- | ------------- | -------------
[**uuid_default_value**](FakeApi.md#uuid_default_value) | **GET** /fake/uuid_default_value_test | test uuid default value
# **uuid_default_value**
> uuid_default_value(req::HTTP.Request, uuid_parameter::String;) -> Nothing
test uuid default value
test uuid default value
### Required Parameters
Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**req** | **HTTP.Request** | The HTTP Request object |
**uuid_parameter** | **String**| test uuid default value | [default to nothing]
### Return type
Nothing
### Authorization
No authorization required
### HTTP request headers
- **Content-Type**: Not defined
- **Accept**: Not defined
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)

View File

@@ -7,6 +7,9 @@ Encapsulates generated server code for OpenAPIGenPetStoreServer
The following server methods must be implemented:
- **uuid_default_value**
- *invocation:* GET /fake/uuid_default_value_test
- *signature:* uuid_default_value(req::HTTP.Request, uuid_parameter::String;) -> Nothing
- **add_pet**
- *invocation:* POST /pet
- *signature:* add_pet(req::HTTP.Request, pet::Pet;) -> Pet
@@ -81,6 +84,7 @@ const API_VERSION = "1.0.0"
include("modelincludes.jl")
include("apis/api_FakeApi.jl")
include("apis/api_PetApi.jl")
include("apis/api_StoreApi.jl")
include("apis/api_UserApi.jl")
@@ -106,6 +110,7 @@ The order in which middlewares are invoked are:
`init |> read |> pre_validation |> validate |> pre_invoke |> invoke |> post_invoke`
"""
function register(router::HTTP.Router, impl; path_prefix::String="", optional_middlewares...)
registerFakeApi(router, impl; path_prefix=path_prefix, optional_middlewares...)
registerPetApi(router, impl; path_prefix=path_prefix, optional_middlewares...)
registerStoreApi(router, impl; path_prefix=path_prefix, optional_middlewares...)
registerUserApi(router, impl; path_prefix=path_prefix, optional_middlewares...)

View File

@@ -0,0 +1,37 @@
# This file was generated by the Julia OpenAPI Code Generator
# Do not modify this file directly. Modify the OpenAPI specification instead.
function uuid_default_value_read(handler)
function uuid_default_value_read_handler(req::HTTP.Request)
openapi_params = Dict{String,Any}()
headers = Dict{String,String}(HTTP.headers(req))
openapi_params["uuid_parameter"] = OpenAPI.Servers.to_param(String, headers, "uuid_parameter", required=true, )
req.context[:openapi_params] = openapi_params
return handler(req)
end
end
function uuid_default_value_validate(handler)
function uuid_default_value_validate_handler(req::HTTP.Request)
openapi_params = req.context[:openapi_params]
return handler(req)
end
end
function uuid_default_value_invoke(impl; post_invoke=nothing)
function uuid_default_value_invoke_handler(req::HTTP.Request)
openapi_params = req.context[:openapi_params]
ret = impl.uuid_default_value(req::HTTP.Request, openapi_params["uuid_parameter"];)
resp = OpenAPI.Servers.server_response(ret)
return (post_invoke === nothing) ? resp : post_invoke(req, resp)
end
end
function registerFakeApi(router::HTTP.Router, impl; path_prefix::String="", optional_middlewares...)
HTTP.register!(router, "GET", path_prefix * "/fake/uuid_default_value_test", OpenAPI.Servers.middleware(impl, uuid_default_value_read, uuid_default_value_validate, uuid_default_value_invoke; optional_middlewares...))
return router
end

View File

@@ -7,20 +7,24 @@ to test mapping features
AnotherModel(;
another_property=nothing,
uuid_default_value=nothing,
)
- another_property::Int64
- uuid_default_value::String
"""
Base.@kwdef mutable struct AnotherModel <: OpenAPI.APIModel
another_property::Union{Nothing, Int64} = nothing
uuid_default_value::Union{Nothing, String} = nothing
function AnotherModel(another_property, )
function AnotherModel(another_property, uuid_default_value, )
OpenAPI.validate_property(AnotherModel, Symbol("another_property"), another_property)
return new(another_property, )
OpenAPI.validate_property(AnotherModel, Symbol("uuid_default_value"), uuid_default_value)
return new(another_property, uuid_default_value, )
end
end # type AnotherModel
const _property_types_AnotherModel = Dict{Symbol,String}(Symbol("another_property")=>"Int64", )
const _property_types_AnotherModel = Dict{Symbol,String}(Symbol("another_property")=>"Int64", Symbol("uuid_default_value")=>"String", )
OpenAPI.property_type(::Type{ AnotherModel }, name::Symbol) = Union{Nothing,eval(Base.Meta.parse(_property_types_AnotherModel[name]))}
function check_required(o::AnotherModel)
@@ -31,4 +35,7 @@ function OpenAPI.validate_property(::Type{ AnotherModel }, name::Symbol, val)
if name === Symbol("another_property")
OpenAPI.validate_param(name, "AnotherModel", :format, val, "int32")
end
if name === Symbol("uuid_default_value")
OpenAPI.validate_param(name, "AnotherModel", :format, val, "uuid")
end
end