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

Protocol test clients generation #3247

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ public class ServiceGeneratorConfig {
SPEC_OVERRIDE_MAPPING.put("cpp-neptune-query", new NeptuneCppClientGenerator());
SPEC_OVERRIDE_MAPPING.put("cpp-eventbridge-json", new EventBridgeCppClientGenerator());
SPEC_OVERRIDE_MAPPING.put("cpp-dsql-rest-json", new DsqlCppClientGenerator());

// protocol tests clients
SPEC_OVERRIDE_MAPPING.put("cpp-ec2-protocol-ec2", new Ec2CppClientGenerator());
} catch (Exception e) {
e.printStackTrace();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/

package com.amazonaws.util.awsclientgenerator.domainmodels.c2j;


import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.google.gson.JsonPrimitive;

import java.lang.reflect.Type;

public class C2jXmlNamespaceDeserializer implements JsonDeserializer<C2jXmlNamespace> {

@Override
public C2jXmlNamespace deserialize(JsonElement jsonElement, Type type,
JsonDeserializationContext context) throws JsonParseException {
C2jXmlNamespace retValue = new C2jXmlNamespace();

if (jsonElement.isJsonObject()) {
JsonObject jsonObject = jsonElement.getAsJsonObject();
if (jsonObject.has("uri")) {
JsonPrimitive uriPrimitive = jsonObject.getAsJsonPrimitive("uri");
if (!uriPrimitive.isString()) {
throw new JsonParseException("Unexpected C2jXmlNamespace.uri type, expected a String!");
}
retValue.setUri(uriPrimitive.getAsString());
}
if (jsonObject.has("prefix")) {
JsonPrimitive prefixPrimitive = jsonObject.getAsJsonPrimitive("prefix");
if (!prefixPrimitive.isString()) {
throw new JsonParseException("Unexpected C2jXmlNamespace.prefix type, expected a String!");
}
retValue.setPrefix(prefixPrimitive.getAsString());
}
} else if (jsonElement.isJsonPrimitive() && jsonElement.getAsJsonPrimitive().isString()) {
retValue.setUri(jsonElement.getAsJsonPrimitive().getAsString());
} else {
throw new JsonParseException("Unexpected C2jXmlNamespace value, expected primitive Object or Primitive!");
}

return retValue;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
package com.amazonaws.util.awsclientgenerator.generators;

import com.amazonaws.util.awsclientgenerator.domainmodels.c2j.C2jServiceModel;
import com.amazonaws.util.awsclientgenerator.domainmodels.c2j.C2jXmlNamespace;
import com.amazonaws.util.awsclientgenerator.domainmodels.c2j.C2jXmlNamespaceDeserializer;
import com.amazonaws.util.awsclientgenerator.domainmodels.codegeneration.EndpointRuleSetModel;
import com.amazonaws.util.awsclientgenerator.domainmodels.codegeneration.PartitionsModel;
import com.amazonaws.util.awsclientgenerator.domainmodels.defaults.BaseOption;
Expand Down Expand Up @@ -38,6 +40,7 @@ public ByteArrayOutputStream generateServiceSourceFromJson(String rawJson, Strin
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.registerTypeAdapter(EndpointTests.EndpointTestParams.class, new EndpointTestParamsDeserializer());
gsonBuilder.registerTypeAdapter(EndpointParameterValue.class, new EndpointParameterValueDeserializer());
gsonBuilder.registerTypeAdapter(C2jXmlNamespace.class, new C2jXmlNamespaceDeserializer());
Gson gson = gsonBuilder.create();

C2jServiceModel c2jServiceModel = gson.fromJson(rawJson, C2jServiceModel.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,13 @@ public SdkFileEntry[] generateSourceFiles(ServiceModel serviceModel) throws Exce
shapes.put(key.replaceAll("Result$", "Response"), shape);
}

//add "disabled" state to SpotInstanceState
List<String> spotInstanceStateEnumValues = shapes.get("SpotInstanceState").getEnumValues();

if(!spotInstanceStateEnumValues.contains("disabled")) {
spotInstanceStateEnumValues.add("disabled");
if (shapes.containsKey("SpotInstanceState")) {
// add "disabled" state to SpotInstanceState
List<String> spotInstanceStateEnumValues = shapes.get("SpotInstanceState").getEnumValues();
if (!spotInstanceStateEnumValues.contains("disabled")) {
spotInstanceStateEnumValues.add("disabled");
}
}

final Collection<Error> serviceErrors = serviceModel.getServiceErrors();
Expand Down
Loading
Loading