Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
51b7581
style(crystal): fix coding style
n-rodriguez Dec 22, 2025
e3c8012
fix(crystal): object_id is so central in Crystal that it should not b…
n-rodriguez Dec 22, 2025
89e8f32
style(crystal): fix coding style
n-rodriguez Dec 23, 2025
ab689e0
fix(crystal): fix partial_oneof_module by using a class instead of a …
n-rodriguez Dec 23, 2025
840f769
fix(crystal): remove non-working code
n-rodriguez Dec 23, 2025
4f71fb0
fix(crystal): update reserved words, separate reserved keywords from …
n-rodriguez Dec 23, 2025
c54d72a
fix(crystal): update samples
n-rodriguez Dec 23, 2025
9d4abe3
fix(crystal): set default values when options are not passed
n-rodriguez Dec 23, 2025
dad9b16
fix(crystal): follow up https://github.com/OpenAPITools/openapi-gener…
n-rodriguez Dec 23, 2025
a630c10
fix(crystal): remove travis.yml file
n-rodriguez Dec 23, 2025
221f862
style(crystal): fix coding style
n-rodriguez Dec 23, 2025
66a4ee2
style(crystal): use kwargs when calling @api_client
n-rodriguez Dec 23, 2025
7638e61
style(crystal): use kwargs when calling Crest::Request.new
n-rodriguez Dec 23, 2025
6f01c8b
fix(crystal): remove useless return_type argument
n-rodriguez Dec 23, 2025
0102edf
fix(crystal): map object type to JSON::Any type
n-rodriguez Dec 24, 2025
594c604
fix(crystal): reduce use of require
n-rodriguez Dec 24, 2025
7656747
fix(crystal): return early if value is nil
n-rodriguez Dec 24, 2025
b72b957
fix(crystal): update doc
n-rodriguez Dec 24, 2025
024d3f3
fix(crystal): remove dead code
n-rodriguez Dec 25, 2025
d4a4d8f
fix(crystal): kemal is not used in specs
n-rodriguez Dec 25, 2025
c5e8303
fix(crystal): class name should be in PascalCase
n-rodriguez Dec 25, 2025
5ad006e
fix(crystal): fix ameba warnings
n-rodriguez Dec 25, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs/generators/crystal.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,19 @@ These options may be applied as additional-properties (cli) or configOptions (pl
<li>if</li>
<li>in</li>
<li>include</li>
<li>instance</li>
<li>instance_sizeof</li>
<li>is_a?</li>
<li>lib</li>
<li>macro</li>
<li>module</li>
<li>next</li>
<li>nil</li>
<li>nil?</li>
<li>object_id</li>
<li>of</li>
<li>out</li>
<li>pointerof</li>
<li>previous_def</li>
<li>private</li>
<li>protected</li>
<li>require</li>
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.openapitools.codegen.templating.mustache;

import com.samskivert.mustache.Mustache;
import com.samskivert.mustache.Template;
import org.openapitools.codegen.utils.CamelizeOption;

import java.io.IOException;
import java.io.Writer;

import static org.openapitools.codegen.utils.StringUtils.camelize;

/**
* Converts text in a fragment to PascalCase.
* <p>
* Register:
* <pre>
* additionalProperties.put("pascalcase", new PascalCaseLambda());
* </pre>
* <p>
* Use:
* <pre>
* {{#pascalcase}}{{name}}{{/pascalcase}}
* </pre>
*/
public class PascalCaseLambda implements Mustache.Lambda {
public PascalCaseLambda() {
}

@Override
public void execute(Template.Fragment fragment, Writer writer) throws IOException {
String text = fragment.execute();
text = camelize(text);
writer.write(text);
}
}
26 changes: 13 additions & 13 deletions modules/openapi-generator/src/main/resources/crystal/api.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -159,25 +159,25 @@ module {{moduleName}}
# http body (model)
post_body = {{#bodyParam}}{{{paramName}}}.to_json{{/bodyParam}}{{^bodyParam}}nil{{/bodyParam}}

# return_type
return_type = {{#returnType}}"{{{.}}}"{{/returnType}}{{^returnType}}nil{{/returnType}}

# auth_names
auth_names = {{#authMethods}}{{#-first}}[{{/-first}}"{{name}}"{{^-last}}, {{/-last}}{{#-last}}]{{/-last}}{{/authMethods}}{{^authMethods}}[] of String{{/authMethods}}

data, status_code, headers = @api_client.call_api(:{{httpMethod}},
local_var_path,
:"{{classname}}.{{operationId}}",
return_type,
post_body,
auth_names,
header_params,
query_params,
cookie_params,
form_params)
data, status_code, headers = @api_client.call_api(
http_method: :{{httpMethod}},
path: local_var_path,
operation: :"{{classname}}.{{operationId}}",
post_body: post_body,
auth_names: auth_names,
header_params: header_params,
query_params: query_params,
cookie_params: cookie_params,
form_params: form_params
)

if @api_client.config.debugging
Log.debug {"API called: {{classname}}#{{operationId}}\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"}
end

return {{#returnType}}{{{.}}}.from_json(data){{/returnType}}{{^returnType}}nil{{/returnType}}, status_code, headers
end
{{^-last}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ module {{moduleName}}
#
# @return [Array<(Object, Integer, Hash)>] an array of 3 elements:
# the data deserialized from response body (could be nil), response status code and response headers.
def call_api(http_method : Symbol, path : String, operation : Symbol, return_type : String?, post_body : String?, auth_names = [] of String, header_params = {} of String => String, query_params = {} of String => String, cookie_params = {} of String => String, form_params = {} of Symbol => (String | ::File))
def call_api(http_method : Symbol, path : String, operation : Symbol, post_body : String?, auth_names = [] of String, header_params = {} of String => String, query_params = {} of String => String, cookie_params = {} of String => String, form_params = {} of Symbol => (String | ::File))
#ssl_options = {
# :ca_file => @config.ssl_ca_file,
# :verify => @config.ssl_verify,
Expand All @@ -139,8 +139,9 @@ module {{moduleName}}
form_or_body = form_params
end

request = Crest::Request.new(http_method,
build_request_url(path, operation),
request = Crest::Request.new(
method: http_method,
url: build_request_url(path, operation),
params: query_params,
headers: header_params,
cookies: cookie_params,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,78 +1,3 @@
# Builds the object from hash
# @param [Hash] attributes Model attributes in the form of hash
# @return [Object] Returns the model itself
def self.build_from_hash(attributes)
new.build_from_hash(attributes)
end

# Builds the object from hash
# @param [Hash] attributes Model attributes in the form of hash
# @return [Object] Returns the model itself
def build_from_hash(attributes)
return nil unless attributes.is_a?(Hash)
{{#parent}}
super(attributes)
{{/parent}}
self.class.openapi_types.each_pair do |key, type|
if !attributes[self.class.attribute_map[key]]? && self.class.openapi_nullable.includes?(key)
self.send("#{key}=", nil)
elsif type =~ /\AArray<(.*)>/i
# check to ensure the input is an array given that the attribute
# is documented as an array but the input is not
if attributes[self.class.attribute_map[key]].is_a?(Array)
self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
end
elsif !attributes[self.class.attribute_map[key]].nil?
self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
end
end

self
end

# Deserializes the data based on type
# @param string type Data type
# @param string value Value to be deserialized
# @return [Object] Deserialized data
def _deserialize(type, value)
case type.to_sym
when :Time
Time.parse(value)
when :Date
Date.parse(value)
when :String
value.to_s
when :Integer
value.to_i
when :Float
value.to_f
when :Boolean
if value.to_s =~ /\A(true|t|yes|y|1)\z/i
true
else
false
end
when :Object
# generic object (usually a Hash), return directly
value
when /\AArray<(?<inner_type>.+)>\z/
inner_type = Regexp.last_match[:inner_type]
value.map { |v| _deserialize(inner_type, v) }
when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
k_type = Regexp.last_match[:k_type]
v_type = Regexp.last_match[:v_type]
({} of Symbol => String).tap do |hash|
value.each do |k, v|
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
end
end
else # model
# models (e.g. Pet) or oneOf
klass = {{moduleName}}.const_get(type)
klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
end
end

# Returns the string representation of the object
# @return [String] String presentation of the object
def to_s
Expand Down Expand Up @@ -100,6 +25,8 @@
# @param [Object] value Any valid value
# @return [Hash] Returns the value in the form of hash
private def _to_h(value)
return nil if value.nil?

if value.is_a?(Hash)
hash = NetboxClient::RecursiveHash.new
value.each { |k, v| hash[k] = _to_h(v) }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
# {{#lambdaPrefixWithHash}}{{> api_info}}{{/lambdaPrefixWithHash}}

require "big"
require "json"
require "yaml"
require "time"

module {{moduleName}}
{{#models}}
{{#model}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
{{#vars}}
{{#isEnum}}
{{^isContainer}}
class EnumAttributeValidatorFor{{#lambdaTitlecase}}{{{name}}}{{/lambdaTitlecase}} < EnumAttributeValidator
class EnumAttributeValidatorFor{{#lambdaPascalcase}}{{{name}}}{{/lambdaPascalcase}} < EnumAttributeValidator
@attribute : String
@allowable_values : Array(Int32 | Int64 | Float32 | Float64 | String)

Expand Down Expand Up @@ -118,7 +118,7 @@
{{#vars}}
{{#isEnum}}
{{^isContainer}}
{{{name}}}_validator = EnumAttributeValidatorFor{{#lambdaTitlecase}}{{{name}}}{{/lambdaTitlecase}}.new
{{{name}}}_validator = EnumAttributeValidatorFor{{#lambdaPascalcase}}{{{name}}}{{/lambdaPascalcase}}.new
if !{{{name}}}_validator.valid?(@{{{name}}})
message = {{{name}}}_validator.message
invalid_properties.push(message)
Expand Down Expand Up @@ -181,7 +181,7 @@
{{#vars}}
{{#isEnum}}
{{^isContainer}}
{{{name}}}_validator = EnumAttributeValidatorFor{{#lambdaTitlecase}}{{{name}}}{{/lambdaTitlecase}}.new
{{{name}}}_validator = EnumAttributeValidatorFor{{#lambdaPascalcase}}{{{name}}}{{/lambdaPascalcase}}.new
return false unless {{{name}}}_validator.valid?(@{{{name}}})
{{/isContainer}}
{{/isEnum}}
Expand Down Expand Up @@ -234,7 +234,7 @@
# Custom attribute writer method checking allowed values (enum).
# @param [Object] {{{name}}} Object to be assigned
def {{{name}}}=({{{name}}})
validator = EnumAttributeValidatorFor{{#lambdaTitlecase}}{{{name}}}{{/lambdaTitlecase}}.new
validator = EnumAttributeValidatorFor{{#lambdaPascalcase}}{{{name}}}{{/lambdaPascalcase}}.new
unless validator.valid?({{{name}}})
raise ArgumentError.new(validator.message)
end
Expand Down
Loading
Loading