io.swagger.models.ExternalDocs Java Examples

The following examples show how to use io.swagger.models.ExternalDocs. 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: SwaggerDefinitionProcessor.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
private ExternalDocs convertExternalDocs(io.swagger.annotations.ExternalDocs annotationExternalDocs) {
  ExternalDocs externalDocs = new ExternalDocs();

  if (StringUtils.isNotEmpty(annotationExternalDocs.url())) {
    externalDocs.setUrl(annotationExternalDocs.url());
  }
  if (StringUtils.isNotEmpty(annotationExternalDocs.value())) {
    externalDocs.setDescription(annotationExternalDocs.value());
  }

  if (StringUtils.isEmpty(externalDocs.getUrl()) && StringUtils.isEmpty(externalDocs.getDescription())) {
    return null;
  }

  return externalDocs;
}
 
Example #2
Source File: ExternalDocsComponent.java    From swagger2markup with Apache License 2.0 6 votes vote down vote up
@Override
public MarkupDocBuilder apply(MarkupDocBuilder markupDocBuilder, Parameters params) {
    ExternalDocs externalDocs = params.externalDocs;
    String description = externalDocs.getDescription();
    String url = externalDocs.getUrl();
    if ((description != null && (isNotBlank(description) || (url != null && isNotBlank(url))))) {
        markupDocBuilder.sectionTitleLevel(params.titleLevel, labels.getLabel(EXTERNAL_DOCS));
        MarkupDocBuilder paragraph = copyMarkupDocBuilder(markupDocBuilder);

        if (isNotBlank(description)) {
            paragraph.italicText(labels.getLabel(EXTERNAL_DOCS_DESC)).textLine(COLON + description);
        }
        if (isNotBlank(url)) {
            paragraph.italicText(labels.getLabel(EXTERNAL_DOCS_URL)).textLine(COLON + url);
        }

        markupDocBuilder.paragraph(paragraph.toString(), true);
    }

    return markupDocBuilder;
}
 
Example #3
Source File: ExternalDocsComponentTest.java    From swagger2markup with Apache License 2.0 6 votes vote down vote up
@Test
public void testExternalDocsComponent() throws URISyntaxException {
 //Given
 Path file = Paths.get(DefinitionComponentTest.class.getResource("/yaml/swagger_petstore_20160612.yaml").toURI());
 Swagger2MarkupConverter converter = Swagger2MarkupConverter.from(file).build();
 Swagger swagger = converter.getContext().getSchema();

 ExternalDocs externalDocs = swagger.getExternalDocs();
 Assert.assertNotNull(externalDocs);

 Swagger2MarkupConverter.SwaggerContext context = converter.getContext();
 MarkupDocBuilder markupDocBuilder = context.createMarkupDocBuilder();

 //When
 markupDocBuilder = new ExternalDocsComponent(context).apply(markupDocBuilder, ExternalDocsComponent.parameters(externalDocs, OverviewDocument.SECTION_TITLE_LEVEL));
 markupDocBuilder.writeToFileWithoutExtension(outputDirectory, StandardCharsets.UTF_8);

 //Then
 Path expectedFile = getExpectedFile(COMPONENT_NAME);
 DiffUtils.assertThatFileIsEqual(expectedFile, outputDirectory, getReportName(COMPONENT_NAME));

}
 
Example #4
Source File: AbstractDocumentSourceTest.java    From swagger-maven-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void testExternalDocsGetAdded() throws MojoFailureException {
    // arrange
    when(apiSource.getExternalDocs()).thenReturn(new ExternalDocs("Example external docs", "https://example.com/docs"));

    // act
    AbstractDocumentSource externalDocsSource = new AbstractDocumentSource(log, apiSource, null) {
        @Override
        protected ClassSwaggerReader resolveApiReader() throws GenerateException {
            return null;
        }

        @Override
        protected AbstractReader createReader() {
            return null;
        }
    };

    // assert
    assertThat(externalDocsSource.swagger.getExternalDocs(), notNullValue());
    assertThat(externalDocsSource.swagger.getExternalDocs().getDescription(), equalTo("Example external docs"));
    assertThat(externalDocsSource.swagger.getExternalDocs().getUrl(), equalTo("https://example.com/docs"));
}
 
