Skip to content
Merged
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 @@ -555,17 +555,37 @@ public static Optional<Schema> getArraySchema(io.swagger.v3.oas.annotations.medi
}

if (arraySchema.arraySchema() != null) {
if (StringUtils.isNotBlank(arraySchema.arraySchema().description())) {
arraySchemaObject.setDescription(arraySchema.arraySchema().description());
}
if (StringUtils.isNotBlank(arraySchema.arraySchema().title())) {
arraySchemaObject.setTitle(arraySchema.arraySchema().title());
}
applyArraySchemaAnnotation(arraySchema.arraySchema(), arraySchemaObject);
}

return Optional.of(arraySchemaObject);
}

private static void applyArraySchemaAnnotation(io.swagger.v3.oas.annotations.media.Schema arraySchemaAnnotation, Schema arraySchemaObject) {
if (StringUtils.isNotBlank(arraySchemaAnnotation.description())) {
arraySchemaObject.setDescription(arraySchemaAnnotation.description());
}
if (StringUtils.isNotBlank(arraySchemaAnnotation.title())) {
arraySchemaObject.setTitle(arraySchemaAnnotation.title());
}
if (arraySchemaAnnotation.deprecated()) {
arraySchemaObject.deprecated(true);
}
if (arraySchemaAnnotation.accessMode().equals(io.swagger.v3.oas.annotations.media.Schema.AccessMode.READ_ONLY)) {
arraySchemaObject.setReadOnly(true);
arraySchemaObject.setWriteOnly(null);
} else if (arraySchemaAnnotation.accessMode().equals(io.swagger.v3.oas.annotations.media.Schema.AccessMode.WRITE_ONLY)) {
arraySchemaObject.setReadOnly(null);
arraySchemaObject.setWriteOnly(true);
} else if (arraySchemaAnnotation.accessMode().equals(io.swagger.v3.oas.annotations.media.Schema.AccessMode.READ_WRITE)) {
arraySchemaObject.setReadOnly(null);
arraySchemaObject.setWriteOnly(null);
}
if (arraySchemaAnnotation.examples().length > 0) {
arraySchemaObject.setExamples(Arrays.asList(arraySchemaAnnotation.examples()));
}
}

