Search in sources :

Example 26 with Tags

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));
}
Also used : OpenAPI(io.swagger.v3.oas.models.OpenAPI) NoOpOperationsFilter(io.swagger.v3.core.filter.resources.NoOpOperationsFilter) Test(org.testng.annotations.Test)

Example 27 with Tags

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));
}
Also used : OpenAPI(io.swagger.v3.oas.models.OpenAPI) NoPetOperationsFilter(io.swagger.v3.core.filter.resources.NoPetOperationsFilter) Test(org.testng.annotations.Test)

Example 28 with Tags

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");
}
Also used : AnnotatedType(io.swagger.v3.core.converter.AnnotatedType) OpenAPISchema2JsonSchema(io.swagger.v3.core.util.OpenAPISchema2JsonSchema) OpenAPISchema2JsonSchema(io.swagger.v3.core.util.OpenAPISchema2JsonSchema) Schema(io.swagger.v3.oas.models.media.Schema) AnnotatedPet(io.swagger.v3.core.resolving.v31.model.AnnotatedPet) ModelConverterContextImpl(io.swagger.v3.core.converter.ModelConverterContextImpl) ModelResolver(io.swagger.v3.core.jackson.ModelResolver) Test(org.testng.annotations.Test)

Example 29 with Tags

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);
}
Also used : OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 30 with Tags

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);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ExampleObject(io.swagger.v3.oas.annotations.media.ExampleObject) Tag(io.swagger.v3.oas.models.tags.Tag)

Aggregations

OpenAPI (io.swagger.v3.oas.models.OpenAPI)20 Test (org.testng.annotations.Test)15 ArrayList (java.util.ArrayList)11 Operation (io.swagger.v3.oas.models.Operation)9 PathItem (io.swagger.v3.oas.models.PathItem)8 Schema (io.swagger.v3.oas.models.media.Schema)8 Tag (io.swagger.v3.oas.models.tags.Tag)8 Paths (io.swagger.v3.oas.models.Paths)7 MediaType (io.swagger.v3.oas.models.media.MediaType)5 Parameter (io.swagger.v3.oas.models.parameters.Parameter)5 ApiResponse (io.swagger.v3.oas.models.responses.ApiResponse)5 ApiResponses (io.swagger.v3.oas.models.responses.ApiResponses)5 Callback (io.swagger.v3.oas.models.callbacks.Callback)4 Content (io.swagger.v3.oas.models.media.Content)4 RequestBody (io.swagger.v3.oas.models.parameters.RequestBody)4 SecurityScheme (io.swagger.v3.oas.models.security.SecurityScheme)4 List (java.util.List)4 Map (java.util.Map)4 AnnotatedType (io.swagger.v3.core.converter.AnnotatedType)3 IntegerSchema (io.swagger.v3.oas.models.media.IntegerSchema)3