use of org.eclipse.microprofile.openapi.models.media.Encoding in project wildfly-swarm by wildfly-swarm.
the class OpenApiSerializer method writeEncodings.
/**
* Writes a map of {@link Encoding} objects to the JSON tree.
* @param parent
* @param models
*/
private void writeEncodings(ObjectNode parent, Map<String, Encoding> models) {
if (models == null) {
return;
}
ObjectNode node = parent.putObject(OpenApiConstants.PROP_ENCODING);
for (String name : models.keySet()) {
Encoding encoding = models.get(name);
writeEncoding(node, encoding, name);
}
}
use of org.eclipse.microprofile.openapi.models.media.Encoding in project wildfly-swarm by wildfly-swarm.
the class OpenApiAnnotationScanner method readEncoding.
/**
* Reads a single Encoding annotation into a model.
* @param annotation
*/
private Encoding readEncoding(AnnotationInstance annotation) {
if (annotation == null) {
return null;
}
LOG.debug("Processing a single @Encoding annotation.");
Encoding encoding = new EncodingImpl();
encoding.setContentType(JandexUtil.stringValue(annotation, OpenApiConstants.PROP_CONTENT_TYPE));
encoding.setStyle(JandexUtil.enumValue(annotation, OpenApiConstants.PROP_STYLE, org.eclipse.microprofile.openapi.models.media.Encoding.Style.class));
encoding.setExplode(JandexUtil.booleanValue(annotation, OpenApiConstants.PROP_EXPLODE));
encoding.setAllowReserved(JandexUtil.booleanValue(annotation, OpenApiConstants.PROP_ALLOW_RESERVED));
encoding.setHeaders(readHeaders(annotation.value(OpenApiConstants.PROP_HEADERS)));
return encoding;
}
use of org.eclipse.microprofile.openapi.models.media.Encoding in project wildfly-swarm by wildfly-swarm.
the class OpenApiAnnotationScanner method readEncodings.
/**
* Reads an array of Encoding annotations as a Map.
* @param value
*/
private Map<String, Encoding> readEncodings(AnnotationValue value) {
if (value == null) {
return null;
}
LOG.debug("Processing a map of @Encoding annotations.");
Map<String, Encoding> map = new LinkedHashMap<>();
AnnotationInstance[] nestedArray = value.asNestedArray();
for (AnnotationInstance annotation : nestedArray) {
String name = JandexUtil.stringValue(annotation, OpenApiConstants.PROP_NAME);
if (name != null) {
map.put(name, readEncoding(annotation));
}
}
return map;
}
use of org.eclipse.microprofile.openapi.models.media.Encoding in project Payara by payara.
the class ContentImpl method merge.
public static void merge(ContentImpl from, Content to, boolean override, ApiContext context) {
if (from == null) {
return;
}
for (Map.Entry<String, MediaType> fromEntry : from.getMediaTypes().entrySet()) {
final String typeName = fromEntry.getKey();
final MediaType fromMediaType = fromEntry.getValue();
// Get or create the corresponding media type
MediaTypeImpl toMediaType = (MediaTypeImpl) to.getMediaTypes().getOrDefault(typeName, new MediaTypeImpl());
to.addMediaType(typeName, toMediaType);
// Merge encoding
for (Map.Entry<String, Encoding> encoding : fromMediaType.getEncoding().entrySet()) {
EncodingImpl.merge(encoding.getKey(), encoding.getValue(), toMediaType.encoding, override, context);
}
// Merge examples
for (Map.Entry<String, Example> example : fromMediaType.getExamples().entrySet()) {
ExampleImpl.merge(example.getKey(), example.getValue(), toMediaType.examples, override);
}
toMediaType.setExample(mergeProperty(toMediaType.getExample(), fromMediaType.getExample(), override));
// Merge schema
if (fromMediaType.getSchema() != null) {
if (toMediaType.getSchema() == null) {
toMediaType.setSchema(new SchemaImpl());
}
Schema schema = toMediaType.getSchema();
SchemaImpl.merge(fromMediaType.getSchema(), schema, true, context);
}
}
}
use of org.eclipse.microprofile.openapi.models.media.Encoding in project Payara by payara.
the class MediaBuilderTest method setupBaseDocument.
@Override
protected void setupBaseDocument(OpenAPI document) {
document.getComponents().addSchema("SimpleMap", createSchema().type(SchemaType.OBJECT).additionalPropertiesSchema(createSchema().type(SchemaType.STRING)));
XML xml = createXML().name("name").namespace("namespace").prefix("prefix").attribute(true).wrapped(true).addExtension("x-ext", "ext-value");
document.getComponents().addSchema("XML", createSchema().xml(xml));
Encoding encoding = createEncoding().contentType("contentType").style(Style.FORM).explode(true).allowReserved(true).addExtension("x-ext", "ext-value").addHeader("header1", createHeader().ref("ref1")).addHeader("header2", createHeader().ref("ref2"));
MediaType mediaType = createMediaType().example("example").schema(createSchema().ref("ref")).addExtension("x-ext", "ext-value").addExample("example1", createExample().ref("ref1")).addExample("example2", createExample().ref("ref2")).addEncoding("encoding1", encoding);
document.getComponents().addResponse("MediaType", createAPIResponse().description("description").content(createContent().addMediaType("type1", mediaType)));
Discriminator discriminator = createDiscriminator().propertyName("propertyName").addMapping("key1", "value1").addMapping("key2", "value2");
document.getComponents().addSchema("Discriminator", createSchema().discriminator(discriminator));
document.getComponents().addSchema("Schema", createSchema().title("title").multipleOf(BigDecimal.ONE).maximum(BigDecimal.ONE).exclusiveMaximum(true).minimum(BigDecimal.ONE).exclusiveMinimum(true).maxLength(10).minLength(1).pattern("pattern").maxItems(11).minItems(2).uniqueItems(true).maxProperties(12).minProperties(3).addRequired("required1").addRequired("required2").type(SchemaType.NUMBER).not(createSchema().ref("not")).addProperty("property1", createSchema().ref("property1")).description("description").format("format").nullable(true).readOnly(true).writeOnly(true).example("example").externalDocs(createExternalDocumentation().url("url")).deprecated(true).xml(xml).addEnumeration("enumeration1").addEnumeration("enumeration2").discriminator(discriminator).addAnyOf(createSchema().ref("anyOf1")).addAnyOf(createSchema().ref("anyOf2")).addAllOf(createSchema().ref("allOf1")).addAllOf(createSchema().ref("allOf2")).addOneOf(createSchema().ref("oneOf1")).addOneOf(createSchema().ref("oneOf2")).additionalPropertiesBoolean(true).items(createSchema().ref("items")).addExtension("x-ext", "ext-value"));
}
Aggregations