Java Code Examples for io.swagger.v3.oas.models.OpenAPI#getTags()

The following examples show how to use io.swagger.v3.oas.models.OpenAPI#getTags() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TagDescriptionAsNameOpenAPIFilter.java    From RestDoc with Apache License 2.0 6 votes vote down vote up
@Override
public OpenAPI handle(OpenAPI swagger) {
    if (swagger.getTags() == null) return swagger;

    for (Tag tag : swagger.getTags())
    {
        String newTagName = TextUtils.getFirstLine(tag.getDescription());

        swagger.getPaths().values().forEach(path -> {
            handleOperation(tag, newTagName, path.getGet());
            handleOperation(tag, newTagName, path.getPost());
            handleOperation(tag, newTagName, path.getPut());
            handleOperation(tag, newTagName, path.getDelete());
            handleOperation(tag, newTagName, path.getHead());
            handleOperation(tag, newTagName, path.getOptions());
            handleOperation(tag, newTagName, path.getPatch());
        });

        tag.setName(newTagName);
    }
    return swagger;
}
 
Example 2
Source File: OpenAPIDeserializerTest.java    From swagger-parser with Apache License 2.0 6 votes vote down vote up
@Test(dataProvider = "data")
public void readTagObject(JsonNode rootNode) throws Exception {
    final OpenAPIDeserializer deserializer = new OpenAPIDeserializer();
    final SwaggerParseResult result = deserializer.deserialize(rootNode);

    Assert.assertNotNull(result);

    final OpenAPI openAPI = result.getOpenAPI();
    Assert.assertNotNull(openAPI);

    final List<Tag> Tag = openAPI.getTags();
    Assert.assertNotNull(Tag);
    Assert.assertNotNull(Tag.get(0));
    Assert.assertNotNull(Tag.get(0).getName());
    Assert.assertEquals(Tag.get(0).getName(),"pet");
    Assert.assertNotNull(Tag.get(0).getDescription());
    Assert.assertEquals(Tag.get(0).getDescription(),"Everything about your Pets");
    Assert.assertNotNull(Tag.get(0).getExternalDocs());

    Assert.assertNotNull(Tag.get(1));
    Assert.assertNotNull(Tag.get(1).getName());
    Assert.assertNotNull(Tag.get(1).getDescription());
    Assert.assertEquals(Tag.get(1).getName(),"store");
    Assert.assertEquals(Tag.get(1).getDescription(),"Access to Petstore orders");
}
 
Example 3
Source File: OpenAPISerializer.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(OpenAPI value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
    if (value != null) {
        gen.writeStartObject();
        gen.writeStringField("openapi", value.getOpenapi());
        if(value.getInfo() != null) {
            gen.writeObjectField("info", value.getInfo());
        }
        if(value.getExternalDocs() != null) {
            gen.writeObjectField("externalDocs", value.getExternalDocs());
        }
        if(value.getServers() != null) {
            gen.writeObjectField("servers", value.getServers());
        }
        if(value.getSecurity() != null) {
            gen.writeObjectField("security", value.getSecurity());
        }
        if(value.getTags() != null) {
            gen.writeObjectField("tags", value.getTags());
        }
        if(value.getPaths() != null) {
            gen.writeObjectField("paths", value.getPaths());
        }
        if(value.getComponents() != null) {
            gen.writeObjectField("components", value.getComponents());
        }
        if(value.getExtensions() != null) {
            for (Entry<String, Object> e : value.getExtensions().entrySet()) {
                gen.writeObjectField(e.getKey(), e.getValue());
            }
        }
        gen.writeEndObject();
    }
}
 
Example 4
Source File: BallerinaService.java    From product-microgateway with Apache License 2.0 5 votes vote down vote up
/**
 * Build a {@link BallerinaService} object from a {@link OpenAPI} object.
 * All non iterable objects using handlebars library is converted into
 * supported iterable object types.
 *
 * @param openAPI {@link OpenAPI} type object to be converted
 * @return Converted {@link BallerinaService} object
 */
@Override
public BallerinaService buildContext(OpenAPI openAPI) {
    this.info = openAPI.getInfo();
    this.tags = openAPI.getTags();
    this.containerConfig = CmdUtils.getContainerConfig();
    this.config = CmdUtils.getConfig();

    return this;
}
 
Example 5
Source File: V2ConverterTest.java    From swagger-parser with Apache License 2.0 5 votes vote down vote up
@Test(description = "Tags are missing in the converted spec")
public void testIssue5() throws Exception {
    OpenAPI oas = getConvertedOpenAPIFromJsonFile(PET_STORE_JSON);
    //Global Tags
    List<Tag> tags = oas.getTags();
    assertNotNull(tags);
    assertEquals(PET_TAG, tags.get(0).getName());
    //Operation Tag
    Operation petPut = oas.getPaths().get(PET_PATH).getPut();
    assertNotNull(petPut.getTags());
    assertEquals(PET_TAG, petPut.getTags().get(0));
}
 
Example 6
Source File: V2ConverterTest.java    From swagger-parser with Apache License 2.0 5 votes vote down vote up
@Test(description = "Extensions in External Docs")
public void testIssue12() throws Exception {
    OpenAPI oas = getConvertedOpenAPIFromJsonFile(PET_STORE_JSON);
    for (Tag tag : oas.getTags()) {
        if (tag.getExternalDocs() != null) {
            assertNull(tag.getExternalDocs().getExtensions());
        }
    }
}
 
Example 7
Source File: OpenApiTagsValidator.java    From servicecomb-toolkit with Apache License 2.0 4 votes vote down vote up
@Override
protected List<Tag> getListProperty(OpenAPI oasObject) {
  return oasObject.getTags();
}
 
Example 8
Source File: OpenApiTagsDiffValidator.java    From servicecomb-toolkit with Apache License 2.0 4 votes vote down vote up
@Override
protected List<Tag> getListProperty(OpenAPI oasObject) {
  return oasObject.getTags();
}
 
Example 9
Source File: VaadinConnectTsGenerator.java    From flow with Apache License 2.0 4 votes vote down vote up
@Override
public void preprocessOpenAPI(OpenAPI openAPI) {
    super.processOpenAPI(openAPI);
    List<Tag> openAPITags = openAPI.getTags();
    this.tags = openAPITags != null ? openAPITags : Collections.emptyList();
}