sngular/scs-multiapi-plugin

Bad ApiRestClient Generation

Closed this issue · 0 comments

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;
  }