Skip to content

Commit

Permalink
Use xml name (#265)
Browse files Browse the repository at this point in the history
* Update testserver

* Bump to v2.0.19

* Fix generator and update testserver version

* Accept that .XmlName sometimes throws for some reason

* Update autorest

* Fix polymorphism test

* Downgrade autorest testserver version for now

* Update package.json

* Bump to v2.0.20. Fix testserver version range.
  • Loading branch information
RikkiGibson committed Jul 10, 2018
1 parent 1eb2909 commit 65f93d6
Show file tree
Hide file tree
Showing 8 changed files with 203 additions and 15 deletions.
4 changes: 4 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
.idea/
target/
*.iml
.gulp/
.vscode/
src/Model/
src/Properties/
src/Templates/
test/
src/obj/
package/
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@microsoft.azure/autorest.java",
"version": "2.0.18",
"version": "2.0.20",
"description": "The Java extension for classic generators in AutoRest.",
"scripts": {
"autorest": "autorest",
Expand Down Expand Up @@ -32,8 +32,8 @@
},
"homepage": "https://github.com/Azure/autorest.java/blob/master/README.md",
"devDependencies": {
"@microsoft.azure/autorest.testserver": "2.3.14",
"autorest": "2.0.4245",
"@microsoft.azure/autorest.testserver": "2.5.12",
"autorest": "^2.0.4280",
"coffee-script": "1.12.7",
"dotnet-sdk-2.0.0": "1.1.1",
"gulp": "3.9.1",
Expand All @@ -53,4 +53,4 @@
"dependencies": {
"dotnet-2.0.0": "^1.1.0"
}
}
}
29 changes: 18 additions & 11 deletions src/JavaCodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1774,9 +1774,26 @@ private static ServiceModelProperty ParseModelProperty(AutoRestProperty autoRest
}
}

string xmlName;
if (autoRestProperty.ModelType is AutoRestCompositeType)
{
xmlName = autoRestProperty.ModelType.XmlName;
}
else
{
try
{
xmlName = autoRestProperty.XmlName;
}
catch
{
xmlName = null;
}
}

