Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 7 additions & 9 deletions codegen/generators/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,25 +105,23 @@ def property_type_from_ref(ref)
class_name(ref)
end

def property_type_from_type(parent_type_name, property_name, property, type:)
def property_type_from_type(parent_type_name, property_name, property)
type = property['type']
return array_type_for(type_for(parent_type_name, nil, property['items'])) if type == 'array'
return property_type_from_enum(enum_name(parent_type_name, property_name, property['enum'])) if property['enum']

unless language_translations_for_data_types.key?(type)
property = select_language_translations_for_data_types(type, property)
unless property
raise "No type mapping for JSONSchema type #{type}. Schema:\n#{JSON.pretty_generate(property)}"
end

if property['enum']
property_type_from_enum(enum_name(parent_type_name, property_name, property['enum']))
else
language_translations_for_data_types.fetch(type)
end
property
end

def type_for(parent_type_name, property_name, property)
if property['$ref']
property_type_from_ref(property['$ref'])
elsif property['type']
property_type_from_type(parent_type_name, property_name, property, type: property['type'])
property_type_from_type(parent_type_name, property_name, property)
else
# Inline schema (not supported)
raise "Property #{property_name} did not define 'type' or '$ref'"
Expand Down
4 changes: 2 additions & 2 deletions codegen/generators/cpp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ def format_description(raw_description, indent_string: '')

private

def language_translations_for_data_types
def select_language_translations_for_data_types(type, property)
{
'integer' => 'std::size_t',
'string' => 'std::string',
'boolean' => 'bool'
}
}[type]
end
end
end
4 changes: 2 additions & 2 deletions codegen/generators/dotnet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ def format_description(raw_description, indent_string: '')

private

def language_translations_for_data_types
def select_language_translations_for_data_types(type, property)
{
'integer' => 'long',
'string' => 'string',
'boolean' => 'bool'
}
}[type]
end
end
end
4 changes: 2 additions & 2 deletions codegen/generators/go.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ def property_type_from_ref(ref)

private

def language_translations_for_data_types
def select_language_translations_for_data_types(type, property)
{
'integer' => 'int64',
'string' => 'string',
'boolean' => 'bool'
}
}[type]
end
end
end
22 changes: 15 additions & 7 deletions codegen/generators/java.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Generator
# Automatic Code generation overrides for the Java programming language
class Java < Base
def array_type_for(type_name)
"java.util.List<#{type_name}>"
"List<#{type_name}>"
end

def format_description(raw_description, indent_string: '')
Expand All @@ -23,12 +23,20 @@ def format_description(raw_description, indent_string: '')

private

def language_translations_for_data_types
{
'integer' => 'Long',
'string' => 'String',
'boolean' => 'Boolean'
}
def select_language_translations_for_data_types(type, property)
if type == 'integer'
if property['maximum'] and property['maximum'] <= 2147483647
'Integer'
else
'Long'
end
elsif type == 'string'
'String'
elsif type == 'boolean'
'Boolean'
else
nil
end
end
end
end
4 changes: 2 additions & 2 deletions codegen/generators/markdown.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ def property_type_from_ref(ref)

private

def language_translations_for_data_types
def select_language_translations_for_data_types(type, property)
{
'integer' => 'integer',
'string' => 'string',
'boolean' => 'boolean'
}
}[type]
end
end
end
4 changes: 2 additions & 2 deletions codegen/generators/perl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ def default_value_for_string(property_name, enum)
end
end

def language_translations_for_data_types
def select_language_translations_for_data_types(type, property)
{
'integer' => 'number',
'string' => 'string',
'boolean' => 'boolean'
}
}[type]
end
end
end
8 changes: 4 additions & 4 deletions codegen/generators/php.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ def nullable?(property_name, schema)
end

def scalar?(property)
property.key?('type') && language_translations_for_data_types.key?(property['type'])
property.key?('type') && select_language_translations_for_data_types(property['type'], property)
end

def scalar_type_for(property)
language_translations_for_data_types[property['type']]
select_language_translations_for_data_types(property['type'], property)
end

private
Expand All @@ -68,12 +68,12 @@ def default_value(class_name, property_name, property, schema)
super(class_name, property_name, property)
end

def language_translations_for_data_types
def select_language_translations_for_data_types(type, property)
{
'string' => 'string',
'integer' => 'int',
'boolean' => 'bool'
}
}[type]
end

def non_nullable_non_scalar_constructor(parent_type, property, property_name, schema, source)
Expand Down
14 changes: 7 additions & 7 deletions codegen/generators/python.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ def format_description(raw_description, indent_string: ' ')
%("""\n#{lines.join("\n")}\n#{indent_string}""")
end

