2016-08-26 7 views
0

Javaソースの変換のためにスプーンライブラリを初めて使用しました。既存のRESTサービスを変換するためにそれを使用しようとしています。要件は、例えば、クラスレベルでio.swagger.annotations.SwaggerDefinitionアノテーションを追加することです:クラスレベルでAnnotation SwaggerDefinitionを追加する際の問題

@SwaggerDefinition(
     tags = { 
      @Tag(
        name = "api name", description = "api description" 
       ) 
       } 
) 

直面している問題は、私は、注釈を追加していたときに、そのは以下のように追加されていることである:

@SwaggerDefinition(
     tags = 
      @Tag(
        name = "api name", description = "api description" 
       )     
) 

:行方不明中括弧「{」とマッチング閉じ括弧「}」

後は使用されている機能であります

private CtAnnotation createSwaggerDefinitionAnnotation(CtClass<?> ctClass) throws JSONException { 

     CtAnnotation tagAnnotation = createTagAnnotation(ctClass); 

     CtAnnotation swaggerDefAnnotation = getFactory().Core().createAnnotation(); 
     CtTypeReference<Object> ref = getFactory().Core().createTypeReference(); 
     ref.setSimpleName("SwaggerDefinition"); 

     CtPackageReference refPackage = getFactory().Core().createPackageReference(); 
     refPackage.setSimpleName("io.swagger.annotations"); 
     ref.setPackage(refPackage); 
     swaggerDefAnnotation.setAnnotationType(ref); 

     swaggerDefAnnotation.addValue("tags", tagAnnotation); // TODO: The tag should be wrapped in curly braces 

     return swaggerDefAnnotation; 
    } 

private CtAnnotation createTagAnnotation(CtClass<?> ctClass) { 

     String className = ctClass.getQualifiedName(); 

     CtAnnotation tagAnnotation = getFactory().Core().createAnnotation(); 
     CtTypeReference<Object> ref = getFactory().Core().createTypeReference(); 
     ref.setSimpleName("Tag"); 

     CtPackageReference refPackage = getFactory().Core().createPackageReference(); 
     refPackage.setSimpleName("io.swagger.annotations"); 
     ref.setPackage(refPackage); 
     tagAnnotation.setAnnotationType(ref); 

     tagAnnotation.addValue("name", getSwaggerDefinitionTagName(className)); 
     tagAnnotation.addValue("description", getSwaggerDefinitionTagDescription(className)); 
     return tagAnnotation; 
    } 

誰かが欠けている部分を特定できますか?私はそれを理解することができません。

答えて

0

値の周りに括弧を追加するには、注釈の値を含むCtNewArrayを作成する必要があります。

private CtAnnotation createSwaggerDefinitionAnnotation(CtClass<?> ctClass) { 

    CtAnnotation tagAnnotation = createTagAnnotation(ctClass); 

    CtAnnotation swaggerDefAnnotation = getFactory().Core().createAnnotation(); 
    CtTypeReference<Object> ref = getFactory().Core().createTypeReference(); 
    ref.setSimpleName("SwaggerDefinition"); 

    CtPackageReference refPackage = getFactory().Core().createPackageReference(); 
    refPackage.setSimpleName("io.swagger.annotations"); 
    ref.setPackage(refPackage); 
    swaggerDefAnnotation.setAnnotationType(ref); 

    CtNewArray<Object> arrayValue = getFactory().Core().createNewArray(); 
    arrayValue.addElement(tagAnnotation); 
    swaggerDefAnnotation.addValue("tags", arrayValue); 

    return swaggerDefAnnotation; 
} 

出力に含ま:

@io.swagger.annotations.SwaggerDefinition(
tags = { 
    @io.swagger.annotations.Tag(
      description = "description", name = "name") 
}) 
+0

大感謝@Thomas!出来た – sanjay

関連する問題