Skip to content

Commit

Permalink
code generation wrappers refactoring and protocol test clients genera…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
SergeyRyabinin committed Jan 15, 2025
1 parent fd99d0c commit 5ea3ad1
Show file tree
Hide file tree
Showing 10 changed files with 815 additions and 532 deletions.
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,42 @@
package com.amazonaws.util.awsclientgenerator.domainmodels.c2j;

import com.google.gson.*;

import java.lang.reflect.Type;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
import java.util.List;

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
4 changes: 4 additions & 0 deletions tools/scripts/codegen/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env python3

# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0.
Loading

0 comments on commit 5ea3ad1

Please sign in to comment.