Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bad ApiRestClient Generation #315

Closed
RobertoSngular opened this issue Jan 18, 2024 · 0 comments · Fixed by #316
Closed

Bad ApiRestClient Generation #315

RobertoSngular opened this issue Jan 18, 2024 · 0 comments · Fixed by #316
Assignees
Labels
bug Something isn't working

Comments

@RobertoSngular
Copy link
Contributor

There're 2 issues:

It's declaring variables finals and then changing his value so a compiles error is made.

private static void createDefaultObjectMapper(final DateFormat defaultDateFormat, final AbstractJackson2HttpMessageConverter converter) {
      final DateFormat dateFormat = defaultDateFormat;
      if (Objects.isNull(defaultDateFormat)) {
        dateFormat = createDefaultDateFormat();
      }
      final ObjectMapper mapper = converter.getObjectMapper();
      mapper.setDateFormat(dateFormat);
      mapper.registerModule(new JavaTimeModule());
      mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    }

DateFormat shouldn't be declared final.

public MultiValueMap<String, String> parameterToMultiValueMap(final CollectionFormat collectionFormat, final String name, final Object value) {
    final MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>();

    if (name == null || name.isEmpty() || value == null) {
      return params;
    }

    if (collectionFormat == null) {
      collectionFormat = CollectionFormat.CSV;
    }

    if (value instanceof Map) {
      @SuppressWarnings("unchecked")
      final Map<String, Object> valuesMap = (Map<String, Object>) value;
      for (final Entry<String, Object> entry : valuesMap.entrySet()) {
        params.add(entry.getKey(), parameterToString(entry.getValue()));
      }
      return params;
    }

    Collection<?> valueCollection = null;
    if (value instanceof Collection) {
      valueCollection = (Collection<?>) value;
    } else {
      params.add(name, parameterToString(value));
      return params;
    }

    if (valueCollection.isEmpty()) {
      return params;
    }

    if (collectionFormat.equals(CollectionFormat.MULTI)) {
      for (Object item : valueCollection) {
        params.add(name, parameterToString(item));
      }
      return params;
    }

    List<String> values = new ArrayList<String>();
    for (Object o : valueCollection) {
      values.add(parameterToString(o));
    }
    params.add(name, collectionFormat.collectionToString(values));

    return params;
  }

The parameter collectionFormat shouldn't be declared final

It's missing a semicolon in the last result assigment.

public String collectionPathParameterToString(final CollectionFormat collectionFormat, final Collection<?> values) {
    String result;
    if (CollectionFormat.MULTI.equals(collectionFormat)) {
      result = parameterToString(values);
    }
    if(collectionFormat == null) {
      result = CollectionFormat.CSV.collectionToString(values);
    } else {
      result = collectionFormat.collectionToString(values)
    }
    return result;
  }
@RobertoSngular RobertoSngular added the bug Something isn't working label Jan 18, 2024
@RobertoSngular RobertoSngular self-assigned this Jan 18, 2024
@RobertoSngular RobertoSngular linked a pull request Jan 18, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant