Search in sources :

Example 1 with JavadocBlockTag

use of com.github.javaparser.javadoc.JavadocBlockTag in project javaparser by javaparser.

the class JavadocParserTest method parseParamBlockTags.

@Test
public void parseParamBlockTags() {
    String text = EOL + "     * Add a field to this and automatically add the import of the type if needed" + EOL + "     *" + EOL + "     * @param typeClass the type of the field" + EOL + "     * @param name the name of the field" + EOL + "     * @param modifiers the modifiers like {@link Modifier#PUBLIC}" + EOL + "     * @return the {@link FieldDeclaration} created" + EOL + "     ";
    Javadoc res = JavadocParser.parse(text);
    assertEquals(new Javadoc(JavadocDescription.parseText("Add a field to this and automatically add the import of the type if needed")).addBlockTag(JavadocBlockTag.createParamBlockTag("typeClass", "the type of the field")).addBlockTag(JavadocBlockTag.createParamBlockTag("name", "the name of the field")).addBlockTag(JavadocBlockTag.createParamBlockTag("modifiers", "the modifiers like {@link Modifier#PUBLIC}")).addBlockTag(new JavadocBlockTag(JavadocBlockTag.Type.RETURN, "the {@link FieldDeclaration} created")), res);
}
Also used : Javadoc(com.github.javaparser.javadoc.Javadoc) JavadocBlockTag(com.github.javaparser.javadoc.JavadocBlockTag) Test(org.junit.Test)

Example 2 with JavadocBlockTag

use of com.github.javaparser.javadoc.JavadocBlockTag in project javaparser by javaparser.

the class JavadocParserTest method parseBlockTagsAndEmptyDescription.

@Test
public void parseBlockTagsAndEmptyDescription() {
    String text = EOL + "   * @deprecated" + EOL + "   * @see #getEndColumn" + EOL + "   ";
    assertEquals(new Javadoc(JavadocDescription.parseText("")).addBlockTag(new JavadocBlockTag(JavadocBlockTag.Type.DEPRECATED, "")).addBlockTag(new JavadocBlockTag(JavadocBlockTag.Type.SEE, "#getEndColumn")), JavadocParser.parse(text));
}
Also used : Javadoc(com.github.javaparser.javadoc.Javadoc) JavadocBlockTag(com.github.javaparser.javadoc.JavadocBlockTag) Test(org.junit.Test)

Example 3 with JavadocBlockTag

use of com.github.javaparser.javadoc.JavadocBlockTag in project flow by vaadin.

the class OpenAPIObjectGenerator method createRequestBody.

private RequestBody createRequestBody(MethodDeclaration methodDeclaration, ResolvedTypeParametersMap resolvedTypeParametersMap) {
    Map<String, String> paramsDescription = new HashMap<>();
    methodDeclaration.getJavadoc().ifPresent(javadoc -> {
        for (JavadocBlockTag blockTag : javadoc.getBlockTags()) {
            if (blockTag.getType() == JavadocBlockTag.Type.PARAM) {
                paramsDescription.put(blockTag.getName().orElse(""), blockTag.getContent().toText());
            }
        }
    });
    RequestBody requestBody = new RequestBody();
    Content requestBodyContent = new Content();
    requestBody.content(requestBodyContent);
    MediaType requestBodyObject = new MediaType();
    requestBodyContent.addMediaType("application/json", requestBodyObject);
    Schema requestSchema = new ObjectSchema();
    requestSchema.setRequired(new ArrayList<>());
    requestBodyObject.schema(requestSchema);
    methodDeclaration.getParameters().forEach(parameter -> {
        GeneratorType generatorType = createSchemaType(parameter, resolvedTypeParametersMap);
        Schema paramSchema = parseResolvedTypeToSchema(generatorType, parameter.getAnnotations());
        paramSchema.setDescription("");
        usedTypes.putAll(collectUsedTypesFromSchema(paramSchema));
        String name = (isReservedWord(parameter.getNameAsString()) ? "_" : "").concat(parameter.getNameAsString());
        if (GeneratorUtils.isBlank(paramSchema.get$ref())) {
            paramSchema.description(paramsDescription.remove(parameter.getNameAsString()));
        }
        requestSchema.addProperties(name, paramSchema);
        requestSchema.addRequiredItem(name);
    });
    if (!paramsDescription.isEmpty()) {
        requestSchema.addExtension(EXTENSION_VAADIN_CONNECT_PARAMETERS_DESCRIPTION, new LinkedHashMap<>(paramsDescription));
    }
    return requestBody;
}
Also used : ObjectSchema(io.swagger.v3.oas.models.media.ObjectSchema) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Content(io.swagger.v3.oas.models.media.Content) ComposedSchema(io.swagger.v3.oas.models.media.ComposedSchema) ObjectSchema(io.swagger.v3.oas.models.media.ObjectSchema) ArraySchema(io.swagger.v3.oas.models.media.ArraySchema) Schema(io.swagger.v3.oas.models.media.Schema) MapSchema(io.swagger.v3.oas.models.media.MapSchema) MediaType(io.swagger.v3.oas.models.media.MediaType) JavadocBlockTag(com.github.javaparser.javadoc.JavadocBlockTag) RequestBody(io.swagger.v3.oas.models.parameters.RequestBody)