public static Optional<Schema> getSchemaFromAnnotation(io.swagger.v3.oas.annotations.media.Schema schema, JsonView jsonViewAnnotation) {
return getSchemaFromAnnotation(schema, jsonViewAnnotation, false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@
import io.swagger.v3.core.resolving.resources.TestArrayType;
import io.swagger.v3.core.resolving.resources.TestObject4715;
import io.swagger.v3.core.resolving.v31.model.AnnotatedArray;
import io.swagger.v3.core.resolving.v31.model.AnnotatedArrayProperty;
import io.swagger.v3.core.resolving.v31.model.AnnotatedArrayPropertyWriteOnly;
import io.swagger.v3.core.resolving.v31.model.AnnotatedArrayPropertyReadWrite;
import io.swagger.v3.core.resolving.v31.model.ModelWithDependentSchema;
import io.swagger.v3.core.resolving.v31.model.ModelWithOAS31Stuff;
import io.swagger.v3.oas.models.media.Schema;
import org.testng.annotations.Test;

import javax.validation.constraints.DecimalMax;
import javax.validation.constraints.DecimalMin;
import javax.validation.constraints.Pattern;
Expand Down Expand Up @@ -42,6 +46,82 @@ public void testAnnotatedArray() {
" type: number\n");
}

@Test
public void testAnnotatedArrayProperty() {
final ModelResolver modelResolver = new ModelResolver(mapper()).openapi31(true);
final ModelConverterContextImpl context = new ModelConverterContextImpl(modelResolver);
io.swagger.v3.oas.models.media.Schema model = context.resolve(new AnnotatedType(AnnotatedArrayProperty.class));
SerializationMatchers.assertEqualsToYaml31(model,
"type: object\n" +
"properties:\n" +
" randomList:\n" +
" type: array\n" +
" contains:\n" +
" type: string\n" +
" deprecated: true\n" +
" description: arraydescription\n" +
" examples:\n" +
" - John\n" +
" items:\n" +
" type: string\n" +
" description: itemdescription\n" +
" title: itemtitle\n" +
" maxContains: 10\n" +
" minContains: 1\n" +
" prefixItems:\n" +
" - type: string\n" +
" description: prefixdescription\n" +
" readOnly: true\n" +
" title: arraytitle\n" +
" unevaluatedItems:\n" +
" type: number");
}

@Test
public void testAnnotatedArrayPropertyWriteOnly() {
final ModelResolver modelResolver = new ModelResolver(mapper()).openapi31(true);
final ModelConverterContextImpl context = new ModelConverterContextImpl(modelResolver);
io.swagger.v3.oas.models.media.Schema model = context.resolve(new AnnotatedType(AnnotatedArrayPropertyWriteOnly.class));
SerializationMatchers.assertEqualsToYaml31(model,
"type: object\n" +
"properties:\n" +
" randomList:\n" +
" type: array\n" +
" description: arraydescription\n" +
" examples:\n" +
" - Jane\n" +
" items:\n" +
" type: string\n" +
" description: itemdescription\n" +
" title: itemtitle\n" +
" maxContains: 5\n" +
" minContains: 1\n" +
" title: arraytitle\n" +
" writeOnly: true");
}

@Test
public void testAnnotatedArrayPropertyReadWrite() {
final ModelResolver modelResolver = new ModelResolver(mapper()).openapi31(true);
final ModelConverterContextImpl context = new ModelConverterContextImpl(modelResolver);
io.swagger.v3.oas.models.media.Schema model = context.resolve(new AnnotatedType(AnnotatedArrayPropertyReadWrite.class));
SerializationMatchers.assertEqualsToYaml31(model,
"type: object\n" +
"properties:\n" +
" randomList:\n" +
" type: array\n" +
" description: arraydescription\n" +
" examples:\n" +
" - Bob\n" +
" items:\n" +
" type: string\n" +
" description: itemdescription\n" +
" title: itemtitle\n" +
" maxContains: 8\n" +
" minContains: 2\n" +
" title: arraytitle");
}

@Test
public void testOAS31Fields() {
final ModelResolver modelResolver = new ModelResolver(mapper()).openapi31(true);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package io.swagger.v3.core.resolving.v31.model;

import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Schema;

import java.util.List;

public class AnnotatedArrayProperty {

private List<String> randomList;

@ArraySchema(
schema = @Schema(
types = { "string" },
description = "itemdescription",
title = "itemtitle"

),
arraySchema = @Schema(
description = "arraydescription",
title = "arraytitle",
deprecated = true,
accessMode = Schema.AccessMode.READ_ONLY,
examples = "John"),
maxContains = 10,
minContains = 1,
contains = @Schema(
types = "string"
),
unevaluatedItems = @Schema(
types = "number"
),
prefixItems = {
@Schema(
description = "prefixdescription",
types = "string"
)
}
)
public List<String> getRandomList() {
return randomList;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package io.swagger.v3.core.resolving.v31.model;

import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Schema;

import java.util.List;

public class AnnotatedArrayPropertyReadWrite {

private List<String> randomList;

@ArraySchema(
schema = @Schema(
types = { "string" },
description = "itemdescription",
title = "itemtitle"

),
arraySchema = @Schema(
description = "arraydescription",
title = "arraytitle",
accessMode = Schema.AccessMode.READ_WRITE,
examples = "Bob"),
maxContains = 8,
minContains = 2
)
public List<String> getRandomList() {
return randomList;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package io.swagger.v3.core.resolving.v31.model;

import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Schema;

import java.util.List;

public class AnnotatedArrayPropertyWriteOnly {

private List<String> randomList;

@ArraySchema(
schema = @Schema(
types = { "string" },
description = "itemdescription",
title = "itemtitle"

),
arraySchema = @Schema(
description = "arraydescription",
title = "arraytitle",
accessMode = Schema.AccessMode.WRITE_ONLY,
examples = "Jane"),
maxContains = 5,
minContains = 1
)
public List<String> getRandomList() {
return randomList;
}
}
Loading