Skip to content

Commit

Permalink
Merge pull request #8 from Pakisan/feat/2.6.0_components
Browse files Browse the repository at this point in the history
feat(AsyncAPI 2.6.0): Components
  • Loading branch information
Pakisan authored Feb 15, 2023
2 parents 7e5e705 + 116b466 commit 6b17ff4
Show file tree
Hide file tree
Showing 62 changed files with 4,138 additions and 306 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.asyncapi.v2._6_0.jackson;

import com.asyncapi.v2._6_0.model.Reference;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.ObjectCodec;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
* Deserializes AsyncAPI map of parameters
* @param <ObjectType> object
*/
public abstract class MapOfReferencesOrObjectsDeserializer<ObjectType> extends JsonDeserializer<Map<String, Object>> {

private final ObjectMapper objectMapper = new ObjectMapper();

abstract public Class<ObjectType> objectTypeClass();

@Override
public Map<String, Object> deserialize(JsonParser jsonParser,
DeserializationContext deserializationContext
) throws IOException, JsonProcessingException {
ObjectCodec objectCodec = jsonParser.getCodec();
JsonNode map = objectCodec.readTree(jsonParser);

Map<String, Object> parameters = new HashMap<>();

map.fieldNames().forEachRemaining(
fieldName -> {
try {
parameters.put(fieldName, chooseKnownPojo(map.get(fieldName)));
} catch (IOException e) {
e.printStackTrace();
}
}
);

return parameters;
}

private Object chooseKnownPojo(JsonNode parametersValue) throws IOException {
if (parametersValue.get("$ref") != null) {
return objectMapper.readValue(parametersValue.toString(), Reference.class);
} else {
return objectMapper.readValue(parametersValue.toString(), objectTypeClass());
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.asyncapi.v2._6_0.jackson.model.component;

import com.asyncapi.v2._6_0.jackson.MapOfReferencesOrObjectsDeserializer;
import com.asyncapi.v2._6_0.model.channel.message.CorrelationId;

public class ComponentsCorrelationIdsDeserializer extends MapOfReferencesOrObjectsDeserializer<CorrelationId> {

@Override
public Class<CorrelationId> objectTypeClass() {
return CorrelationId.class;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.asyncapi.v2._6_0.jackson.model.component;

import com.asyncapi.v2._6_0.jackson.MapOfReferencesOrObjectsDeserializer;
import com.asyncapi.v2._6_0.model.channel.message.CorrelationId;
import com.asyncapi.v2._6_0.model.channel.message.MessageTrait;

public class ComponentsMessageTraitsDeserializer extends MapOfReferencesOrObjectsDeserializer<MessageTrait> {

@Override
public Class<MessageTrait> objectTypeClass() {
return MessageTrait.class;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.asyncapi.v2._6_0.jackson.model.component;

import com.asyncapi.v2._6_0.jackson.MapOfReferencesOrObjectsDeserializer;
import com.asyncapi.v2._6_0.model.channel.message.Message;

public class ComponentsMessagesDeserializer extends MapOfReferencesOrObjectsDeserializer<Message> {

@Override
public Class<Message> objectTypeClass() {
return Message.class;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.asyncapi.v2._6_0.jackson.model.component;

import com.asyncapi.v2._6_0.jackson.MapOfReferencesOrObjectsDeserializer;
import com.asyncapi.v2._6_0.model.channel.message.CorrelationId;
import com.asyncapi.v2._6_0.model.channel.operation.OperationTrait;

public class ComponentsOperationTraitsDeserializer extends MapOfReferencesOrObjectsDeserializer<OperationTrait> {

@Override
public Class<OperationTrait> objectTypeClass() {
return OperationTrait.class;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.asyncapi.v2._6_0.jackson.model.component;

import com.asyncapi.v2._6_0.jackson.MapOfReferencesOrObjectsDeserializer;
import com.asyncapi.v2._6_0.model.channel.Parameter;

public class ComponentsParametersDeserializer extends MapOfReferencesOrObjectsDeserializer<Parameter> {

@Override
public Class<Parameter> objectTypeClass() {
return Parameter.class;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.asyncapi.v2._6_0.jackson.model.component;

import com.asyncapi.v2._6_0.jackson.MapOfReferencesOrObjectsDeserializer;
import com.asyncapi.v2._6_0.model.schema.Schema;

public class ComponentsSchemasDeserializer extends MapOfReferencesOrObjectsDeserializer<Schema> {

@Override
public Class<Schema> objectTypeClass() {
return Schema.class;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.asyncapi.v2._6_0.jackson.model.component;

import com.asyncapi.v2._6_0.jackson.MapOfReferencesOrObjectsDeserializer;
import com.asyncapi.v2._6_0.model.security_scheme.SecurityScheme;

public class ComponentsSecuritySchemesDeserializer extends MapOfReferencesOrObjectsDeserializer<SecurityScheme> {

@Override
public Class<SecurityScheme> objectTypeClass() {
return SecurityScheme.class;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.asyncapi.v2._6_0.jackson.model.component;

import com.asyncapi.v2._6_0.jackson.MapOfReferencesOrObjectsDeserializer;
import com.asyncapi.v2._6_0.model.server.ServerVariable;

public class ComponentsServerVariablesDeserializer extends MapOfReferencesOrObjectsDeserializer<ServerVariable> {

@Override
public Class<ServerVariable> objectTypeClass() {
return ServerVariable.class;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.asyncapi.v2._6_0.jackson.model.component;

import com.asyncapi.v2._6_0.jackson.MapOfReferencesOrObjectsDeserializer;
import com.asyncapi.v2._6_0.model.server.Server;

public class ComponentsServersDeserializer extends MapOfReferencesOrObjectsDeserializer<Server> {

@Override
public Class<Server> objectTypeClass() {
return Server.class;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.asyncapi.v2.model.ExternalDocumentation;
import com.asyncapi.v2.model.Tag;
import com.asyncapi.v2._6_0.model.channel.ChannelItem;
import com.asyncapi.v2.model.component.Components;
import com.asyncapi.v2._6_0.model.component.Components;
import com.asyncapi.v2._6_0.model.info.Info;
import com.asyncapi.v2._6_0.model.server.Server;
import lombok.*;
Expand Down
Loading

0 comments on commit 6b17ff4

Please sign in to comment.