swagger-codegen icon indicating copy to clipboard operation
swagger-codegen copied to clipboard

adding fluent api options to spring java codegen

Open UltimateDogg opened this issue 8 years ago • 7 comments

this adds two boolean flags simpleFluentPattern and collectionFluentPattern for the spring language generator. Both default to true which is the current behavior today. This is probably applicable to anything that is java related but there seems to be a lot of disparate classes that deal with Java. feedback is welcome.

I added these flags as some versions of jackson has issues with multiple setters that take the same input.

@bbdouglas @JFCote @sreeshas @jfiala @lukoyanov @cbornet

UltimateDogg avatar Nov 25 '17 18:11 UltimateDogg

@UltimateDogg can you detail the problem you have with Jackson ?

cbornet avatar Nov 25 '17 19:11 cbornet

Sure @cbornet. Error was com.fasterxml.jackson.databind.JsonMappingException: Can not construct instance of x.x.x.x.L2SwitchInterface: no String-argument constructor/factory method to deserialize from String value ('WAN1') the error seemed to be coming from the fact that there is a field like

@JsonProperty("name") @JacksonXmlProperty(localName = "name") private String name = null;

and getter and setters of

public L2SwitchInterface name(String name) { this.name = name; return this; }

public String getName() { return name; }

public void setName(String name) { this.name = name; }

since there are two setters it seems that jackson is having issues picking which one is the setter. removing the one helped.

UltimateDogg avatar Nov 26 '17 04:11 UltimateDogg

I don’t understand : there’s a mix of name and L2SwitchInterfaceName. Can you provide your swagger spec and the command line used for generation ?

cbornet avatar Nov 26 '17 09:11 cbornet

here is the stripped down area that caused issue with version jackson 2.8.5, but works ok in latest 2.9

package com.github.test.model;

import java.util.Objects;
import com.fasterxml.jackson.annotation.JsonProperty;

/**
 * L2SwitchInterfaces
 */
@javax.annotation.Generated(value = "io.swagger.codegen.languages.SpringCodegen", date = "2017-11-27T15:02:32.772-05:00")
public class L2SwitchInterfaces   {
  @JsonProperty("name")
  private String name = null;

  public L3ucpeApiUniversalcpeftUniversalcpeftL2SwitchInterfaces name(String name) {
    this.name = name;
    return this;
  }

  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }
}

basically when i passed WAN1 in the name field it would fail unless i removed the

  public L3ucpeApiUniversalcpeftUniversalcpeftL2SwitchInterfaces name(String name) {
    this.name = name;
    return this;
  }

so i wrote some flags for this

UltimateDogg avatar Nov 27 '17 20:11 UltimateDogg

I just tried the Spring Petstore sample and didn't reproduce your issue. The Pet model has a string property called name just as your snippet. So your issue is something else. Could you share a minimal project reproducing your issue on a github repo ?

cbornet avatar Nov 28 '17 07:11 cbornet

i will try and see about setting up a github project with the exact details. I know that my swagger is about 8 levels deep so i dont know if that had something to do with it.

UltimateDogg avatar Nov 29 '17 02:11 UltimateDogg

i was unable to make a test case. It may be the combination of version / libraries I used or it may have been a transitive issue that was due to environment. The features added do work however so i will leave it up to you if you think there is any value. I can also always reopen if i am able to reproduce in the future.

UltimateDogg avatar Dec 03 '17 17:12 UltimateDogg