Skip to content
GitLab
    • Explore Projects Groups Snippets
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Merge requests
  • !13903
An error occurred while fetching the assigned milestone of the selected merge_request.

Clash of variable name when the body is just a string

  • Review changes

  • Download
  • Email patches
  • Plain diff
Closed Administrator requested to merge github/fork/gerardnico/patch-1 into 7.0.x 2 years ago
  • Overview 1
  • Commits 6
  • Pipelines 0
  • Changes 10

Created by: gerardnico

If a body is just treated as a string, you would get a body clash name on body

ie this is wrong

RequestParameter body = requestParameters.body();
// body = body is not accepted by java
String body = body != null ? DatabindCodec.mapper().convertValue(body.get(), new TypeReference<String>(){}) : null;

with this change, you would get:

RequestParameter requestParameterBody = requestParameters.body();
String body = requestParameterBody != null ? DatabindCodec.mapper().convertValue(requestParameterBody.get(), new TypeReference<String>(){}) : 

PR checklist

  • [x ] Read the contribution guidelines.
  • [x ] Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package 
    ./bin/generate-samples.sh
    ./bin/utils/export_docs_generators.sh
    Commit all changed files. This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master. These must match the expectations made by your contribution. You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*. For Windows users, please run the script in Git BASH.
  • [x ] File the PR against the correct branch: master (6.1.0) (minor release - breaking changes with fallbacks), 7.0.x (breaking changes without fallbacks)
  • [x ] If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request. @bbdouglas (2017/07) @sreeshas (2017/08) @jfiala (2017/08) @lukoyanov (2017/09) @cbornet (2017/09) @jeff9finger (2018/01) @karismann (2019/03) @Zomzog (2019/04) @lwlee2608 (2019/10)
Compare
  • 7.0.x (base)

and
  • latest version
    0784b20d
    6 commits, 2 years ago

10 files
+ 232
- 36

    Preferences

    File browser
    Compare changes
modules/open‎api-generator‎
src/main/‎resources‎
JavaVertX‎WebServer‎
bodyParam‎s.mustache‎ +3 -2
eli‎xir‎
deserializer‎.ex.mustache‎ +12 -7
p‎hp‎
ObjectSerial‎izer.mustache‎ +49 -4
ruby-‎client‎
api_client_farada‎y_partial.mustache‎ +2 -0
pom‎.xml‎ +8 -8
samples/cli‎ent/petstore‎
elixir/lib/op‎enapi_petstore‎
deseria‎lizer.ex‎ +12 -7
php/OpenAP‎IClient-php‎
l‎ib‎
ObjectSeri‎alizer.php‎ +49 -4
te‎sts‎
ObjectSerial‎izerTest.php‎ +91 -0
ruby-faraday‎/lib/petstore‎
api_cl‎ient.rb‎ +2 -0
pom‎.xml‎ +4 -4
modules/openapi-generator/src/main/resources/JavaVertXWebServer/bodyParams.mustache
+ 3
- 2
  • View file @ 0784b20d

