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

Configuration "withXml" not work for "jaxrs-cxf-client" language in version 3.0.0-SNAPSHOT #8393

Closed
bdileo1 opened this issue Jul 5, 2018 · 6 comments
Assignees

Comments

@bdileo1
Copy link

bdileo1 commented Jul 5, 2018

Description

Hi, we are using the "swagger-codegen-maven-plugin" in version 3.0.0-SNAPSHOT and we noticed that there are problems with the "withXml" property.
In particular, there are 2 problems :

  1. the properiety configured in the pom.xml is ignored, which causes a regression on the insertion of the annotations on the API;
  2. Xml annotations are not inserted in nested enums.
Swagger-codegen version

3.0.0-SNAPSHOT

Command line used for generation

mvn clean install

following the configuration of the maven plugin

<plugin>
	<groupId>io.swagger</groupId>
	<artifactId>swagger-codegen-maven-plugin</artifactId>
	<version>3.0.0-SNAPSHOT</version>
	<executions>
		<execution>
			<goals>
				<goal>generate</goal>
			</goals>
			<configuration>
				<inputSpec>src/main/resources/test.json</inputSpec>
				<language>jaxrs-cxf-client</language>
				<withXml>true</withXml>
				<sourceFolder>src/main/java</sourceFolder>
				<apiPackage>codegen.api</apiPackage>
				<modelPackage>codegen.model</modelPackage>
				<generateApis>true</generateApis>
				<generateApiTest>false</generateApiTest>
				<generateApiDocumentation>false</generateApiDocumentation>
				<generateModels>true</generateModels>
				<generateModelTests>false</generateModelTests>
				<generateModelDocumentation>false</generateModelDocumentation>
				<dateLibrary>java8-localdatetime</dateLibrary>
			</configuration>
		</execution>
	</executions>
</plugin>
Swagger declaration file content or url

following the configuration of the example json

{
    "swagger": "2.0",
    "info": {
        "description": "description",
        "version": "1.0",
        "title": "Test json"
    },
    "host": "localhost:8080",
    "basePath": "/tets/servlet/services",
    "schemes": [
        "http"
    ],
    "paths": {
        "/testRequest": {
            "post": {
                "operationId": "testRequest",
                "tags": [
                    "test operation"
                ],
                "description": "",
                "consumes": [
                    "application/json"
                ],
                "produces": [
                    "application/json",
                    "text/plain"
                ],
                "parameters": [
                    {
                        "in": "body",
                        "name": "Request Body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/TestRequest"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/TestResponse"
                        }
                    }
                }
            }
        }
    },
    "definitions": {
        "TestRequest": {
            "description": "Request Message",
            "type": "object",
            "allOf": [ {
                    "properties": {
                        "body": {
                            "$ref": "#/definitions/TestRequestBody"
                        }
                    },
                    "required": [
                        "body"
                    ]
                }
            ]
        },
        "TestRequestBody": {
            "type": "object",
            "properties": {
                "TestCode": {
                    "$ref": "#/definitions/tTestCode"
                }
            },
            "required": [
                "TestCode"
            ]
        },
        "TestResponse": {
            "description": "Response Message",
            "type": "object",
            "allOf": [ {
                    "properties": {
                        "body": {
                            "$ref": "#/definitions/TestResponseBody"
                        }
                    },
                    "required": [
                        "body"
                    ]
                }
            ]
        },
        "TestResponseBody": {
            "type": "object",
            "properties": {
                "TestType": {
                    "$ref": "#/definitions/tTestType"
                }
            },
            "required": [
                "TestType"
            ]
        },
        "tTestCode": {
            "type": "integer",
            "minLength": 3,
            "maxLength": 3,
            "format": "int64"
        },
        "tTestType": {
            "type": "string",
            "minLength": 0,
            "maxLength": 20,
            "enum": [
                "Test1",
                "Test2",
                "Test3"
            ]
        }
    }
}
@HugoMario
Copy link
Contributor

Hey @bdileo1 i think the issue here is that template is not working with the withXml, if you can give me the expected output i can create a PR solving this.

@bdileo1
Copy link
Author

bdileo1 commented Jul 9, 2018

Hi @HugoMario, thank you for fast reply.

About the enum class:
The expected result should be similar to the EXAMPLE_1, but the plugin generates the code reported in EXAMPLE_2 :

EXAMPLE_1 (expected result):

@XmlType(name = "TTestType")
@XmlEnum(String.class)
public enum TTestType {
	@XmlEnumValue("Test1")
	TEST1("Test1"),
	@XmlEnumValue("Test2")
	TEST2("Test2"),
	@XmlEnumValue("Test3")
	TEST3("Test3");

	private String value;
	TTestType(String value) {
		this.value = value;
	}
	@Override
	public String toString() {
		return String.valueOf(value);
	}
	public static TTestType fromValue(String text) {
		for (TTestType b : TTestType.values()) {
			if (String.valueOf(b.value).equals(text)) {
				return b;
			}
		}
		return null;
	}
}

EXAMPLE_2:

public enum TTestType {
	TEST1("Test1"),
	TEST2("Test2"),
	TEST3("Test3");

	private String value;
	TTestType(String value) {
		this.value = value;
	}
	@Override
	public String toString() {
		return String.valueOf(value);
	}
	public static TTestType fromValue(String text) {
		for (TTestType b : TTestType.values()) {
			if (String.valueOf(b.value).equals(text)) {
				return b;
			}
		}
		return null;
	}
}

About a simple DTO:
The expected result should be similar to the EXAMPLE_3, but the plugin generates the code reported in EXAMPLE_4 :

EXAMPLE_3 (expected result):

@ApiModel(description="Request Message")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "TestRequest", propOrder = { "testCode" })
@XmlRootElement(name = "TestRequest")
public class TestRequest  {
	@ApiModelProperty(required = true, value = "")
	@XmlElement(name="testCode", required=true)
	private Long testCode = null;
        ...
}

EXAMPLE_4:

@ApiModel(description="Request Message")
public class TestRequest  {
	@ApiModelProperty(required = true, value = "")
	private Long testCode = null;
        ...
}

thanks.

@HugoMario
Copy link
Contributor

@bdileo1 i just merged PR fixing this, can you please verify it when you have a chance?

@bdileo1
Copy link
Author

bdileo1 commented Nov 23, 2018

Hi @HugoMario I have the same problem in release 3.0.0-rc0 and 3.0.0-rc1.
Can you fix it?

Thanks.
Regards.

@HugoMario
Copy link
Contributor

hey @bdileo1,

it's being a long time now, but i'll assign this to myself and check if i can add a fix

@HugoMario HugoMario self-assigned this Aug 14, 2020
@HugoMario
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants