Skip to content

Commit

Permalink
[julia] fix enum default vals, add api validations
Browse files Browse the repository at this point in the history
- Fix enum default value generation. Default values were falling back to the default code generator and were being generated improperly for Julia.
- Add more validations to client and server API call handlers. These validations were already being generated for models, but were missed out for API calls.
  • Loading branch information
tanmaykm committed Jan 22, 2025
1 parent bc70f04 commit b046d58
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,18 @@ public String toDefaultValue(Schema schema) {
return "nothing";
}

@Override
public String toEnumDefaultValue(String value, String datatype) {
// we do not generate any separate enum structure in Julia
return value;
}

@Override
public String toEnumVarName(String value, String datatype) {
// we do not generate any separate enum structure in Julia
return value;
}

@Override
public String escapeUnsafeCharacters(String input) {
return input.replace("#=", "#_=").replace("=#", "=_#");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,21 @@ function _oacinternal_{{operationId}}(_api::{{classname}}{{#allParams}}{{#requir
{{#minItems}}
OpenAPI.validate_param("{{paramName}}", "{{operationId}}", :minItems, {{paramName}}, {{minItems}})
{{/minItems}}
{{#uniqueItems}}
OpenAPI.validate_param("{{paramName}}", "{{operationId}}", :uniqueItems, {{paramName}}, {{uniqueItems}})
{{/uniqueItems}}
{{#maxProperties}}
OpenAPI.validate_param("{{paramName}}", "{{operationId}}", :maxProperties, {{paramName}}, {{maxProperties}})
{{/maxProperties}}
{{#minProperties}}
OpenAPI.validate_param("{{paramName}}", "{{operationId}}", :minProperties, {{paramName}}, {{minProperties}})
{{/minProperties}}
{{#pattern}}
OpenAPI.validate_param("{{paramName}}", "{{operationId}}", :pattern, {{paramName}}, r"{{{pattern}}}")
{{/pattern}}
{{#multipleOf}}
OpenAPI.validate_param("{{paramName}}", "{{operationId}}", :multipleOf, {{paramName}}, {{multipleOf}})
{{/multipleOf}}

{{/hasValidation}}
{{/allParams}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,21 @@ function {{operationId}}_validate(handler)
{{#minItems}}
OpenAPI.validate_param("{{#lambda.escapeDollar}}{{baseName}}{{/lambda.escapeDollar}}", "{{operationId}}", :minItems, openapi_params["{{#lambda.escapeDollar}}{{baseName}}{{/lambda.escapeDollar}}"], {{minItems}})
{{/minItems}}
{{#uniqueItems}}
OpenAPI.validate_param("{{#lambda.escapeDollar}}{{baseName}}{{/lambda.escapeDollar}}", "{{operationId}}", :uniqueItems, openapi_params["{{#lambda.escapeDollar}}{{baseName}}{{/lambda.escapeDollar}}"], {{uniqueItems}})
{{/uniqueItems}}
{{#maxProperties}}
OpenAPI.validate_param("{{#lambda.escapeDollar}}{{baseName}}{{/lambda.escapeDollar}}", "{{operationId}}", :maxProperties, openapi_params["{{#lambda.escapeDollar}}{{baseName}}{{/lambda.escapeDollar}}"], {{maxProperties}})
{{/maxProperties}}
{{#minProperties}}
OpenAPI.validate_param("{{#lambda.escapeDollar}}{{baseName}}{{/lambda.escapeDollar}}", "{{operationId}}", :minProperties, openapi_params["{{#lambda.escapeDollar}}{{baseName}}{{/lambda.escapeDollar}}"], {{minProperties}})
{{/minProperties}}
{{#pattern}}
OpenAPI.validate_param("{{#lambda.escapeDollar}}{{baseName}}{{/lambda.escapeDollar}}", "{{operationId}}", :pattern, openapi_params["{{#lambda.escapeDollar}}{{baseName}}{{/lambda.escapeDollar}}"], r"{{{pattern}}}")
{{/pattern}}
{{#multipleOf}}
OpenAPI.validate_param("{{#lambda.escapeDollar}}{{baseName}}{{/lambda.escapeDollar}}", "{{operationId}}", :multipleOf, openapi_params["{{#lambda.escapeDollar}}{{baseName}}{{/lambda.escapeDollar}}"], {{multipleOf}})
{{/multipleOf}}
{{/hasValidation}}{{/allParams}}
return handler(req)
end
Expand Down
1 change: 1 addition & 0 deletions samples/client/petstore/julia/src/apis/api_UserApi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ const _returntypes_login_user_UserApi = Dict{Regex,Type}(
)

function _oacinternal_login_user(_api::UserApi, username::String, password::String; _mediaType=nothing)
OpenAPI.validate_param("username", "login_user", :pattern, username, r"^[a-zA-Z0-9]+[a-zA-Z0-9\.\-_]*[a-zA-Z0-9]+$")

_ctx = OpenAPI.Clients.Ctx(_api.client, "GET", _returntypes_login_user_UserApi, "/user/login", [])
OpenAPI.Clients.set_param(_ctx.query, "username", username; style="form", is_explode=true) # type String
Expand Down
1 change: 1 addition & 0 deletions samples/server/petstore/julia/src/apis/api_UserApi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ function login_user_validate(handler)
function login_user_validate_handler(req::HTTP.Request)
openapi_params = req.context[:openapi_params]

OpenAPI.validate_param("username", "login_user", :pattern, openapi_params["username"], r"^[a-zA-Z0-9]+[a-zA-Z0-9\.\-_]*[a-zA-Z0-9]+$")

return handler(req)
end
Expand Down

0 comments on commit b046d58

Please sign in to comment.