Skip to content

Commit

Permalink
feat(openapi) OpenAPI Schema
Browse files Browse the repository at this point in the history
  • Loading branch information
Pakisan committed Apr 4, 2024
1 parent 99f8c1f commit 46b5e87
Show file tree
Hide file tree
Showing 23 changed files with 1,822 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.asyncapi.v3.jackson.schema.openapi;

import com.asyncapi.v3.schema.openapi.OpenAPISchema;
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 java.io.IOException;

/**
* @author Pavel Bodiachevskii
* @version 3.0.0
*/
public class OpenAPISchemaAdditionalPropertiesDeserializer extends JsonDeserializer<Object> {

@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException {
ObjectCodec objectCodec = p.getCodec();
JsonNode node = objectCodec.readTree(p);

return chooseKnownPojo(node, objectCodec);
}

private Object chooseKnownPojo(JsonNode jsonNode, final ObjectCodec objectCodec) throws IOException {
try (JsonParser jsonParser = jsonNode.traverse(objectCodec)) {
if (jsonNode.isBoolean()) {
return jsonNode.asBoolean();
} else {
return jsonParser.readValueAs(OpenAPISchema.class);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.asyncapi.v3.jackson.schema.openapi;

import com.asyncapi.v3.jackson.schema.SchemaAnyValueDeserializer;
import com.asyncapi.v3.schema.openapi.OpenAPISchema;

/**
* @author Pavel Bodiachevskii
*/
public class OpenAPISchemaAnyValueDeserializer extends SchemaAnyValueDeserializer<OpenAPISchema> {

@Override
public Class<OpenAPISchema> schemaClass() {
return OpenAPISchema.class;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.asyncapi.v3.schema.openapi;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyDescription;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Map;

/**
* When request bodies or response payloads may be one of a number of different schemas,
* a discriminator object can be used to aid in serialization, deserialization, and validation.
* <p>
* The discriminator is a specific object in a schema which is used to inform the consumer of the
* specification of an alternative schema based on the value associated with it.
* <p>
* When using the discriminator, inline schemas will not be considered.
* <p>
* The discriminator attribute is legal only when using one of the composite keywords oneOf, anyOf, allOf.
*
* @see <a href="https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.0.md#discriminator-object">Discriminator Object</a>
* @see <a href="https://github.com/swagger-api/swagger-core/blob/v2.1.13/modules/swagger-models/src/main/java/io/swagger/v3/oas/models/media/Discriminator.java">Discriminator</a>
*
* @author Pavel Bodiachevskii
* @version 3.0.0
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Discriminator {

/**
* <b>REQUIRED</b>.
* <p>
* The name of the property in the payload that will hold the discriminator value.
*/
@NotNull
@JsonProperty("propertyName")
@JsonPropertyDescription("The name of the property in the payload that will hold the discriminator value.")
public String propertyName;

/**
* An object to hold mappings between payload values and schema names or references.
*/
@Nullable
@JsonProperty("mapping")
@JsonPropertyDescription("An object to hold mappings between payload values and schema names or references.")
public Map<String, String> mapping;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.asyncapi.v3.schema.openapi;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyDescription;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
* Allows referencing an external resource for extended documentation.
*
* @see <a href="https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.0.md#external-documentation-object">Schema Object</a>
* @see <a href="https://github.com/swagger-api/swagger-core/blob/v2.1.13/modules/swagger-models/src/main/java/io/swagger/v3/oas/models/ExternalDocumentation.java">ExternalDocumentation</a>
*
* @author Pavel Bodiachevskii
* @version 3.0.0
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ExternalDocumentation {

/**
* A short description of the target documentation.
* <p>
* <a href="http://spec.commonmark.org/">CommonMark syntax</a> <b>MAY</b> be used for rich text representation.
*/
@Nullable
@JsonProperty("description")
@JsonPropertyDescription("A short description of the target documentation.")
public String description;

/**
* <b>REQUIRED</b>.
* <p>
* The URL for the target documentation. Value <b>MUST</b> be in the format of a URL.
*/
@NotNull
@JsonProperty("url")
@JsonPropertyDescription("The URL for the target documentation.")
public String url;

}
Loading

0 comments on commit 46b5e87

Please sign in to comment.