List<string> annotationArgumentList = new List<string>()
{
$"value = \"{(settings.ShouldGenerateXmlSerialization ? autoRestProperty.XmlName : autoRestProperty.SerializedName)}\""
$"value = \"{(settings.ShouldGenerateXmlSerialization ? xmlName : autoRestProperty.SerializedName)}\""
};
if (autoRestProperty.IsRequired)
{
Expand All @@ -1790,16 +1807,6 @@ private static ServiceModelProperty ParseModelProperty(AutoRestProperty autoRest

bool isXmlAttribute = autoRestProperty.XmlIsAttribute;

string xmlName;
try
{
xmlName = autoRestProperty.XmlName;
}
catch (ArgumentNullException)
{
xmlName = null;
}

string serializedName = autoRestProperty.SerializedName;

bool isXmlWrapper = autoRestProperty.XmlIsWrapped;
Expand Down
39 changes: 39 additions & 0 deletions test/vanilla/src/main/java/fixtures/bodycomplex/Polymorphisms.java
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,45 @@ public interface Polymorphisms {
*/
Completable putComplicatedAsync(@NonNull Salmon complexBody);

/**
* Put complex types that are polymorphic, omitting the discriminator.
*
* @param complexBody the Salmon value.
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws ErrorException thrown if the request is rejected by server.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
* @return the Salmon object if successful.
*/
Salmon putMissingDiscriminator(@NonNull Salmon complexBody);

/**
* Put complex types that are polymorphic, omitting the discriminator.
*
* @param complexBody the Salmon value.
* @param serviceCallback the async ServiceCallback to handle successful and failed responses.
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @return a ServiceFuture which will be completed with the result of the network request.
*/
ServiceFuture<Salmon> putMissingDiscriminatorAsync(@NonNull Salmon complexBody, ServiceCallback<Salmon> serviceCallback);

/**
* Put complex types that are polymorphic, omitting the discriminator.
*
* @param complexBody the Salmon value.
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @return a Single which performs the network request upon subscription.
*/
Single<BodyResponse<Salmon>> putMissingDiscriminatorWithRestResponseAsync(@NonNull Salmon complexBody);

/**
* Put complex types that are polymorphic, omitting the discriminator.
*
* @param complexBody the Salmon value.
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @return a Single which performs the network request upon subscription.
*/
Maybe<Salmon> putMissingDiscriminatorAsync(@NonNull Salmon complexBody);

/**
* Put complex types that are polymorphic, attempting to omit required 'birthday' field - the request should not be allowed from the client.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ private interface PolymorphismsService {
@UnexpectedResponseExceptionType(ErrorException.class)
Single<VoidResponse> putComplicated(@BodyParam("application/json; charset=utf-8") Salmon complexBody);

@PUT("complex/polymorphism/missingdiscriminator")
@ExpectedResponses({200})
@UnexpectedResponseExceptionType(ErrorException.class)
Single<BodyResponse<Salmon>> putMissingDiscriminator(@BodyParam("application/json; charset=utf-8") Salmon complexBody);

@PUT("complex/polymorphism/missingrequired/invalid")
@ExpectedResponses({200})
@UnexpectedResponseExceptionType(ErrorException.class)
Expand Down Expand Up @@ -400,6 +405,58 @@ public Completable putComplicatedAsync(@NonNull Salmon complexBody) {
.toCompletable();
}

/**
* Put complex types that are polymorphic, omitting the discriminator.
*
* @param complexBody the Salmon value.
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @throws ErrorException thrown if the request is rejected by server.
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
* @return the Salmon object if successful.
*/
public Salmon putMissingDiscriminator(@NonNull Salmon complexBody) {
return putMissingDiscriminatorAsync(complexBody).blockingGet();
}

/**
* Put complex types that are polymorphic, omitting the discriminator.
*
* @param complexBody the Salmon value.
* @param serviceCallback the async ServiceCallback to handle successful and failed responses.
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @return a ServiceFuture which will be completed with the result of the network request.
*/
public ServiceFuture<Salmon> putMissingDiscriminatorAsync(@NonNull Salmon complexBody, ServiceCallback<Salmon> serviceCallback) {
return ServiceFuture.fromBody(putMissingDiscriminatorAsync(complexBody), serviceCallback);
}

/**
* Put complex types that are polymorphic, omitting the discriminator.
*
* @param complexBody the Salmon value.
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @return a Single which performs the network request upon subscription.
*/
public Single<BodyResponse<Salmon>> putMissingDiscriminatorWithRestResponseAsync(@NonNull Salmon complexBody) {
if (complexBody == null) {
throw new IllegalArgumentException("Parameter complexBody is required and cannot be null.");
}
Validator.validate(complexBody);
return service.putMissingDiscriminator(complexBody);
}

/**
* Put complex types that are polymorphic, omitting the discriminator.
*
* @param complexBody the Salmon value.
* @throws IllegalArgumentException thrown if parameters fail the validation.
* @return a Single which performs the network request upon subscription.
*/
public Maybe<Salmon> putMissingDiscriminatorAsync(@NonNull Salmon complexBody) {
return putMissingDiscriminatorWithRestResponseAsync(complexBody)
.flatMapMaybe((BodyResponse<Salmon> res) -> res.body() == null ? Maybe.empty() : Maybe.just(res.body()));
}

/**
* Put complex types that are polymorphic, attempting to omit required 'birthday' field - the request should not be allowed from the client.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for
* license information.
*
* Code generated by Microsoft (R) AutoRest Code Generator.
* Changes may cause incorrect behavior and will be lost if the code is
* regenerated.
*/

package fixtures.bodycomplex.models;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.microsoft.rest.v2.ExpandableStringEnum;
import java.util.Collection;

/**
* Defines values for GoblinSharkColor.
*/
public final class GoblinSharkColor extends ExpandableStringEnum<GoblinSharkColor> {
/**
* Static value pink for GoblinSharkColor.
*/
public static final GoblinSharkColor PINK = fromString("pink");

/**
* Static value gray for GoblinSharkColor.
*/
public static final GoblinSharkColor GRAY = fromString("gray");

/**
* Static value brown for GoblinSharkColor.
*/
public static final GoblinSharkColor BROWN = fromString("brown");

/**
* Creates or finds a GoblinSharkColor from its string representation.
*
* @param name a name to look for.
* @return the corresponding GoblinSharkColor.
*/
@JsonCreator
public static GoblinSharkColor fromString(String name) {
return fromString(name, GoblinSharkColor.class);
}

/**
* @return known GoblinSharkColor values.
*/
public static Collection<GoblinSharkColor> values() {
return values(GoblinSharkColor.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ public final class Goblinshark extends Shark {
@JsonProperty(value = "jawsize")
private Integer jawsize;

/**
* Colors possible. Possible values include: 'pink', 'gray', 'brown'.
*/
@JsonProperty(value = "color")
private GoblinSharkColor color;

/**
* Get the jawsize value.
*
Expand All @@ -45,4 +51,24 @@ public Goblinshark withJawsize(Integer jawsize) {
this.jawsize = jawsize;
return this;
}

/**
* Get the color value.
*
* @return the color value.
*/
public GoblinSharkColor color() {
return this.color;
}

/**
* Set the color value.
*
* @param color the color value to set.
* @return the Goblinshark object itself.
*/
public Goblinshark withColor(GoblinSharkColor color) {
this.color = color;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import fixtures.bodycomplex.implementation.AutoRestComplexTestServiceImpl;
import fixtures.bodycomplex.models.Fish;
import fixtures.bodycomplex.models.GoblinSharkColor;
import fixtures.bodycomplex.models.Goblinshark;
import fixtures.bodycomplex.models.Salmon;
import fixtures.bodycomplex.models.Sawshark;
Expand Down Expand Up @@ -73,6 +74,7 @@ public void putValid() {
sib3.withLength(30.0);
sib3.withSpecies("scary");
sib3.withJawsize(5);
sib3.withColor(GoblinSharkColor.fromString("pinkish-gray"));
body.siblings().add(sib3);

client.polymorphisms().putValid(body);
Expand Down

0 comments on commit 65f93d6

Please sign in to comment.