Search in sources :

Example 21 with Tag

use of io.swagger.v3.jaxrs2.resources.model.Tag in project swagger-parser by swagger-api.

the class OpenAPIDeserializer method getTagList.

public List<Tag> getTagList(ArrayNode obj, String location, ParseResult result) {
    if (obj == null) {
        return null;
    }
    List<Tag> tags = new ArrayList<>();
    Set<String> tagsTracker = new HashSet<>();
    for (JsonNode item : obj) {
        if (item.getNodeType().equals(JsonNodeType.OBJECT)) {
            Tag tag = getTag((ObjectNode) item, location, result);
            if (tag != null) {
                tags.add(tag);
                if (tagsTracker.contains((String) tag.getName())) {
                    result.uniqueTags(location, tag.getName());
                }
                tagsTracker.add(tag.getName());
            }
        }
    }
    return tags;
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) Tag(io.swagger.v3.oas.models.tags.Tag)

Example 22 with Tag

use of io.swagger.v3.jaxrs2.resources.model.Tag in project swagger-parser by swagger-api.

the class SwaggerConverter method convertTags.

private List<Tag> convertTags(List<io.swagger.models.Tag> v2tags) {
    List<Tag> v3tags = new ArrayList<>();
    for (io.swagger.models.Tag v2tag : v2tags) {
        Tag v3tag = new Tag();
        v3tag.setDescription(v2tag.getDescription());
        v3tag.setName(v2tag.getName());
        if (v2tag.getExternalDocs() != null) {
            v3tag.setExternalDocs(convert(v2tag.getExternalDocs()));
        }
        Map<String, Object> extensions = convert(v2tag.getVendorExtensions());
        if (extensions != null) {
            v3tag.setExtensions(extensions);
        }
        v3tags.add(v3tag);
    }
    return v3tags;
}
Also used : ArrayList(java.util.ArrayList) Tag(io.swagger.v3.oas.models.tags.Tag)

Example 23 with Tag

use of io.swagger.v3.jaxrs2.resources.model.Tag in project swagger-parser by swagger-api.

the class OpenAPIResolverTest method testYamlArrayResponseRemoteRefs.

@Test(description = "resolve array response remote refs in yaml")
public void testYamlArrayResponseRemoteRefs() {
    final OpenAPI swagger = new OpenAPI();
    swagger.path("/fun", new PathItem().get(new Operation().responses(new ApiResponses().addApiResponse("200", new ApiResponse().content(new Content().addMediaType("*/*", new MediaType().schema(new ArraySchema().items(new Schema().$ref(replacePort(REMOTE_REF_YAML))))))))));
    final OpenAPI resolved = new OpenAPIResolver(swagger, null).resolve();
    final ApiResponse response = swagger.getPaths().get("/fun").getGet().getResponses().get("200");
    final ArraySchema array = (ArraySchema) response.getContent().get("*/*").getSchema();
    assertNotNull(array.getItems());
    assertEquals(array.getItems().get$ref(), "#/components/schemas/Tag");
    assertNotNull(swagger.getComponents().getSchemas().get("Tag"));
}
Also used : PathItem(io.swagger.v3.oas.models.PathItem) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) Content(io.swagger.v3.oas.models.media.Content) ComposedSchema(io.swagger.v3.oas.models.media.ComposedSchema) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) ObjectSchema(io.swagger.v3.oas.models.media.ObjectSchema) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) Schema(io.swagger.v3.oas.models.media.Schema) MediaType(io.swagger.v3.oas.models.media.MediaType) OpenAPIResolver(io.swagger.v3.parser.OpenAPIResolver) Operation(io.swagger.v3.oas.models.Operation) OpenAPI(io.swagger.v3.oas.models.OpenAPI) ApiResponses(io.swagger.v3.oas.models.responses.ApiResponses) ApiResponse(io.swagger.v3.oas.models.responses.ApiResponse) Test(org.testng.annotations.Test)

Example 24 with Tag

use of io.swagger.v3.jaxrs2.resources.model.Tag in project swagger-parser by swagger-api.

the class OpenAPIResolverTest method testMapRemoteModelProperty.