{{#isBodyParam}}
RequestParameter body = requestParameters.body();
{{{dataType}}} {{paramName}} = body != null ? DatabindCodec.mapper().convertValue(body.get(), new TypeReference<{{{dataType}}}>(){}) : null;
{{! Don't use body or requestBody as name, to avoid a name clash with the paramName }}
RequestParameter requestParameterBody = requestParameters.body();
{{{dataType}}} {{paramName}} = requestParameterBody != null ? DatabindCodec.mapper().convertValue(requestParameterBody.get(), new TypeReference<{{{dataType}}}>(){}) : null;
{{/isBodyParam}}
modules/openapi-generator/src/main/resources/elixir/deserializer.ex.mustache
+ 12
- 7
  • View file @ 0784b20d


@@ -19,13 +19,18 @@ defmodule {{moduleName}}.Deserializer do
end
def deserialize(model, field, :map, mod, options) do
model
|> Map.update!(
field,
&Map.new(&1, fn {key, val} ->
{key, Poison.Decode.decode(val, Keyword.merge(options, [as: struct(mod)]))}
end)
)
maybe_transform_map = fn
nil ->
nil
existing_value ->
Map.new(existing_value, fn
{key, val} ->
{key, Poison.Decode.decode(val, Keyword.merge(options, as: struct(mod)))}
end)
end
Map.update!(model, field, maybe_transform_map)
end
def deserialize(model, field, :date, _, _options) do
modules/openapi-generator/src/main/resources/php/ObjectSerializer.mustache
+ 49
- 4
  • View file @ 0784b20d


@@ -148,6 +148,49 @@ class ObjectSerializer
return rawurlencode(self::toString($value));
}
/**
* Checks if a value is empty, based on its OpenAPI type.
*
* @param mixed $value
* @param string $openApiType
*
* @return bool true if $value is empty
*/
private static function isEmptyValue($value, string $openApiType): bool
{
# If empty() returns false, it is not empty regardless of its type.
if (!empty($value)) {
return false;
}
# Null is always empty, as we cannot send a real "null" value in a query parameter.
if ($value === null) {
return true;
}
switch ($openApiType) {
# For numeric values, false and '' are considered empty.
# This comparison is safe for floating point values, since the previous call to empty() will
# filter out values that don't match 0.
case 'int':
case 'integer':
return $value !== 0;
case 'number':
case 'float':
return $value !== 0 && $value !== 0.0;
# For boolean values, '' is considered empty
case 'bool':
case 'boolean':
return !in_array($value, [false, 0], true);
# For all the other types, any value at this point can be considered empty.
default:
return true;
}
}
/**
* Take query parameter properties and turn it into an array suitable for
* native http_build_query or GuzzleHttp\Psr7\Query::build.
@@ -169,10 +212,12 @@ class ObjectSerializer
bool $explode = true,
bool $required = true
): array {
if (
empty($value)
&& ($value !== false || $openApiType !== 'boolean') // if $value === false and $openApiType ==='boolean' it isn't empty
) {
# Check if we should omit this parameter from the query. This should only happen when:
# - Parameter is NOT required; AND
# - its value is set to a value that is equivalent to "empty", depending on its OpenAPI type. For
# example, 0 as "int" or "boolean" is NOT an empty value.
if (self::isEmptyValue($value, $openApiType)) {
if ($required) {
return ["{$paramName}" => ''];
} else {
modules/openapi-generator/src/main/resources/ruby-client/api_client_faraday_partial.mustache
+ 2
- 0
  • View file @ 0784b20d


@@ -26,6 +26,8 @@
end
rescue Faraday::TimeoutError
fail ApiError.new('Connection timed out')
rescue Faraday::ConnectionFailed
fail ApiError.new('Connection failed')
end
if opts[:return_type]
modules/openapi-generator/pom.xml
+ 8
- 8
  • View file @ 0784b20d


@@ -79,7 +79,7 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<version>3.1.0</version>
<executions>
<execution>
<goals>
@@ -227,7 +227,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jxr-plugin</artifactId>
<version>3.0.0</version>
<version>3.3.0</version>
<configuration>
<aggregate>true</aggregate>
</configuration>
@@ -354,9 +354,9 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.atlassian.commonmark</groupId>
<groupId>org.commonmark</groupId>
<artifactId>commonmark</artifactId>
<version>0.11.0</version>
<version>0.20.0</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
@@ -415,23 +415,23 @@
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava-testlib</artifactId>
<version>28.2-jre</version>
<version>31.1-jre</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId>
<version>5.5.0</version>
<version>5.12.1</version>
</dependency>
<dependency>
<groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>caffeine</artifactId>
<version>2.8.1</version>
<version>2.9.3</version>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.19.0</version>
<version>3.23.1</version>
<scope>test</scope>
</dependency>
</dependencies>
0 Assignees
None
Assign to
0 Reviewers
None
Request review from
Labels
0
None
0
None
    Assign labels
  • Manage project labels

Milestone
No milestone
None
None
Time tracking
No estimate or time spent
Lock merge request
Unlocked
0
0 participants
Reference:
Source branch: github/fork/gerardnico/patch-1

Menu

Explore Projects Groups Snippets