def select_language_translations_for_data_types(type, property)
language_translations_for_data_types[type]
end

private

def language_translations_for_data_types
{
'integer' => 'int',
Expand All @@ -71,9 +77,7 @@ def language_translations_for_data_types
'array' => 'list'
}
end

private


def default_value(parent_type_name, property_name, property)
if property['type'] == 'string'
default_value_for_string(parent_type_name, property_name, property)
Expand Down Expand Up @@ -109,10 +113,6 @@ def enum_name(parent_type_name, property_name, enum)
end
end

def property_type_from_ref(ref)
class_name(ref)
end

def class_name(ref)
return ref if language_translations_for_data_types.values.include?(ref)

Expand Down
4 changes: 2 additions & 2 deletions codegen/generators/ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ def default_value_for_string(parent_type_name, property_name, property)
end
end

def language_translations_for_data_types
def select_language_translations_for_data_types(type, property)
{
'integer' => 'number',
'string' => 'string',
'boolean' => 'boolean'
}
}[type]
end

def line_as_comment(line)
Expand Down
4 changes: 2 additions & 2 deletions codegen/generators/typescript.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ def array_type_for(type_name)

private

def language_translations_for_data_types
def select_language_translations_for_data_types(type, property)
{
'integer' => 'number',
'string' => 'string',
'boolean' => 'boolean'
}
}[type]
end
end
end
27 changes: 16 additions & 11 deletions codegen/templates/java.java.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
<%= class_name(key) %>.java
package io.cucumber.messages.types;

import java.util.ArrayList;
import org.jspecify.annotations.Nullable;

import java.util.List;
import java.util.Objects;
import java.util.Optional;

import static java.util.Collections.unmodifiableList;
import static java.util.Objects.requireNonNull;

