Skip to content

Commit ae590c4

Browse files
authored
[Ruby] Add support for populating a gem metadata (#16872)
* [Ruby] Add support for gems metadata This defaults to an empty hash, but can be overridden with any custom object by the callers via the `gemMetadata` property. * Regenerate samples The gemspecs files will now include a metadata field
1 parent f16744a commit ae590c4

File tree

13 files changed

+26
-0
lines changed

13 files changed

+26
-0
lines changed

docs/generators/ruby.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
2727
|gemDescription|gem description. | |This gem maps to a REST API|
2828
|gemHomepage|gem homepage. | |https://openapi-generator.tech|
2929
|gemLicense|gem license. | |unlicense|
30+
|gemMetadata|gem metadata.| |{}|
3031
|gemName|gem name (convention: underscore_case).| |openapi_client|
3132
|gemRequiredRubyVersion|gem required Ruby version. | |>= 2.4|
3233
|gemSummary|gem summary. | |A ruby wrapper for the REST APIs|

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RubyClientCodegen.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public class RubyClientCodegen extends AbstractRubyCodegen {
4848
public static final String GEM_DESCRIPTION = "gemDescription";
4949
public static final String GEM_AUTHOR = "gemAuthor";
5050
public static final String GEM_AUTHOR_EMAIL = "gemAuthorEmail";
51+
public static final String GEM_METADATA = "gemMetadata";
5152
public static final String FARADAY = "faraday";
5253
public static final String HTTPX = "httpx";
5354
public static final String TYPHOEUS = "typhoeus";
@@ -66,6 +67,7 @@ public class RubyClientCodegen extends AbstractRubyCodegen {
6667
protected String gemSummary = "A Ruby SDK for the REST API";
6768
protected String gemDescription = "This gem maps to a REST API";
6869
protected String gemAuthor = "";
70+
protected String gemMetadata = "{}";
6971
protected String gemAuthorEmail = "";
7072
protected String apiDocPath = "docs/";
7173
protected String modelDocPath = "docs/";
@@ -170,6 +172,9 @@ public RubyClientCodegen() {
170172

171173
cliOptions.add(new CliOption(GEM_AUTHOR_EMAIL, "gem author email (only one is supported)."));
172174

175+
cliOptions.add(new CliOption(GEM_METADATA, "gem metadata.").
176+
defaultValue("{}"));
177+
173178
cliOptions.add(new CliOption(CodegenConstants.HIDE_GENERATION_TIMESTAMP, CodegenConstants.HIDE_GENERATION_TIMESTAMP_DESC).
174179
defaultValue(Boolean.TRUE.toString()));
175180

@@ -246,6 +251,10 @@ public void processOpts() {
246251
setGemAuthorEmail((String) additionalProperties.get(GEM_AUTHOR_EMAIL));
247252
}
248253

254+
if (additionalProperties.containsKey(GEM_METADATA)) {
255+
setGemMetadata((String) additionalProperties.get(GEM_METADATA));
256+
}
257+
249258
if (additionalProperties.containsKey(USE_AUTOLOAD)) {
250259
setUseAutoload(convertPropertyToBooleanAndWriteBack(USE_AUTOLOAD));
251260
}
@@ -613,6 +622,10 @@ public void setGemAuthorEmail(String gemAuthorEmail) {
613622
this.gemAuthorEmail = gemAuthorEmail;
614623
}
615624

625+
public void setGemMetadata(String gemMetadata) {
626+
this.gemMetadata = gemMetadata;
627+
}
628+
616629
public void setUseAutoload(boolean useAutoload) {
617630
this.useAutoload = useAutoload;
618631
}

modules/openapi-generator/src/main/resources/ruby-client/gemspec.mustache

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Gem::Specification.new do |s|
1818
s.description = "{{gemDescription}}{{^gemDescription}}{{{appDescription}}}{{^appDescription}}{{{appName}}} Ruby Gem{{/appDescription}}{{/gemDescription}}"
1919
s.license = "{{{gemLicense}}}{{^gemLicense}}Unlicense{{/gemLicense}}"
2020
s.required_ruby_version = "{{{gemRequiredRubyVersion}}}{{^gemRequiredRubyVersion}}>= 2.7{{/gemRequiredRubyVersion}}"
21+
s.metadata = {{{gemMetadata}}}{{^gemMetadata}}{}{{/gemMetadata}}
2122

2223
{{#isFaraday}}
2324
s.add_runtime_dependency 'faraday', '>= 1.0.1', '< 3.0'

modules/openapi-generator/src/test/java/org/openapitools/codegen/options/RubyClientOptionsProvider.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public class RubyClientOptionsProvider implements OptionsProvider {
3636
public static final String GEM_SUMMARY_VALUE = "summary";
3737
public static final String GEM_DESCRIPTION_VALUE = "description";
3838
public static final String GEM_AUTHOR_VALUE = "foo";
39+
public static final String GEM_METADATA_VALUE = "{}";
3940
public static final String GEM_AUTHOR_EMAIL_VALUE = "foo";
4041
public static final String ALLOW_UNICODE_IDENTIFIERS_VALUE = "false";
4142
public static final String PREPEND_FORM_OR_BODY_PARAMETERS_VALUE = "true";
@@ -61,6 +62,7 @@ public Map<String, String> createOptions() {
6162
.put(RubyClientCodegen.GEM_SUMMARY, GEM_SUMMARY_VALUE)
6263
.put(RubyClientCodegen.GEM_AUTHOR, GEM_AUTHOR_VALUE)
6364
.put(RubyClientCodegen.GEM_AUTHOR_EMAIL, GEM_AUTHOR_EMAIL_VALUE)
65+
.put(RubyClientCodegen.GEM_METADATA, GEM_METADATA_VALUE)
6466
.put(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG, SORT_PARAMS_VALUE)
6567
.put(CodegenConstants.SORT_MODEL_PROPERTIES_BY_REQUIRED_FLAG, SORT_MODEL_PROPERTIES_VALUE)
6668
.put(CodegenConstants.ENSURE_UNIQUE_PARAMS, ENSURE_UNIQUE_PARAMS_VALUE)

modules/openapi-generator/src/test/java/org/openapitools/codegen/ruby/RubyClientOptionsTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ protected void verifyOptions() {
5050
verify(clientCodegen).setGemSummary(RubyClientOptionsProvider.GEM_SUMMARY_VALUE);
5151
verify(clientCodegen).setGemAuthor(RubyClientOptionsProvider.GEM_AUTHOR_VALUE);
5252
verify(clientCodegen).setGemAuthorEmail(RubyClientOptionsProvider.GEM_AUTHOR_EMAIL_VALUE);
53+
verify(clientCodegen).setGemMetadata(RubyClientOptionsProvider.GEM_METADATA_VALUE);
5354
verify(clientCodegen).setEnumUnknownDefaultCase(Boolean.parseBoolean(RubyClientOptionsProvider.ENUM_UNKNOWN_DEFAULT_CASE_VALUE));
5455
verify(clientCodegen).setUseAutoload(Boolean.parseBoolean(RubyClientOptionsProvider.USE_AUTOLOAD_VALUE));
5556
}

samples/client/echo_api/ruby-httpx/openapi_client.gemspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Gem::Specification.new do |s|
2626
s.description = "Echo Server API"
2727
s.license = "Unlicense"
2828
s.required_ruby_version = ">= 2.7"
29+
s.metadata = {}
2930

3031
s.add_runtime_dependency 'httpx', '~> 1.0', '>= 1.0.0'
3132

samples/client/petstore/ruby-autoload/petstore.gemspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Gem::Specification.new do |s|
2626
s.description = "This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\"
2727
s.license = "Unlicense"
2828
s.required_ruby_version = ">= 2.7"
29+
s.metadata = {}
2930

3031
s.add_runtime_dependency 'typhoeus', '~> 1.0', '>= 1.0.1'
3132

samples/client/petstore/ruby-faraday/petstore.gemspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Gem::Specification.new do |s|
2626
s.description = "This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\"
2727
s.license = "Unlicense"
2828
s.required_ruby_version = ">= 2.7"
29+
s.metadata = {}
2930

3031
s.add_runtime_dependency 'faraday', '>= 1.0.1', '< 3.0'
3132
s.add_runtime_dependency 'faraday-multipart'

samples/client/petstore/ruby-httpx/petstore.gemspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Gem::Specification.new do |s|
2626
s.description = "This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\"
2727
s.license = "Unlicense"
2828
s.required_ruby_version = ">= 2.7"
29+
s.metadata = {}
2930

3031
s.add_runtime_dependency 'httpx', '~> 1.0', '>= 1.0.0'
3132

samples/client/petstore/ruby/petstore.gemspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Gem::Specification.new do |s|
2626
s.description = "This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\"
2727
s.license = "Unlicense"
2828
s.required_ruby_version = ">= 2.7"
29+
s.metadata = {}
2930

3031
s.add_runtime_dependency 'typhoeus', '~> 1.0', '>= 1.0.1'
3132

0 commit comments

Comments
 (0)