Example 4 with JavadocBlockTag

use of com.github.javaparser.javadoc.JavadocBlockTag in project javaparser by javaparser.

the class JavadocParserTest method parseBlockTagsAndProvideTagName.

@Test
public void parseBlockTagsAndProvideTagName() {
    String expectedText = EOL + "   * @unofficial" + EOL + " " + "   ";
    Javadoc underTest = new Javadoc(JavadocDescription.parseText("")).addBlockTag(new JavadocBlockTag("unofficial", ""));
    assertEquals(underTest, JavadocParser.parse(expectedText));
    assertEquals(1, underTest.getBlockTags().size());
    assertEquals("unofficial", underTest.getBlockTags().get(0).getTagName());
}
Also used : Javadoc(com.github.javaparser.javadoc.Javadoc) JavadocBlockTag(com.github.javaparser.javadoc.JavadocBlockTag) Test(org.junit.Test)

Example 5 with JavadocBlockTag

use of com.github.javaparser.javadoc.JavadocBlockTag in project javaparser by javaparser.

the class JavadocParserTest method parseMultilineParamBlockTags.

@Test
public void parseMultilineParamBlockTags() {
    String text = EOL + "     * Add a field to this and automatically add the import of the type if needed" + EOL + "     *" + EOL + "     * @param typeClass the type of the field" + EOL + "     *     continued in a second line" + EOL + "     * @param name the name of the field" + EOL + "     * @param modifiers the modifiers like {@link Modifier#PUBLIC}" + EOL + "     * @return the {@link FieldDeclaration} created" + EOL + "     ";
    Javadoc res = JavadocParser.parse(text);
    assertEquals(new Javadoc(JavadocDescription.parseText("Add a field to this and automatically add the import of the type if needed")).addBlockTag(JavadocBlockTag.createParamBlockTag("typeClass", "the type of the field" + EOL + "    continued in a second line")).addBlockTag(JavadocBlockTag.createParamBlockTag("name", "the name of the field")).addBlockTag(JavadocBlockTag.createParamBlockTag("modifiers", "the modifiers like {@link Modifier#PUBLIC}")).addBlockTag(new JavadocBlockTag(JavadocBlockTag.Type.RETURN, "the {@link FieldDeclaration} created")), res);
}
Also used : Javadoc(com.github.javaparser.javadoc.Javadoc) JavadocBlockTag(com.github.javaparser.javadoc.JavadocBlockTag) Test(org.junit.Test)

Aggregations

JavadocBlockTag (com.github.javaparser.javadoc.JavadocBlockTag)6 Javadoc (com.github.javaparser.javadoc.Javadoc)4 Test (org.junit.Test)4 Content (io.swagger.v3.oas.models.media.Content)2 MediaType (io.swagger.v3.oas.models.media.MediaType)2 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)1 ComposedSchema (io.swagger.v3.oas.models.media.ComposedSchema)1 MapSchema (io.swagger.v3.oas.models.media.MapSchema)1 ObjectSchema (io.swagger.v3.oas.models.media.ObjectSchema)1 Schema (io.swagger.v3.oas.models.media.Schema)1 RequestBody (io.swagger.v3.oas.models.parameters.RequestBody)1 ApiResponse (io.swagger.v3.oas.models.responses.ApiResponse)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1