Package com.carma.swagger.doclet.translator

Examples of com.carma.swagger.doclet.translator.NameBasedTranslator


    // map of raw field names to translated names, translated names may be different
    // due to annotations like XMLElement
    Map<String, String> rawToTranslatedFields = new HashMap<String, String>();

    NameBasedTranslator nameTranslator = new NameBasedTranslator(this.options);

    for (ClassDoc classDoc : classes) {

      AnnotationParser p = new AnnotationParser(classDoc);
      String xmlAccessorType = p.getAnnotationValue("javax.xml.bind.annotation.XmlAccessorType", "value");

      Set<String> customizedFieldNames = new HashSet<String>();

      // add fields
      Set<String> excludeFields = new HashSet<String>();
      if (!"javax.xml.bind.annotation.XmlAccessType.PROPERTY".equals(xmlAccessorType)) {
        FieldDoc[] fieldDocs = classDoc.fields();

        if (fieldDocs != null) {
          for (FieldDoc field : fieldDocs) {

            // ignore static or transient fields or _ prefixed ones
            if (field.isStatic() || field.isTransient() || field.name().charAt(0) == '_') {
              continue;
            }

            String name = this.translator.fieldName(field).value();
            rawToTranslatedFields.put(field.name(), name);
            if (!field.name().equals(name)) {
              customizedFieldNames.add(field.name());
            }

            // ignore deprecated fields
            if (this.options.isExcludeDeprecatedFields() && ParserHelper.isDeprecated(field)) {
              excludeFields.add(field.name());
              continue;
            }

            // ignore fields we are to explicitly exclude
            if (ParserHelper.hasTag(field, this.options.getExcludeFieldTags())) {
              excludeFields.add(field.name());
              continue;
            }

            // ignore fields that are for a different json view
            ClassDoc[] jsonViews = ParserHelper.getJsonViews(field);
            if (!ParserHelper.isItemPartOfView(this.viewClasses, jsonViews)) {
              excludeFields.add(field.name());
              continue;
            }

            if (name != null && !elements.containsKey(name)) {

              Type fieldType = getModelType(field.type(), nested);

              String description = getFieldDescription(field, true);
              String min = getFieldMin(field);
              String max = getFieldMax(field);
              Boolean required = getFieldRequired(field);
              String defaultValue = getFieldDefaultValue(field);

              String paramCategory = this.composite ? ParserHelper.paramTypeOf(false, this.consumesMultipart, field, fieldType, this.options)
                  : null;

              elements.put(field.name(), new TypeRef(field.name(), paramCategory, " field: " + field.name(), fieldType, description, min, max,
                  defaultValue, required));
            }
          }
        }
      }

      // add methods
      if (!"javax.xml.bind.annotation.XmlAccessType.FIELD".equals(xmlAccessorType)) {
        MethodDoc[] methodDocs = classDoc.methods();
        if (methodDocs != null) {
          for (MethodDoc method : methodDocs) {

            // ignore static methods and private methods
            if (method.isStatic() || method.isPrivate() || method.name().charAt(0) == '_') {
              continue;
            }

            // we tie getters and their corresponding methods together via this rawFieldName
            String rawFieldName = nameTranslator.methodName(method).value();

            String translatedNameViaMethod = this.translator.methodName(method).value();

            if (translatedNameViaMethod != null) {
View Full Code Here


                .rootElement("com.fasterxml.jackson.annotation.JsonRootName", "value"))

        .addNext(
            new AnnotationAwareTranslator(this).ignore("org.codehaus.jackson.map.annotate.JsonIgnore")
                .element("org.codehaus.jackson.map.annotate.JsonProperty", "value")
                .rootElement("org.codehaus.jackson.map.annotate.JsonRootName", "value")).addNext(new NameBasedTranslator(this));

    fnnTranslator.addNext(new NameBasedTranslator(this));

    this.translator = fnnTranslator;
  }
View Full Code Here

TOP

Related Classes of com.carma.swagger.doclet.translator.NameBasedTranslator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.