Example #5
Source File: ApiDocV2Service.java    From api-layer with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Updates External documentation in Swagger
 *
 * @param swagger    the API doc
 * @param apiDocInfo the service information
 */
protected void updateExternalDoc(Swagger swagger, ApiDocInfo apiDocInfo) {
    if (apiDocInfo.getApiInfo() == null)
        return;

    String externalDoc = apiDocInfo.getApiInfo().getDocumentationUrl();

    if (externalDoc != null) {
        swagger.setExternalDocs(new ExternalDocs(EXTERNAL_DOCUMENTATION, externalDoc));
    }
}
 
Example #6
Source File: Reader.java    From dorado with Apache License 2.0 5 votes vote down vote up
private void readExternalDocs(Method method, Operation operation) {
	io.swagger.annotations.ExternalDocs externalDocs = ReflectionUtils.getAnnotation(method,
			io.swagger.annotations.ExternalDocs.class);
	if (externalDocs != null) {
		operation.setExternalDocs(new ExternalDocs(externalDocs.value(), externalDocs.url()));
	}
}
 
Example #7
Source File: SwaggerConverter.java    From swagger-parser with Apache License 2.0 5 votes vote down vote up
private ExternalDocumentation convert(ExternalDocs externalDocs) {
    ExternalDocumentation externalDocumentation = new ExternalDocumentation();

    externalDocumentation.setUrl(externalDocs.getUrl());
    externalDocumentation.setDescription(externalDocs.getDescription());
    Map<String, Object> extensions = convert(externalDocs.getVendorExtensions());
    if (extensions != null && extensions.size() > 0) {
        externalDocumentation.setExtensions(extensions);
    }

    return externalDocumentation;
}
 
Example #8
Source File: ApiSourceTest.java    From swagger-maven-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetExternalDocsNoneFound() {
    // given
    @SwaggerDefinition
    class TestClassNoExternalDocs { }

    ApiSource apiSource = spy(ApiSource.class);
    when(apiSource.getValidClasses(SwaggerDefinition.class)).thenReturn(Sets.newHashSet(TestClassNoExternalDocs.class));

    // when
    ExternalDocs externalDocs = apiSource.getExternalDocs();

    // then
    Assert.assertNull(externalDocs);
}
 
Example #9
Source File: Reader.java    From proteus with Apache License 2.0 4 votes vote down vote up
private void readExternalDocs(Method method, Operation operation) {
    io.swagger.annotations.ExternalDocs externalDocs = ReflectionUtils.getAnnotation(method, io.swagger.annotations.ExternalDocs.class);
    if(externalDocs != null) {
        operation.setExternalDocs(new ExternalDocs(externalDocs.value(), externalDocs.url()));
    }
}
 
Example #10
Source File: ExternalDocsComponent.java    From swagger2markup with Apache License 2.0 4 votes vote down vote up
public static ExternalDocsComponent.Parameters parameters(ExternalDocs externalDocs, int titleLevel) {
    return new ExternalDocsComponent.Parameters(externalDocs, titleLevel);
}
 
Example #11
Source File: ExternalDocsComponent.java    From swagger2markup with Apache License 2.0 4 votes vote down vote up
public Parameters(ExternalDocs externalDocs,
                  int titleLevel) {
    this.externalDocs = Validate.notNull(externalDocs, "ExternalDocs must not be null");
    this.titleLevel = titleLevel;
}
 
Example #12
Source File: SwaggerView.java    From poi-tl with Apache License 2.0 4 votes vote down vote up
public ExternalDocs getExternalDocs() {
    return externalDocs;
}
 
Example #13
Source File: SwaggerView.java    From poi-tl with Apache License 2.0 4 votes vote down vote up
public void setExternalDocs(ExternalDocs externalDocs) {
    this.externalDocs = externalDocs;
}
 
Example #14
Source File: ApiSource.java    From swagger-maven-plugin with Apache License 2.0 4 votes vote down vote up
public ExternalDocs getExternalDocs() {
    if (externalDocs == null) {
        setExternalDocsFromAnnotation();
    }
    return externalDocs;
}