From b046d58ce2392f870c88ff01aff964cc383b7bf7 Mon Sep 17 00:00:00 2001 From: tan Date: Wed, 22 Jan 2025 13:56:31 +0530 Subject: [PATCH] [julia] fix enum default vals, add api validations - 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. --- .../codegen/languages/AbstractJuliaCodegen.java | 12 ++++++++++++ .../src/main/resources/julia-client/api.mustache | 15 +++++++++++++++ .../src/main/resources/julia-server/api.mustache | 15 +++++++++++++++ .../client/petstore/julia/src/apis/api_UserApi.jl | 1 + .../server/petstore/julia/src/apis/api_UserApi.jl | 1 + 5 files changed, 44 insertions(+) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJuliaCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJuliaCodegen.java index b8a628ed5271..faed1d91c8ef 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJuliaCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJuliaCodegen.java @@ -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("=#", "=_#"); diff --git a/modules/openapi-generator/src/main/resources/julia-client/api.mustache b/modules/openapi-generator/src/main/resources/julia-client/api.mustache index 045543bedc1a..2e6741227240 100644 --- a/modules/openapi-generator/src/main/resources/julia-client/api.mustache +++ b/modules/openapi-generator/src/main/resources/julia-client/api.mustache @@ -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}} diff --git a/modules/openapi-generator/src/main/resources/julia-server/api.mustache b/modules/openapi-generator/src/main/resources/julia-server/api.mustache index 89ef0cca2c10..e007ad919026 100644 --- a/modules/openapi-generator/src/main/resources/julia-server/api.mustache +++ b/modules/openapi-generator/src/main/resources/julia-server/api.mustache @@ -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 diff --git a/samples/client/petstore/julia/src/apis/api_UserApi.jl b/samples/client/petstore/julia/src/apis/api_UserApi.jl index 89ed37ed772a..893a30b7cdd9 100644 --- a/samples/client/petstore/julia/src/apis/api_UserApi.jl +++ b/samples/client/petstore/julia/src/apis/api_UserApi.jl @@ -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 diff --git a/samples/server/petstore/julia/src/apis/api_UserApi.jl b/samples/server/petstore/julia/src/apis/api_UserApi.jl index 5f2f35210ca0..d0bdcf033bca 100644 --- a/samples/server/petstore/julia/src/apis/api_UserApi.jl +++ b/samples/server/petstore/julia/src/apis/api_UserApi.jl @@ -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