/**
Expand All @@ -17,10 +18,12 @@ import static java.util.Objects.requireNonNull;
<%- end -%>
*/
// Generated code
@SuppressWarnings("unused")
@SuppressWarnings({"unused", "JavaLangClash"})
public final class <%= class_name(key) %> {
<%- schema['properties'].each do |property_name, property| -%>
private final <%= type_for(class_name(key), property_name, property) -%> <%= property_name %>;
<%- schema['properties'].each do |property_name, property|
nullable = !(schema['required'] || []).index(property_name)
-%>
private final <% if nullable -%>@Nullable <%- end -%><%= type_for(class_name(key), property_name, property) -%> <%= property_name %>;
<%- end -%>
<%- if (schema['required'] || []).empty? -%>
<%- schema['properties'].each do |(property_name, property)| -%>
Expand All @@ -30,7 +33,7 @@ public final class <%= class_name(key) %> {
<%- schema['properties'].each_with_index do |(property_name_2, _property_2), index| -%>
<%- if property_name_2 == property_name -%>
<%- if property['items'] -%>
unmodifiableList(new ArrayList<>(requireNonNull(<%= property_name %>, "<%= class_name(key) %>.<%= property_name %> cannot be null")))<%= index < schema['properties'].length - 1 ? ',' : '' %>
List.copyOf(requireNonNull(<%= property_name %>, "<%= class_name(key) %>.<%= property_name %> cannot be null"))<%= index < schema['properties'].length - 1 ? ',' : '' %>
<%- else -%>
requireNonNull(<%= property_name %>, "<%= class_name(key) %>.<%= property_name %> cannot be null")<%= index < schema['properties'].length - 1 ? ',' : '' %>
<%- end -%>
Expand All @@ -44,22 +47,24 @@ public final class <%= class_name(key) %> {
<%- end -%>

public <%= class_name(key) %>(
<%- schema['properties'].each_with_index do |(property_name, property), index| -%>
<%= type_for(class_name(key), property_name, property) -%> <%= property_name %><%= index < schema['properties'].length-1 ? ',' : ''%>
<%- schema['properties'].each_with_index do |(property_name, property), index|
nullable = !(schema['required'] || []).index(property_name)
-%>
<% if nullable -%>@Nullable <%- end -%><%= type_for(class_name(key), property_name, property) -%> <%= property_name %><%= index < schema['properties'].length-1 ? ',' : ''%>
<%- end -%>
) {
<%- schema['properties'].each do |(property_name, property)|
required = (schema['required'] || []).index(property_name)
-%>
<%- if required -%>
<%- if property['items'] -%>
this.<%= property_name %> = unmodifiableList(new ArrayList<>(requireNonNull(<%= property_name %>, "<%= class_name(key) %>.<%= property_name %> cannot be null")));
this.<%= property_name %> = List.copyOf(requireNonNull(<%= property_name %>, "<%= class_name(key) %>.<%= property_name %> cannot be null"));
<%- else -%>
this.<%= property_name %> = requireNonNull(<%= property_name %>, "<%= class_name(key) %>.<%= property_name %> cannot be null");
<%- end -%>
<%- else -%>
<%- if property['items'] -%>
this.<%= property_name %> = <%= property_name %> == null ? null : unmodifiableList(new ArrayList<>(<%= property_name %>));
this.<%= property_name %> = <%= property_name %> == null ? null : List.copyOf(<%= property_name %>);
<%- else -%>
this.<%= property_name %> = <%= property_name %>;
<%- end -%>
Expand All @@ -81,7 +86,7 @@ public final class <%= class_name(key) %> {

<%- unless (property['description'] || []).empty? -%>
/**
<%= format_description(property['description'], indent_string: ' ') %>
<%= format_description(property['description'], indent_string: ' ') %>
*/
<%- end -%>
public Optional<<%= type_for(class_name(key), property_name, property) -%>> get<%= capitalize(property_name) %>() {
Expand Down
2 changes: 2 additions & 0 deletions cpp/include/messages/cucumber/messages/pickle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <nlohmann/json.hpp>

#include <cucumber/messages/location.hpp>
#include <cucumber/messages/pickle_step.hpp>
#include <cucumber/messages/pickle_tag.hpp>

Expand Down Expand Up @@ -34,6 +35,7 @@ struct pickle
{
std::string id;
std::string uri;
std::optional<cucumber::messages::location> location;
std::string name;
std::string language;
std::vector<cucumber::messages::pickle_step> steps;
Expand Down
2 changes: 2 additions & 0 deletions cpp/src/lib/messages/cucumber/messages/pickle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pickle::to_string() const

cucumber::messages::to_string(oss, "id=", id);
cucumber::messages::to_string(oss, ", uri=", uri);
cucumber::messages::to_string(oss, ", location=", location);
cucumber::messages::to_string(oss, ", name=", name);
cucumber::messages::to_string(oss, ", language=", language);
cucumber::messages::to_string(oss, ", steps=", steps);
Expand All @@ -26,6 +27,7 @@ pickle::to_json(json& j) const
{
cucumber::messages::to_json(j, camelize("id"), id);
cucumber::messages::to_json(j, camelize("uri"), uri);
cucumber::messages::to_json(j, camelize("location"), location);
cucumber::messages::to_json(j, camelize("name"), name);
cucumber::messages::to_json(j, camelize("language"), language);
cucumber::messages::to_json(j, camelize("steps"), steps);
Expand Down
10 changes: 10 additions & 0 deletions dotnet/Cucumber.Messages/generated/Pickle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ public sealed class Pickle
* The uri of the source file
*/
public string Uri { get; private set; }
/**
* The location of this pickle in source file. A pickle constructed from `Examples` will point to the example row.
*/
public Location Location { get; private set; }
/**
* The name of the pickle
*/
Expand Down Expand Up @@ -63,6 +67,7 @@ public sealed class Pickle
public Pickle(
string id,
string uri,
Location location,
string name,
string language,
List<PickleStep> steps,
Expand All @@ -74,6 +79,7 @@ List<string> astNodeIds
this.Id = id;
RequireNonNull<string>(uri, "Uri", "Pickle.Uri cannot be null");
this.Uri = uri;
this.Location = location;
RequireNonNull<string>(name, "Name", "Pickle.Name cannot be null");
this.Name = name;
RequireNonNull<string>(language, "Language", "Pickle.Language cannot be null");
Expand All @@ -94,6 +100,7 @@ public override bool Equals(Object o)
return
Id.Equals(that.Id) &&
Uri.Equals(that.Uri) &&
Object.Equals(Location, that.Location) &&
Name.Equals(that.Name) &&
Language.Equals(that.Language) &&
Steps.Equals(that.Steps) &&
Expand All @@ -108,6 +115,8 @@ public override int GetHashCode()
hash = hash * 31 + Id.GetHashCode();
if (Uri != null)
hash = hash * 31 + Uri.GetHashCode();
if (Location != null)
hash = hash * 31 + Location.GetHashCode();
if (Name != null)
hash = hash * 31 + Name.GetHashCode();
if (Language != null)
Expand All @@ -126,6 +135,7 @@ public override string ToString()
return "Pickle{" +
"id=" + Id +
", uri=" + Uri +
", location=" + Location +
", name=" + Name +
", language=" + Language +
", steps=" + Steps +
Expand Down
Loading
Loading