use of io.swagger.v3.oas.annotations.tags.Tags in project swagger-core by swagger-api.
the class SpecFilterTest method shouldContainAllTopLevelTags.
@Test(description = "it should contain all tags in the top level OpenAPI object")
public void shouldContainAllTopLevelTags() throws IOException {
final OpenAPI openAPI = getOpenAPI(RESOURCE_REFERRED_SCHEMAS);
final NoOpOperationsFilter filter = new NoOpOperationsFilter();
final OpenAPI filtered = new SpecFilter().filter(openAPI, filter, null, null, null);
assertEquals(getTagNames(filtered), Sets.newHashSet(PET_TAG, USER_TAG, STORE_TAG));
}
use of io.swagger.v3.oas.annotations.tags.Tags in project swagger-core by swagger-api.
the class SpecFilterTest method shouldNotContainTopLevelUserTags.
@Test(description = "it should not contain user tags in the top level OpenAPI object")
public void shouldNotContainTopLevelUserTags() throws IOException {
final OpenAPI openAPI = getOpenAPI(RESOURCE_REFERRED_SCHEMAS);
final NoPetOperationsFilter filter = new NoPetOperationsFilter();
final OpenAPI filtered = new SpecFilter().filter(openAPI, filter, null, null, null);
assertEquals(getTagNames(filtered), Sets.newHashSet(USER_TAG, STORE_TAG));
}
use of io.swagger.v3.oas.annotations.tags.Tags in project swagger-core by swagger-api.
the class PatternAndSchemaPropertiesTest method testPatternAndSchemaProperties.
@Test
public void testPatternAndSchemaProperties() throws Exception {
final ModelResolver modelResolver = new ModelResolver(mapper());
ModelConverterContextImpl context = new ModelConverterContextImpl(modelResolver);
Schema model = context.resolve(new AnnotatedType(AnnotatedPet.class));
assertEquals(((Schema) model.getPatternProperties().get("what.*ever")).getFormat(), "int32");
assertEquals(((Schema) model.getPatternProperties().get("it.*takes")).get$ref(), "#/components/schemas/Category");
assertEquals(((Schema) model.getProperties().get("anotherCategory")).get$ref(), "#/components/schemas/Category");
assertEquals(((Schema) model.getProperties().get("anotherInteger")).getFormat(), "int32");
SerializationMatchers.assertEqualsToYaml(context.getDefinedModels(), "AnnotatedPet:\n" + " type: object\n" + " properties:\n" + " id:\n" + " type: integer\n" + " format: int64\n" + " category:\n" + " $ref: '#/components/schemas/Category'\n" + " name:\n" + " type: string\n" + " photoUrls:\n" + " type: array\n" + " xml:\n" + " wrapped: true\n" + " items:\n" + " type: string\n" + " xml:\n" + " name: photoUrl\n" + " tags:\n" + " type: array\n" + " xml:\n" + " wrapped: true\n" + " items:\n" + " $ref: '#/components/schemas/Tag'\n" + " status:\n" + " type: string\n" + " description: pet status in the store\n" + " enum:\n" + " - available\n" + " - pending\n" + " - sold\n" + " anotherCategory:\n" + " $ref: '#/components/schemas/Category'\n" + " anotherInteger:\n" + " maximum: 10\n" + " type: integer\n" + " description: prop schema 1\n" + " format: int32\n" + " description: Annotated Pet\n" + " nullable: true\n" + "Category:\n" + " type: object\n" + " properties:\n" + " id:\n" + " type: integer\n" + " format: int64\n" + " name:\n" + " type: string\n" + " description: prop schema 2\n" + " xml:\n" + " name: Category\n" + "Tag:\n" + " type: object\n" + " properties:\n" + " id:\n" + " type: integer\n" + " format: int64\n" + " name:\n" + " type: string\n" + " xml:\n" + " name: Tag");
context.getDefinedModels().values().forEach(s -> new OpenAPISchema2JsonSchema().process(s));
SerializationMatchers.assertEqualsToYaml31(context.getDefinedModels(), "AnnotatedPet:\n" + " type:\n" + " - object\n" + " - \"null\"\n" + " properties:\n" + " id:\n" + " type: integer\n" + " format: int64\n" + " category:\n" + " $ref: '#/components/schemas/Category'\n" + " name:\n" + " type: string\n" + " photoUrls:\n" + " type: array\n" + " xml:\n" + " wrapped: true\n" + " items:\n" + " type: string\n" + " xml:\n" + " name: photoUrl\n" + " tags:\n" + " type: array\n" + " xml:\n" + " wrapped: true\n" + " items:\n" + " $ref: '#/components/schemas/Tag'\n" + " status:\n" + " type: string\n" + " description: pet status in the store\n" + " enum:\n" + " - available\n" + " - pending\n" + " - sold\n" + " anotherCategory:\n" + " $ref: '#/components/schemas/Category'\n" + " anotherInteger:\n" + " maximum: 10\n" + " type: integer\n" + " description: prop schema 1\n" + " format: int32\n" + " patternProperties:\n" + " what.*ever:\n" + " maximum: 10\n" + " type: integer\n" + " description: prop schema 1\n" + " format: int32\n" + " it.*takes:\n" + " $ref: '#/components/schemas/Category'\n" + " description: Annotated Pet\n" + "Category:\n" + " type: object\n" + " properties:\n" + " id:\n" + " type: integer\n" + " format: int64\n" + " name:\n" + " type: string\n" + " description: prop schema 2\n" + " xml:\n" + " name: Category\n" + "Tag:\n" + " type: object\n" + " properties:\n" + " id:\n" + " type: integer\n" + " format: int64\n" + " name:\n" + " type: string\n" + " xml:\n" + " name: Tag\n");
}
use of io.swagger.v3.oas.annotations.tags.Tags in project swagger-core by swagger-api.
the class ReaderTest method testTicket3149.
@Test(description = "overridden generic resource interface default methods")
public void testTicket3149() {
Reader reader = new Reader(new OpenAPI());
OpenAPI openAPI = reader.read(MainResource.class);
String yaml = "openapi: 3.0.1\n" + "paths:\n" + " /test:\n" + " post:\n" + " tags:\n" + " - Test inheritance on default implementation in interfaces\n" + " operationId: firstEndpoint\n" + " requestBody:\n" + " content:\n" + " '*/*':\n" + " schema:\n" + " $ref: '#/components/schemas/SampleDTO'\n" + " responses:\n" + " \"201\":\n" + " description: Created\n" + " \"400\":\n" + " description: Bad Request\n" + " \"403\":\n" + " description: Forbidden\n" + " \"404\":\n" + " description: Not Found\n" + " /test/{id}:\n" + " get:\n" + " tags:\n" + " - Test inheritance on default implementation in interfaces\n" + " operationId: secondEnpoint\n" + " requestBody:\n" + " content:\n" + " '*/*':\n" + " schema:\n" + " $ref: '#/components/schemas/SampleOtherDTO'\n" + " responses:\n" + " \"200\":\n" + " description: OK\n" + " \"400\":\n" + " description: Bad Request\n" + " \"403\":\n" + " description: Forbidden\n" + " \"404\":\n" + " description: Not Found\n" + " /test/original/{id}:\n" + " get:\n" + " tags:\n" + " - Test inheritance on default implementation in interfaces\n" + " operationId: originalEndpoint\n" + " requestBody:\n" + " content:\n" + " '*/*':\n" + " schema:\n" + " $ref: '#/components/schemas/SampleOtherDTO'\n" + " responses:\n" + " \"200\":\n" + " description: OK\n" + " \"400\":\n" + " description: Bad Request\n" + " \"403\":\n" + " description: Forbidden\n" + " \"404\":\n" + " description: Not Found\n" + "components:\n" + " schemas:\n" + " SampleDTO:\n" + " type: object\n" + " properties:\n" + " name:\n" + " type: string\n" + " SampleOtherDTO:\n" + " type: object\n" + " properties:\n" + " label:\n" + " type: string";
SerializationMatchers.assertEqualsToYaml(openAPI, yaml);
}
use of io.swagger.v3.oas.annotations.tags.Tags in project swagger-core by swagger-api.
the class AnnotationsUtils method getTags.
public static Optional<Set<Tag>> getTags(io.swagger.v3.oas.annotations.tags.Tag[] tags, boolean skipOnlyName) {
if (tags == null) {
return Optional.empty();
}
Set<Tag> tagsList = new LinkedHashSet<>();
for (io.swagger.v3.oas.annotations.tags.Tag tag : tags) {
if (StringUtils.isBlank(tag.name())) {
continue;
}
if (skipOnlyName && StringUtils.isBlank(tag.description()) && StringUtils.isBlank(tag.externalDocs().description()) && StringUtils.isBlank(tag.externalDocs().url())) {
continue;
}
Tag tagObject = new Tag();
if (StringUtils.isNotBlank(tag.description())) {
tagObject.setDescription(tag.description());
}
tagObject.setName(tag.name());
getExternalDocumentation(tag.externalDocs()).ifPresent(tagObject::setExternalDocs);
if (tag.extensions().length > 0) {
Map<String, Object> extensions = AnnotationsUtils.getExtensions(tag.extensions());
if (extensions != null) {
extensions.forEach(tagObject::addExtension);
}
}
tagsList.add(tagObject);
}
if (tagsList.isEmpty()) {
return Optional.empty();
}
return Optional.of(tagsList);
}
Aggregations