private void testMapRemoteModelProperty(String remoteRef) {
    final OpenAPI swagger = new OpenAPI();
    swagger.components(new Components().addSchemas("Sample", new Schema().addProperties("remoteRef", new Schema().additionalProperties(new Schema().$ref(remoteRef)))));
    final OpenAPI resolved = new OpenAPIResolver(swagger, null).resolve();
    final Schema prop = (Schema) resolved.getComponents().getSchemas().get("Sample").getProperties().get("remoteRef");
    assertTrue(prop.getAdditionalProperties() != null);
    assertEquals(((Schema) prop.getAdditionalProperties()).get$ref(), "#/components/schemas/Tag");
    assertNotNull(swagger.getComponents().getSchemas().get("Tag"));
}
Also used : Components(io.swagger.v3.oas.models.Components) ComposedSchema(io.swagger.v3.oas.models.media.ComposedSchema) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) ObjectSchema(io.swagger.v3.oas.models.media.ObjectSchema) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) Schema(io.swagger.v3.oas.models.media.Schema) OpenAPIResolver(io.swagger.v3.parser.OpenAPIResolver) OpenAPI(io.swagger.v3.oas.models.OpenAPI)

Example 25 with Tag

use of io.swagger.v3.jaxrs2.resources.model.Tag in project swagger-parser by swagger-api.

the class OpenAPIResolverTest method testArrayRemoteModelProperty.

private void testArrayRemoteModelProperty(String remoteRef) {
    final OpenAPI swagger = new OpenAPI();
    swagger.components(new Components().addSchemas("Sample", new Schema().addProperties("remoteRef", new ArraySchema().items(new Schema().$ref(remoteRef)))));
    final OpenAPI resolved = new OpenAPIResolver(swagger, null).resolve();
    final Schema prop = (Schema) resolved.getComponents().getSchemas().get("Sample").getProperties().get("remoteRef");
    assertTrue(prop instanceof ArraySchema);
    final ArraySchema ap = (ArraySchema) prop;
    assertEquals(ap.getItems().get$ref(), "#/components/schemas/Tag");
    assertNotNull(swagger.getComponents().getSchemas().get("Tag"));
}
Also used : Components(io.swagger.v3.oas.models.Components) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) ComposedSchema(io.swagger.v3.oas.models.media.ComposedSchema) IntegerSchema(io.swagger.v3.oas.models.media.IntegerSchema) StringSchema(io.swagger.v3.oas.models.media.StringSchema) ObjectSchema(io.swagger.v3.oas.models.media.ObjectSchema) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) Schema(io.swagger.v3.oas.models.media.Schema) OpenAPIResolver(io.swagger.v3.parser.OpenAPIResolver) OpenAPI(io.swagger.v3.oas.models.OpenAPI)

Aggregations

OpenAPI (io.swagger.v3.oas.models.OpenAPI)18 Schema (io.swagger.v3.oas.models.media.Schema)14 ArrayList (java.util.ArrayList)13 Tag (io.swagger.v3.oas.models.tags.Tag)12 Test (org.testng.annotations.Test)12 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)11 ObjectSchema (io.swagger.v3.oas.models.media.ObjectSchema)11 StringSchema (io.swagger.v3.oas.models.media.StringSchema)11 ComposedSchema (io.swagger.v3.oas.models.media.ComposedSchema)10 IntegerSchema (io.swagger.v3.oas.models.media.IntegerSchema)10 Operation (io.swagger.v3.oas.models.Operation)9 Components (io.swagger.v3.oas.models.Components)7 PathItem (io.swagger.v3.oas.models.PathItem)7 OpenAPIResolver (io.swagger.v3.parser.OpenAPIResolver)7 MediaType (io.swagger.v3.oas.models.media.MediaType)6 ApiResponse (io.swagger.v3.oas.models.responses.ApiResponse)6 Content (io.swagger.v3.oas.models.media.Content)5 ApiResponses (io.swagger.v3.oas.models.responses.ApiResponses)5 SwaggerParseResult (io.swagger.v3.parser.core.models.SwaggerParseResult)5 HashMap (java.util.HashMap)5