├── .gitignore ├── LICENSE ├── README.md ├── httpdoc-core ├── pom.xml └── src │ └── main │ ├── java │ └── io │ │ └── httpdoc │ │ └── core │ │ ├── Build.java │ │ ├── Category.java │ │ ├── Claxx.java │ │ ├── Config.java │ │ ├── Constant.java │ │ ├── Controller.java │ │ ├── Definition.java │ │ ├── Document.java │ │ ├── Importable.java │ │ ├── Lifecycle.java │ │ ├── Operation.java │ │ ├── Ordered.java │ │ ├── Parameter.java │ │ ├── Preference.java │ │ ├── Property.java │ │ ├── Result.java │ │ ├── Schema.java │ │ ├── Sdk.java │ │ ├── Src.java │ │ ├── annotation │ │ ├── Alias.java │ │ ├── Ignore.java │ │ ├── Name.java │ │ ├── Order.java │ │ ├── Package.java │ │ ├── Skip.java │ │ ├── Style.java │ │ └── Tag.java │ │ ├── appender │ │ ├── AbstractAppender.java │ │ ├── AbstractLineAppender.java │ │ ├── AppendableAppender.java │ │ ├── Appender.java │ │ ├── AppenderWrapper.java │ │ ├── CloseableAppender.java │ │ ├── CommentAppender.java │ │ ├── ConsoleAppender.java │ │ ├── EnterMergedAppender.java │ │ ├── Enterable.java │ │ ├── EnterableAppender.java │ │ ├── FileAppender.java │ │ ├── FilterAppender.java │ │ ├── FilterLineAppender.java │ │ ├── IndentAppender.java │ │ ├── LineAppender.java │ │ ├── LineAppenderWrapper.java │ │ ├── TitleCasedAppender.java │ │ ├── WrappedLineAppender.java │ │ └── WriterAppender.java │ │ ├── conversion │ │ ├── Converter.java │ │ ├── CustomFormat.java │ │ ├── DefaultFormat.java │ │ ├── Format.java │ │ └── StandardConverter.java │ │ ├── deserialization │ │ └── Deserializer.java │ │ ├── exception │ │ ├── DocumentTranslationException.java │ │ ├── HttpdocException.java │ │ ├── HttpdocRuntimeException.java │ │ ├── SchemaDesignException.java │ │ ├── SchemaUnrecognizedException.java │ │ └── SchemaUnsupportedException.java │ │ ├── export │ │ ├── BundleExporter.java │ │ └── Exporter.java │ │ ├── fragment │ │ ├── AssignmentFragment.java │ │ ├── BlockFragment.java │ │ ├── ClassFragment.java │ │ ├── CommentFragment.java │ │ ├── ConstantFragment.java │ │ ├── ConstructorFragment.java │ │ ├── ExceptionFragment.java │ │ ├── FieldFragment.java │ │ ├── Fragment.java │ │ ├── GetterMethodFragment.java │ │ ├── InstanceBlockFragment.java │ │ ├── MethodFragment.java │ │ ├── ModifiedFragment.java │ │ ├── ParameterFragment.java │ │ ├── ResultFragment.java │ │ ├── SetterMethodFragment.java │ │ ├── StaticBlockFragment.java │ │ ├── TypeVariableFragment.java │ │ └── annotation │ │ │ ├── HDAnnotation.java │ │ │ ├── HDAnnotationClass.java │ │ │ ├── HDAnnotationConstant.java │ │ │ ├── HDAnnotationEnum.java │ │ │ ├── HDAnnotationKey.java │ │ │ ├── HDAnnotationPrimary.java │ │ │ └── HDAnnotationString.java │ │ ├── generation │ │ ├── ControllerGenerateContext.java │ │ ├── FragmentGenerator.java │ │ ├── GenerateContext.java │ │ ├── Generation.java │ │ ├── Generator.java │ │ ├── OperationGenerateContext.java │ │ ├── ParameterGenerateContext.java │ │ └── SchemaGenerateContext.java │ │ ├── interpretation │ │ ├── ClassInterpretation.java │ │ ├── DefaultInterpreter.java │ │ ├── EnumInterpretation.java │ │ ├── ExtendedInterpretation.java │ │ ├── FieldInterpretation.java │ │ ├── Interpretation.java │ │ ├── Interpreter.java │ │ ├── MethodInterpretation.java │ │ ├── Note.java │ │ └── SourceInterpreter.java │ │ ├── kit │ │ ├── CollectionKit.java │ │ ├── IOKit.java │ │ ├── LoadKit.java │ │ ├── ReflectionKit.java │ │ └── StringKit.java │ │ ├── modeler │ │ ├── Archetype.java │ │ ├── Modeler.java │ │ └── SimpleModeler.java │ │ ├── picker │ │ ├── AllPicker.java │ │ ├── AnyPicker.java │ │ ├── MixPicker.java │ │ ├── NotPicker.java │ │ ├── PickContext.java │ │ └── Picker.java │ │ ├── reflection │ │ ├── GenericArrayTypeImpl.java │ │ ├── ParameterizedTypeImpl.java │ │ └── WildcardTypeImpl.java │ │ ├── serialization │ │ └── Serializer.java │ │ ├── strategy │ │ ├── BackupStrategy.java │ │ ├── FilterStrategy.java │ │ ├── OverrideStrategy.java │ │ ├── SkipStrategy.java │ │ ├── Strategy.java │ │ └── Task.java │ │ ├── supplier │ │ ├── Supplier.java │ │ └── SystemSupplier.java │ │ ├── translation │ │ ├── AbstractContainer.java │ │ ├── Container.java │ │ ├── Translation.java │ │ └── Translator.java │ │ └── type │ │ ├── HDClass.java │ │ ├── HDGenericArrayType.java │ │ ├── HDParameterizedType.java │ │ ├── HDType.java │ │ ├── HDTypeVariable.java │ │ └── HDWildcardType.java │ └── resources │ └── httpdoc │ ├── converter.properties │ ├── interpreter.properties │ ├── modeler.properties │ └── supplier.properties ├── httpdoc-gson ├── pom.xml └── src │ └── main │ ├── java │ └── io │ │ └── httpdoc │ │ └── gson │ │ ├── deserialization │ │ └── GsonDeserializer.java │ │ └── serialization │ │ └── GsonSerializer.java │ └── resources │ └── httpdoc │ ├── deserializer.properties │ └── serializer.properties ├── httpdoc-jackson ├── pom.xml └── src │ └── main │ ├── java │ └── io │ │ └── httpdoc │ │ └── jackson │ │ ├── deserialization │ │ ├── JsonDeserializer.java │ │ ├── XmlDeserializer.java │ │ └── YamlDeserializer.java │ │ └── serialization │ │ ├── JsonSerializer.java │ │ ├── XmlSerializer.java │ │ └── YamlSerializer.java │ └── resources │ └── httpdoc │ ├── deserializer.properties │ └── serializer.properties ├── httpdoc-jestful-client ├── pom.xml └── src │ └── main │ ├── java │ └── io │ │ └── httpdoc │ │ └── jestful │ │ └── client │ │ ├── JestfulAbstractGenerator.java │ │ ├── JestfulCallbackGenerator.java │ │ ├── JestfulEntityGenerator.java │ │ ├── JestfulExporter.java │ │ ├── JestfulFutureGenerator.java │ │ ├── JestfulGuavaGenerator.java │ │ ├── JestfulHeaderGenerator.java │ │ ├── JestfulJava8Generator.java │ │ ├── JestfulLambdaGenerator.java │ │ ├── JestfulMergedGenerator.java │ │ ├── JestfulMessageGenerator.java │ │ ├── JestfulModeler.java │ │ ├── JestfulRxJavaGenerator.java │ │ ├── JestfulSimpleModeler.java │ │ ├── JestfulStandardGenerator.java │ │ └── JestfulSupplier.java │ └── resources │ ├── httpdoc-sdk │ └── jestful-sdk │ │ ├── pom.xml │ │ └── src │ │ └── test │ │ └── java │ │ └── io │ │ └── httpdoc │ │ └── SDKGenerator.java │ └── httpdoc │ ├── exporter.properties │ ├── generator.properties │ └── modeler.properties ├── httpdoc-jestful-server ├── pom.xml └── src │ └── main │ ├── java │ └── io │ │ └── httpdoc │ │ └── jestful │ │ └── server │ │ ├── ControllerTranslation.java │ │ ├── JestfulHttpdocContainer.java │ │ ├── JestfulHttpdocController.java │ │ ├── JestfulKit.java │ │ ├── JestfulTranslation.java │ │ ├── JestfulTranslator.java │ │ ├── Module.java │ │ ├── OperationTranslation.java │ │ └── ParameterTranslation.java │ └── resources │ ├── httpdoc │ └── translator.properties │ └── io │ └── httpdoc │ └── jestful │ └── server │ └── Module.properties ├── httpdoc-nutz ├── pom.xml └── src │ └── main │ ├── java │ └── io │ │ └── httpdoc │ │ └── nutz │ │ └── NutzTranslator.java │ └── resources │ └── httpdoc │ └── translator.properties ├── httpdoc-objc ├── pom.xml └── src │ └── main │ ├── java │ └── io │ │ └── httpdoc │ │ └── objc │ │ ├── ObjC.java │ │ ├── ObjCExporter.java │ │ ├── ObjCFile.java │ │ ├── ObjCMJExtensionModeler.java │ │ ├── ObjCModeler.java │ │ ├── ObjCRSNetworkingGenerator.java │ │ ├── ObjCSELDefaultNamingStrategy.java │ │ ├── ObjCSELNamingStrategy.java │ │ ├── ObjCSELUnderlineNamingStrategy.java │ │ ├── ObjCSupplier.java │ │ ├── core │ │ ├── ObjCController.java │ │ ├── ObjCDocument.java │ │ ├── ObjCOperation.java │ │ ├── ObjCParameter.java │ │ ├── ObjCProperty.java │ │ ├── ObjCResult.java │ │ └── ObjCSchema.java │ │ ├── external │ │ ├── AFHTTPSessionManager.java │ │ ├── RSCall.java │ │ ├── RSClient.java │ │ ├── RSInvocation.java │ │ └── RSPart.java │ │ ├── foundation │ │ ├── Cbool.java │ │ ├── Cchar.java │ │ ├── Cdouble.java │ │ ├── Cfloat.java │ │ ├── Cid.java │ │ ├── Cinstancetype.java │ │ ├── Cint.java │ │ ├── Clong.java │ │ ├── Cshort.java │ │ ├── Cvoid.java │ │ ├── NSArray.java │ │ ├── NSData.java │ │ ├── NSDate.java │ │ ├── NSDictionary.java │ │ ├── NSError.java │ │ ├── NSNumber.java │ │ ├── NSObject.java │ │ ├── NSString.java │ │ └── NSURL.java │ │ ├── fragment │ │ ├── ObjCBlockFragment.java │ │ ├── ObjCClassHeaderFragment.java │ │ ├── ObjCClassTargetFragment.java │ │ ├── ObjCCommentFragment.java │ │ ├── ObjCEnumDefineFragment.java │ │ ├── ObjCEnumHeaderFragment.java │ │ ├── ObjCEnumTargetFragment.java │ │ ├── ObjCParameterFragment.java │ │ ├── ObjCPropertyFragment.java │ │ ├── ObjCProtocolFragment.java │ │ ├── ObjCResultFragment.java │ │ └── ObjCSelectorFragment.java │ │ └── type │ │ ├── ObjCBlockType.java │ │ ├── ObjCClass.java │ │ ├── ObjCGenericType.java │ │ ├── ObjCProtocolType.java │ │ └── ObjCType.java │ └── resources │ ├── httpdoc-sdk │ └── objc-sdk │ │ ├── AFNetworking │ │ ├── AFCompatibilityMacros.h │ │ ├── AFHTTPSessionManager.h │ │ ├── AFHTTPSessionManager.m │ │ ├── AFNetworkReachabilityManager.h │ │ ├── AFNetworkReachabilityManager.m │ │ ├── AFNetworking.h │ │ ├── AFSecurityPolicy.h │ │ ├── AFSecurityPolicy.m │ │ ├── AFURLRequestSerialization.h │ │ ├── AFURLRequestSerialization.m │ │ ├── AFURLResponseSerialization.h │ │ ├── AFURLResponseSerialization.m │ │ ├── AFURLSessionManager.h │ │ └── AFURLSessionManager.m │ │ ├── MJExtension │ │ ├── MJExtension.h │ │ ├── MJExtensionConst.h │ │ ├── MJExtensionConst.m │ │ ├── MJFoundation.h │ │ ├── MJFoundation.m │ │ ├── MJProperty.h │ │ ├── MJProperty.m │ │ ├── MJPropertyKey.h │ │ ├── MJPropertyKey.m │ │ ├── MJPropertyType.h │ │ ├── MJPropertyType.m │ │ ├── NSObject+MJClass.h │ │ ├── NSObject+MJClass.m │ │ ├── NSObject+MJCoding.h │ │ ├── NSObject+MJCoding.m │ │ ├── NSObject+MJKeyValue.h │ │ ├── NSObject+MJKeyValue.m │ │ ├── NSObject+MJProperty.h │ │ ├── NSObject+MJProperty.m │ │ ├── NSString+MJExtension.h │ │ └── NSString+MJExtension.m │ │ └── RSNetworking │ │ ├── NSArray+RSJoining.h │ │ ├── NSArray+RSJoining.m │ │ ├── NSArray+RSURLEncoder.h │ │ ├── NSArray+RSURLEncoder.m │ │ ├── NSObject+RSJSON.h │ │ ├── NSObject+RSJSON.m │ │ ├── NSObject+RSMultipart.h │ │ ├── NSObject+RSMultipart.m │ │ ├── NSString+RSURLEncoder.h │ │ ├── NSString+RSURLEncoder.m │ │ ├── RSBodyHandler.h │ │ ├── RSBodyHandler.m │ │ ├── RSClient.h │ │ ├── RSClient.m │ │ ├── RSConversion.h │ │ ├── RSConversion.m │ │ ├── RSCookieHandler.h │ │ ├── RSCookieHandler.m │ │ ├── RSErrors.h │ │ ├── RSErrors.m │ │ ├── RSHeaderHandler.h │ │ ├── RSHeaderHandler.m │ │ ├── RSInvocation.h │ │ ├── RSInvocation.m │ │ ├── RSNetworking.h │ │ ├── RSPathHandler.h │ │ ├── RSPathHandler.m │ │ ├── RSQueryHandler.h │ │ ├── RSQueryHandler.m │ │ ├── RSResultHandler.h │ │ └── RSResultHandler.m │ └── httpdoc │ ├── exporter.properties │ ├── modeler.properties │ └── selector-naming-strategy.properties ├── httpdoc-retrofit ├── pom.xml └── src │ └── main │ ├── java │ └── io │ │ └── httpdoc │ │ └── retrofit │ │ ├── RetrofitAbstractGenerator.java │ │ ├── RetrofitCallbackGenerator.java │ │ ├── RetrofitExporter.java │ │ ├── RetrofitMergedGenerator.java │ │ ├── RetrofitModeler.java │ │ ├── RetrofitRxJavaGenerator.java │ │ ├── RetrofitSimpleModeler.java │ │ ├── RetrofitStandardGenerator.java │ │ └── RetrofitSupplier.java │ └── resources │ ├── httpdoc-sdk │ └── retrofit-sdk │ │ ├── pom.xml │ │ └── src │ │ └── test │ │ └── java │ │ └── io │ │ └── httpdoc │ │ └── SDKGenerator.java │ └── httpdoc │ ├── exporter.properties │ ├── generator.properties │ └── modeler.properties ├── httpdoc-retrofit2 ├── pom.xml └── src │ └── main │ ├── java │ └── io │ │ └── httpdoc │ │ └── retrofit2 │ │ ├── Retrofit2AbstractGenerator.java │ │ ├── Retrofit2CallGenerator.java │ │ ├── Retrofit2Exporter.java │ │ ├── Retrofit2GuavaGenerator.java │ │ ├── Retrofit2Java8Generator.java │ │ ├── Retrofit2MergedGenerator.java │ │ ├── Retrofit2Modeler.java │ │ ├── Retrofit2RxJava2Generator.java │ │ ├── Retrofit2RxJavaGenerator.java │ │ ├── Retrofit2SimpleModeler.java │ │ └── Retrofit2Supplier.java │ └── resources │ ├── httpdoc-sdk │ └── retrofit2-sdk │ │ ├── pom.xml │ │ └── src │ │ └── test │ │ └── java │ │ └── io │ │ └── httpdoc │ │ └── SDKGenerator.java │ └── httpdoc │ ├── exporter.properties │ ├── generator.properties │ └── modeler.properties ├── httpdoc-sample ├── pom.xml └── src │ └── main │ ├── java │ └── io │ │ └── httpdoc │ │ └── sample │ │ ├── ApiResult.java │ │ ├── LoginAPI.java │ │ ├── LoginResult.java │ │ ├── order │ │ ├── Order.java │ │ ├── OrderAPI.java │ │ ├── OrderCreateResult.java │ │ └── OrderItem.java │ │ ├── product │ │ ├── Brand.java │ │ ├── Category.java │ │ ├── Product.java │ │ ├── ProductAPI.java │ │ ├── ProductCreateResult.java │ │ ├── ProductDeleteResult.java │ │ ├── ProductQueryResult.java │ │ ├── ProductUpdateResult.java │ │ └── Sku.java │ │ └── user │ │ ├── Gender.java │ │ ├── User.java │ │ ├── UserAPI.java │ │ ├── UserCreateResult.java │ │ ├── UserDeleteResult.java │ │ ├── UserQueryResult.java │ │ └── UserUpdateResult.java │ ├── resources │ └── spring-context.xml │ └── webapp │ ├── WEB-INF │ ├── spring-servlet.xml │ └── web.xml │ └── index.jsp ├── httpdoc-spring-boot ├── pom.xml └── src │ └── main │ └── java │ └── io │ └── httpdoc │ └── spring │ └── boot │ ├── EnableHttpdoc.java │ ├── HttpdocFilterRegistrar.java │ └── Param.java ├── httpdoc-spring-mvc ├── pom.xml └── src │ └── main │ ├── java │ └── io │ │ └── httpdoc │ │ └── spring │ │ └── mvc │ │ ├── ControllerTranslation.java │ │ ├── Module.java │ │ ├── OperationTranslation.java │ │ ├── ParameterTranslation.java │ │ ├── SpringMVCHttpdocContainer.java │ │ ├── SpringMVCHttpdocController.java │ │ ├── SpringMVCTranslation.java │ │ └── SpringMVCTranslator.java │ └── resources │ ├── httpdoc │ └── translator.properties │ └── io │ └── httpdoc │ └── spring │ └── mvc │ └── Module.properties ├── httpdoc-ui ├── pom.xml └── src │ └── main │ └── resources │ └── META-INF │ └── resources │ ├── httpdoc-ui-v1 │ ├── css │ │ ├── bootstrap-3.3.7.min.css │ │ └── httpdoc-1.0.0.css │ ├── fonts │ │ ├── glyphicons-halflings-regular.eot │ │ ├── glyphicons-halflings-regular.svg │ │ ├── glyphicons-halflings-regular.ttf │ │ ├── glyphicons-halflings-regular.woff │ │ └── glyphicons-halflings-regular.woff2 │ ├── index.html │ └── js │ │ ├── autosize-4.0.2.js │ │ ├── bootstrap-3.3.7.min.js │ │ ├── httpdoc-1.0.0.js │ │ ├── jkl-dumper-1.0.0.js │ │ ├── jquery-2.1.1.min.js │ │ ├── mustache.min-3.0.0.js │ │ └── obj-tree-1.0.0.js │ └── httpdoc-ui │ ├── css │ ├── bootstrap-3.3.7.min.css │ └── httpdoc-1.0.0.css │ ├── fonts │ ├── glyphicons-halflings-regular.eot │ ├── glyphicons-halflings-regular.svg │ ├── glyphicons-halflings-regular.ttf │ ├── glyphicons-halflings-regular.woff │ └── glyphicons-halflings-regular.woff2 │ ├── index.html │ └── js │ ├── autosize-4.0.2.js │ ├── bootstrap-3.3.7.min.js │ ├── httpdoc-1.0.0.js │ ├── jkl-dumper-1.0.0.js │ ├── jquery-2.1.1.min.js │ ├── json-editor-v0.7.28.js │ ├── mustache.min-3.0.0.js │ └── obj-tree-1.0.0.js ├── httpdoc-web ├── pom.xml └── src │ └── main │ ├── java │ └── io │ │ └── httpdoc │ │ └── web │ │ ├── Handler.java │ │ ├── HttpdocConversionProvider.java │ │ ├── HttpdocExportHandler.java │ │ ├── HttpdocFilterConfig.java │ │ ├── HttpdocFilterSupport.java │ │ ├── HttpdocMergedTranslator.java │ │ ├── HttpdocServletConfig.java │ │ ├── HttpdocServletSupport.java │ │ ├── HttpdocSuffixSerializer.java │ │ ├── HttpdocThreadLocal.java │ │ ├── HttpdocWebConfig.java │ │ ├── HttpdocWebContainer.java │ │ ├── HttpdocWebSupport.java │ │ ├── Module.java │ │ ├── ZipKit.java │ │ └── conversion │ │ ├── ArrayConverter.java │ │ ├── Conversion.java │ │ ├── ConversionProvider.java │ │ ├── Converter.java │ │ ├── ConvertingException.java │ │ ├── DateConverter.java │ │ ├── EnumConverter.java │ │ ├── ListConverter.java │ │ ├── MapConverter.java │ │ ├── NumberConverter.java │ │ ├── PrimaryConverter.java │ │ ├── SetConverter.java │ │ ├── StandardConversionProvider.java │ │ ├── StringConverter.java │ │ └── WrapperConverter.java │ └── resources │ ├── httpdoc │ └── handler.properties │ └── io │ └── httpdoc │ └── web │ └── Module.properties └── pom.xml /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | *.iml 4 | *.idea 5 | target/ 6 | 7 | # Log file 8 | *.log 9 | 10 | # BlueJ files 11 | *.ctxt 12 | 13 | 14 | # Package Files # 15 | *.jar 16 | *.war 17 | *.ear 18 | *.zip 19 | *.tar.gz 20 | *.rar 21 | 22 | *.bak 23 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/Category.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core; 2 | 3 | /** 4 | * 资源模型类别 5 | * 6 | * @author 杨昌沛 646742615@qq.com 7 | * @date 2018-04-16 13:12 8 | **/ 9 | public enum Category { 10 | 11 | BASIC, DICTIONARY, ARRAY, ENUM, OBJECT 12 | 13 | } 14 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/Claxx.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core; 2 | 3 | /** 4 | * 待生成的类 5 | * 6 | * @author 杨昌沛 646742615@qq.com 7 | * @date 2018-07-04 20:28 8 | **/ 9 | public class Claxx { 10 | private String path; 11 | private Src src; 12 | private Preference preference; 13 | 14 | public Claxx(String path, Src src, Preference preference) { 15 | this.path = path; 16 | this.src = src; 17 | this.preference = preference; 18 | } 19 | 20 | public String getPath() { 21 | return path; 22 | } 23 | 24 | public void setPath(String path) { 25 | this.path = path; 26 | } 27 | 28 | public Src getSrc() { 29 | return src; 30 | } 31 | 32 | public void setSrc(Src src) { 33 | this.src = src; 34 | } 35 | 36 | public Preference getPreference() { 37 | return preference; 38 | } 39 | 40 | public void setPreference(Preference preference) { 41 | this.preference = preference; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/Config.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core; 2 | 3 | import java.util.Enumeration; 4 | 5 | /** 6 | * 配置 7 | * 8 | * @author 杨昌沛 646742615@qq.com 9 | * 2018/11/12 10 | */ 11 | public interface Config { 12 | 13 | String getInitParameter(String name); 14 | 15 | Enumeration getInitParameterNames(); 16 | 17 | } 18 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/Constant.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core; 2 | 3 | /** 4 | * @author 杨昌沛 646742615@qq.com 5 | * @date 2018-04-13 14:16 6 | **/ 7 | public class Constant extends Definition { 8 | private static final long serialVersionUID = 852426625919743178L; 9 | 10 | private String name; 11 | 12 | public Constant() { 13 | } 14 | 15 | public Constant(String name) { 16 | this.name = name; 17 | } 18 | 19 | public Constant(String name, String description) { 20 | this.name = name; 21 | this.description = description; 22 | } 23 | 24 | public String getName() { 25 | return name; 26 | } 27 | 28 | public void setName(String name) { 29 | this.name = name; 30 | } 31 | 32 | @Override 33 | public boolean equals(Object o) { 34 | if (this == o) return true; 35 | if (o == null || getClass() != o.getClass()) return false; 36 | 37 | Constant constant = (Constant) o; 38 | 39 | return name != null ? name.equals(constant.name) : constant.name == null; 40 | } 41 | 42 | @Override 43 | public int hashCode() { 44 | return name != null ? name.hashCode() : 0; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/Definition.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core; 2 | 3 | import java.io.Serializable; 4 | 5 | public class Definition implements Serializable { 6 | private static final long serialVersionUID = -9151357695973200936L; 7 | 8 | protected String description; 9 | 10 | public String getDescription() { 11 | return description; 12 | } 13 | 14 | public void setDescription(String description) { 15 | this.description = description; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/Importable.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core; 2 | 3 | import java.util.Set; 4 | 5 | /** 6 | * 可导入的 7 | * 8 | * @author 杨昌沛 646742615@qq.com 9 | * @date 2018-05-04 10:16 10 | **/ 11 | public interface Importable { 12 | 13 | Set imports(); 14 | 15 | } 16 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/Lifecycle.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core; 2 | 3 | /** 4 | * 生命周期的 5 | * 6 | * @author 杨昌沛 646742615@qq.com 7 | * 2018/11/12 8 | */ 9 | public interface Lifecycle { 10 | 11 | /** 12 | * 初始化 13 | * 14 | * @param config 配置 15 | * @throws Exception 初始化异常 16 | */ 17 | void initial(Config config) throws Exception; 18 | 19 | /** 20 | * 销毁 21 | */ 22 | void destroy(); 23 | 24 | } 25 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/Ordered.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core; 2 | 3 | /** 4 | * 排序的 5 | * 6 | * @author 杨昌沛 646742615@qq.com 7 | * 2018/11/7 8 | */ 9 | public interface Ordered> extends Comparable { 10 | 11 | int getOrder(); 12 | 13 | void setOrder(int order); 14 | 15 | } 16 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/Preference.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core; 2 | 3 | /** 4 | * 代码风格偏好 5 | * 6 | * @author 杨昌沛 646742615@qq.com 7 | * @date 2018-04-28 13:44 8 | **/ 9 | public interface Preference { 10 | 11 | Preference DEFAULT = new Preference() { 12 | @Override 13 | public int getIndent() { 14 | return 4; 15 | } 16 | 17 | @Override 18 | public boolean isAnnotationDefaultValueHidden() { 19 | return true; 20 | } 21 | 22 | @Override 23 | public boolean isAnnotationValueKeyHiddenIfUnnecessary() { 24 | return true; 25 | } 26 | }; 27 | 28 | int getIndent(); 29 | 30 | boolean isAnnotationDefaultValueHidden(); 31 | 32 | boolean isAnnotationValueKeyHiddenIfUnnecessary(); 33 | 34 | } 35 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/Result.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core; 2 | 3 | /** 4 | * 资源操作符结果类型 5 | * 6 | * @author 杨昌沛 646742615@qq.com 7 | * @date 2018-04-12 13:42 8 | **/ 9 | public class Result extends Definition { 10 | private static final long serialVersionUID = -228264825667769977L; 11 | 12 | private Schema type; 13 | 14 | public Schema getType() { 15 | return type; 16 | } 17 | 18 | public void setType(Schema type) { 19 | this.type = type; 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/Sdk.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core; 2 | 3 | public class Sdk { 4 | private String platform; 5 | private String framework; 6 | 7 | public String getPlatform() { 8 | return platform; 9 | } 10 | 11 | public void setPlatform(String platform) { 12 | this.platform = platform; 13 | } 14 | 15 | public String getFramework() { 16 | return framework; 17 | } 18 | 19 | public void setFramework(String framework) { 20 | this.framework = framework; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/Src.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core; 2 | 3 | import io.httpdoc.core.appender.LineAppender; 4 | 5 | import java.io.IOException; 6 | 7 | public interface Src

{ 8 | 9 | > void joinTo(T appender, P preference) throws IOException; 10 | 11 | } 12 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/annotation/Alias.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.annotation; 2 | 3 | import java.lang.annotation.*; 4 | 5 | /** 6 | * 别名, 为了适配不同语言之间有些关键字不同的问题, 通过别名和JSON KEY转换 7 | * 8 | * @author 杨昌沛 646742615@qq.com 9 | * @date 2018-07-12 14:42 10 | **/ 11 | @Target({ElementType.TYPE, ElementType.METHOD, ElementType.PARAMETER}) 12 | @Retention(RetentionPolicy.RUNTIME) 13 | @Documented 14 | public @interface Alias { 15 | 16 | String value(); 17 | 18 | } 19 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/annotation/Ignore.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.annotation; 2 | 3 | import java.lang.annotation.*; 4 | 5 | /** 6 | * 翻译时忽略 7 | * 8 | * @author 杨昌沛 646742615@qq.com 9 | * @date 2018-06-29 15:05 10 | **/ 11 | @Target(ElementType.PARAMETER) 12 | @Retention(RetentionPolicy.RUNTIME) 13 | @Documented 14 | public @interface Ignore { 15 | } 16 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/annotation/Name.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.annotation; 2 | 3 | import java.lang.annotation.*; 4 | 5 | /** 6 | * 重定义翻译名称 7 | * 8 | * @author 杨昌沛 646742615@qq.com 9 | * @date 2018-06-29 15:03 10 | **/ 11 | @Target({ElementType.TYPE, ElementType.METHOD}) 12 | @Retention(RetentionPolicy.RUNTIME) 13 | @Documented 14 | public @interface Name { 15 | 16 | String value(); 17 | 18 | } 19 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/annotation/Order.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.annotation; 2 | 3 | import java.lang.annotation.*; 4 | 5 | /** 6 | * 序号,序号越小越在前面 7 | * 8 | * @author 杨昌沛 646742615@qq.com 9 | * 2018/11/7 10 | */ 11 | @Target({ElementType.TYPE, ElementType.METHOD}) 12 | @Retention(RetentionPolicy.RUNTIME) 13 | @Documented 14 | public @interface Order { 15 | 16 | /** 17 | * @return 序号 18 | */ 19 | int value(); 20 | 21 | } 22 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/annotation/Package.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.annotation; 2 | 3 | import java.lang.annotation.*; 4 | 5 | /** 6 | * 重定义翻译包名 7 | * 8 | * @author 杨昌沛 646742615@qq.com 9 | * @date 2018-06-29 15:05 10 | **/ 11 | @Target(ElementType.TYPE) 12 | @Retention(RetentionPolicy.RUNTIME) 13 | @Documented 14 | public @interface Package { 15 | 16 | String value(); 17 | 18 | } 19 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/annotation/Skip.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.annotation; 2 | 3 | import java.lang.annotation.*; 4 | 5 | /** 6 | * 跳过 7 | * 8 | * @author 杨昌沛 646742615@qq.com 9 | * 2018/11/6 10 | */ 11 | @Target({ElementType.TYPE, ElementType.METHOD}) 12 | @Retention(RetentionPolicy.RUNTIME) 13 | @Documented 14 | public @interface Skip { 15 | } 16 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/annotation/Style.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.annotation; 2 | 3 | import java.lang.annotation.*; 4 | 5 | /** 6 | * 样式 7 | * 8 | * @author 杨昌沛 646742615@qq.com 9 | * @date 2018-07-12 14:42 10 | **/ 11 | @Target({ElementType.TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER}) 12 | @Retention(RetentionPolicy.RUNTIME) 13 | @Documented 14 | public @interface Style { 15 | 16 | /** 17 | * 样式:normal|table|grid 18 | * 19 | * @return 样式 20 | */ 21 | String value(); 22 | 23 | } 24 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/annotation/Tag.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.annotation; 2 | 3 | import java.lang.annotation.*; 4 | 5 | /** 6 | * 所属标签 7 | * 8 | * @author 杨昌沛 646742615@qq.com 9 | * @date 2018-07-12 14:36 10 | **/ 11 | @Target({ElementType.TYPE, ElementType.METHOD}) 12 | @Retention(RetentionPolicy.RUNTIME) 13 | @Documented 14 | public @interface Tag { 15 | 16 | /** 17 | * 如果放在方法上则表明是否覆盖Controller的标签 18 | * 19 | * @return 是否覆盖 20 | */ 21 | boolean override() default true; 22 | 23 | /** 24 | * 所属标签列表 25 | * 26 | * @return 所属标签列表 27 | */ 28 | String[] value(); 29 | 30 | } 31 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/appender/AbstractAppender.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.appender; 2 | 3 | import java.io.IOException; 4 | 5 | /** 6 | * 抽象的拼接器 7 | * 8 | * @author 杨昌沛 646742615@qq.com 9 | * @date 2018-04-27 17:46 10 | **/ 11 | public abstract class AbstractAppender> extends CloseableAppender implements Appender { 12 | 13 | @Override 14 | public T append(CharSequence text) throws IOException { 15 | return append(text, 0, text.length()); 16 | } 17 | 18 | @Override 19 | public T append(CharSequence text, int start, int end) throws IOException { 20 | for (int i = start; i < end; i++) append(text.charAt(i)); 21 | return (T) this; 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/appender/AbstractLineAppender.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.appender; 2 | 3 | import java.io.IOException; 4 | 5 | /** 6 | * 抽象的按行拼接器 7 | * 8 | * @author 杨昌沛 646742615@qq.com 9 | * @date 2018-05-02 13:38 10 | **/ 11 | public abstract class AbstractLineAppender> extends EnterableAppender implements LineAppender { 12 | private volatile StringBuilder buffer = null; 13 | 14 | /** 15 | * 拼接一行 16 | * 17 | * @param line 一行 18 | * @throws IOException IO异常 19 | */ 20 | protected abstract void append(String line) throws IOException; 21 | 22 | @Override 23 | public T append(char c) throws IOException { 24 | validate(); 25 | if (buffer == null) buffer = new StringBuilder(); 26 | switch (c) { 27 | case '\r': 28 | break; 29 | case '\n': 30 | String line = buffer.toString(); 31 | append(line); 32 | buffer.setLength(0); 33 | break; 34 | default: 35 | buffer.append(c); 36 | break; 37 | } 38 | return (T) this; 39 | } 40 | 41 | @Override 42 | public void close() throws IOException { 43 | if (closed) return; 44 | super.close(); 45 | if (buffer == null || buffer.length() == 0) return; 46 | String line = buffer.toString(); 47 | append(line); 48 | buffer.setLength(0); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/appender/AppendableAppender.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.appender; 2 | 3 | import java.io.IOException; 4 | 5 | /** 6 | * Appendable 拼接器 7 | * 8 | * @author 杨昌沛 646742615@qq.com 9 | * @date 2018-04-28 11:06 10 | **/ 11 | public class AppendableAppender extends EnterableAppender implements LineAppender { 12 | private final Appendable appendable; 13 | 14 | public AppendableAppender(Appendable appendable) { 15 | if (appendable == null) throw new NullPointerException(); 16 | this.appendable = appendable; 17 | } 18 | 19 | @Override 20 | public AppendableAppender append(char c) throws IOException { 21 | validate(); 22 | appendable.append(c); 23 | return this; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/appender/Appender.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.appender; 2 | 3 | import java.io.IOException; 4 | 5 | /** 6 | * 拼接器 7 | * 8 | * @author 杨昌沛 646742615@qq.com 9 | * @date 2018-04-27 17:27 10 | **/ 11 | public interface Appender> extends AutoCloseable { 12 | 13 | /** 14 | * 拼接 15 | * 16 | * @param text 文本 17 | * @return {@code this} 18 | * @throws IOException IO异常 19 | */ 20 | T append(CharSequence text) throws IOException; 21 | 22 | /** 23 | * 拼接 24 | * 25 | * @param text 文本 26 | * @param start 起始下标 27 | * @param end 结束下标 28 | * @return {@code this} 29 | * @throws IOException IO异常 30 | */ 31 | T append(CharSequence text, int start, int end) throws IOException; 32 | 33 | /** 34 | * 拼接 35 | * 36 | * @param c 字符 37 | * @return {@code this} 38 | * @throws IOException IO异常 39 | */ 40 | T append(char c) throws IOException; 41 | 42 | /** 43 | * 关闭 44 | * 45 | * @throws IOException IO异常 46 | */ 47 | void close() throws IOException; 48 | 49 | } 50 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/appender/AppenderWrapper.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.appender; 2 | 3 | import java.io.IOException; 4 | 5 | /** 6 | * 拼接器包装器 7 | * 8 | * @author 杨昌沛 646742615@qq.com 9 | * @date 2018-05-02 14:51 10 | **/ 11 | public abstract class AppenderWrapper> extends CloseableAppender implements Appender { 12 | protected final Appender appender; 13 | 14 | protected AppenderWrapper(Appender appender) { 15 | this.appender = appender; 16 | } 17 | 18 | @Override 19 | public T append(CharSequence text) throws IOException { 20 | validate(); 21 | appender.append(text); 22 | return (T) this; 23 | } 24 | 25 | @Override 26 | public T append(CharSequence text, int start, int end) throws IOException { 27 | validate(); 28 | appender.append(text, start, end); 29 | return (T) this; 30 | } 31 | 32 | @Override 33 | public T append(char c) throws IOException { 34 | validate(); 35 | appender.append(c); 36 | return (T) this; 37 | } 38 | 39 | @Override 40 | public void close() throws IOException { 41 | appender.close(); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/appender/CloseableAppender.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.appender; 2 | 3 | import java.io.IOException; 4 | 5 | /** 6 | * 可关闭的拼接器 7 | * 8 | * @author 杨昌沛 646742615@qq.com 9 | * @date 2018-05-02 13:40 10 | **/ 11 | public abstract class CloseableAppender> implements Appender { 12 | protected volatile boolean closed; 13 | 14 | protected void validate() throws IOException { 15 | if (closed) throw new IOException("appender closed"); 16 | } 17 | 18 | @Override 19 | public void close() throws IOException { 20 | closed = true; 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/appender/CommentAppender.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.appender; 2 | 3 | import java.io.IOException; 4 | 5 | /** 6 | * 注释拼接器 7 | * 8 | * @author 杨昌沛 646742615@qq.com 9 | * @date 2018-05-02 14:47 10 | **/ 11 | public class CommentAppender extends LineAppenderWrapper implements LineAppender { 12 | private final LineAppender appender; 13 | 14 | public CommentAppender(LineAppender appender) throws IOException { 15 | super(new WrappedLineAppender(appender, " * ", "")); 16 | this.appender = appender.append("/**").enter(); 17 | } 18 | 19 | @Override 20 | public void close() throws IOException { 21 | if (closed) return; 22 | super.close(); 23 | this.appender.append(" */"); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/appender/ConsoleAppender.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.appender; 2 | 3 | /** 4 | * 控制台拼接器 5 | * 6 | * @author 杨昌沛 646742615@qq.com 7 | * @date 2018-05-02 15:12 8 | **/ 9 | public class ConsoleAppender extends LineAppenderWrapper { 10 | 11 | public ConsoleAppender() { 12 | super(new AppendableAppender(System.out)); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/appender/EnterMergedAppender.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.appender; 2 | 3 | import java.io.IOException; 4 | 5 | /** 6 | * 连续换行忽略拼接器 7 | * 8 | * @author 杨昌沛 646742615@qq.com 9 | * @date 2018-05-07 15:21 10 | **/ 11 | public class EnterMergedAppender extends FilterLineAppender { 12 | private final int max; 13 | private int enter; 14 | 15 | public EnterMergedAppender(LineAppender appender) { 16 | this(appender, 1); 17 | } 18 | 19 | public EnterMergedAppender(LineAppender appender, int max) { 20 | super(appender); 21 | this.max = max; 22 | } 23 | 24 | @Override 25 | public EnterMergedAppender append(char c) throws IOException { 26 | if (c == '\n') { 27 | if (++enter > max) return this; 28 | else return super.append(c); 29 | } else { 30 | enter = 0; 31 | return super.append(c); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/appender/Enterable.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.appender; 2 | 3 | import java.io.IOException; 4 | 5 | /** 6 | * 可回车的 7 | * 8 | * @author 杨昌沛 646742615@qq.com 9 | * @date 2018-05-02 14:19 10 | **/ 11 | public interface Enterable> { 12 | 13 | char CRLF = '\n'; 14 | 15 | /** 16 | * 回车 17 | * 18 | * @return {@code this} 19 | * @throws IOException IO异常 20 | */ 21 | T enter() throws IOException; 22 | 23 | } 24 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/appender/EnterableAppender.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.appender; 2 | 3 | import java.io.IOException; 4 | 5 | /** 6 | * 可回车的拼接器 7 | * 8 | * @author 杨昌沛 646742615@qq.com 9 | * @date 2018-05-02 14:21 10 | **/ 11 | public abstract class EnterableAppender> extends AbstractAppender implements Enterable { 12 | 13 | @Override 14 | public T enter() throws IOException { 15 | return append(CRLF); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/appender/FileAppender.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.appender; 2 | 3 | import io.httpdoc.core.kit.IOKit; 4 | 5 | import java.io.*; 6 | 7 | public class FileAppender extends EnterableAppender implements LineAppender { 8 | private final FileOutputStream fos; 9 | private final OutputStreamWriter osw; 10 | private final BufferedWriter br; 11 | 12 | public FileAppender(String filepath) throws IOException { 13 | this(filepath != null ? new File(filepath) : null); 14 | } 15 | 16 | public FileAppender(File file) throws IOException { 17 | if (file == null) throw new NullPointerException(); 18 | File directory = file.getParentFile(); 19 | if (!directory.exists() && !directory.mkdirs()) throw new IOException("could not create directory : " + directory); 20 | br = new BufferedWriter(osw = new OutputStreamWriter(fos = new FileOutputStream(file))); 21 | } 22 | 23 | @Override 24 | public FileAppender append(char c) throws IOException { 25 | br.write(c); 26 | return this; 27 | } 28 | 29 | @Override 30 | public void close() throws IOException { 31 | super.close(); 32 | if (br != null) br.flush(); 33 | if (osw != null) osw.flush(); 34 | if (fos != null) fos.flush(); 35 | IOKit.close(br); 36 | IOKit.close(osw); 37 | IOKit.close(fos); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/appender/FilterAppender.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.appender; 2 | 3 | import java.io.IOException; 4 | 5 | /** 6 | * 过滤拼接器 7 | * 8 | * @author 杨昌沛 646742615@qq.com 9 | * @date 2018-04-28 15:13 10 | **/ 11 | public abstract class FilterAppender> extends AbstractAppender implements Appender { 12 | protected final Appender appender; 13 | 14 | protected FilterAppender(Appender appender) { 15 | this.appender = appender; 16 | } 17 | 18 | @Override 19 | public T append(char c) throws IOException { 20 | validate(); 21 | appender.append(c); 22 | return (T) this; 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/appender/FilterLineAppender.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.appender; 2 | 3 | import java.io.IOException; 4 | 5 | /** 6 | * 过滤拼接器 7 | * 8 | * @author 杨昌沛 646742615@qq.com 9 | * @date 2018-04-28 15:13 10 | **/ 11 | public abstract class FilterLineAppender> extends AbstractLineAppender implements LineAppender { 12 | protected final LineAppender appender; 13 | 14 | protected FilterLineAppender(LineAppender appender) { 15 | this.appender = appender; 16 | } 17 | 18 | @Override 19 | protected void append(String line) throws IOException { 20 | appender.append(line).enter(); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/appender/IndentAppender.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.appender; 2 | 3 | /** 4 | * 缩进的拼接器 5 | * 6 | * @author 杨昌沛 646742615@qq.com 7 | * @date 2018-04-27 17:32 8 | **/ 9 | public class IndentAppender extends LineAppenderWrapper implements LineAppender { 10 | 11 | public IndentAppender(LineAppender appender, int indent) { 12 | super(wrap(appender, indent)); 13 | } 14 | 15 | private static LineAppender wrap(LineAppender appender, int indent) { 16 | StringBuilder space = new StringBuilder(); 17 | for (int i = 0; i < indent; i++) space.append(" "); 18 | return new WrappedLineAppender(appender, space.toString(), ""); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/appender/LineAppender.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.appender; 2 | 3 | /** 4 | * 按行拼接器 5 | * 6 | * @author 杨昌沛 646742615@qq.com 7 | * @date 2018-05-02 13:35 8 | **/ 9 | public interface LineAppender> extends Appender, Enterable { 10 | 11 | } 12 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/appender/LineAppenderWrapper.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.appender; 2 | 3 | import java.io.IOException; 4 | 5 | /** 6 | * 按行拼接器包装器 7 | * 8 | * @author 杨昌沛 646742615@qq.com 9 | * @date 2018-05-02 14:53 10 | **/ 11 | public abstract class LineAppenderWrapper> extends AppenderWrapper implements LineAppender { 12 | 13 | protected LineAppenderWrapper(LineAppender appender) { 14 | super(appender); 15 | } 16 | 17 | @Override 18 | public T enter() throws IOException { 19 | validate(); 20 | ((LineAppender) appender).enter(); 21 | return (T) this; 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/appender/TitleCasedAppender.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.appender; 2 | 3 | import java.io.IOException; 4 | 5 | /** 6 | * 首字母大写的拼接器 7 | * 8 | * @author 杨昌沛 646742615@qq.com 9 | * @date 2018-07-24 10:03 10 | **/ 11 | public class TitleCasedAppender extends FilterAppender implements LineAppender { 12 | private volatile boolean first = true; 13 | 14 | public TitleCasedAppender(Appender appender) { 15 | super(appender); 16 | } 17 | 18 | @Override 19 | public TitleCasedAppender append(char c) throws IOException { 20 | if (first) { 21 | first = false; 22 | char upper = new String(new char[]{c}).toUpperCase().charAt(0); 23 | return super.append(upper); 24 | } else { 25 | return super.append(c); 26 | } 27 | } 28 | 29 | @Override 30 | public TitleCasedAppender enter() throws IOException { 31 | return append(CRLF); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/appender/WrappedLineAppender.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.appender; 2 | 3 | import java.io.IOException; 4 | 5 | /** 6 | * 包裹的拼接器 7 | * 8 | * @author 杨昌沛 646742615@qq.com 9 | * @date 2018-04-28 15:05 10 | **/ 11 | public class WrappedLineAppender extends FilterLineAppender implements LineAppender { 12 | private final String prefix; 13 | private final String suffix; 14 | 15 | public WrappedLineAppender(LineAppender appender, String prefix, String suffix) { 16 | super(appender); 17 | this.prefix = prefix; 18 | this.suffix = suffix; 19 | } 20 | 21 | @Override 22 | protected void append(String line) throws IOException { 23 | appender.append(prefix); 24 | appender.append(line); 25 | appender.append(suffix); 26 | appender.enter(); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/appender/WriterAppender.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.appender; 2 | 3 | import java.io.IOException; 4 | import java.io.Writer; 5 | 6 | public class WriterAppender extends EnterableAppender implements LineAppender { 7 | private final Writer writer; 8 | 9 | public WriterAppender(Writer writer) { 10 | if (writer == null) throw new NullPointerException(); 11 | this.writer = writer; 12 | } 13 | 14 | @Override 15 | public WriterAppender append(char c) throws IOException { 16 | writer.write(c); 17 | return this; 18 | } 19 | 20 | @Override 21 | public void close() throws IOException { 22 | super.close(); 23 | writer.close(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/conversion/Converter.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.conversion; 2 | 3 | import io.httpdoc.core.Document; 4 | 5 | import java.util.Map; 6 | 7 | /** 8 | * 文档转换器 9 | * 10 | * @author 杨昌沛 646742615@qq.com 11 | * @date 2018-04-17 9:59 12 | **/ 13 | public interface Converter { 14 | 15 | Map convert(Document document); 16 | 17 | Map convert(Document document, Format format); 18 | 19 | Document convert(Map dictionary); 20 | 21 | } 22 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/conversion/DefaultFormat.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.conversion; 2 | 3 | /** 4 | * 默认转换格式 5 | * 6 | * @author 杨昌沛 646742615@qq.com 7 | * @date 2018-04-18 15:10 8 | **/ 9 | public class DefaultFormat implements Format { 10 | private static final long serialVersionUID = 2432350326973481952L; 11 | 12 | @Override 13 | public String getRefPrefix() { 14 | return REF_PREFIX; 15 | } 16 | 17 | @Override 18 | public String getRefSuffix() { 19 | return REF_SUFFIX; 20 | } 21 | 22 | @Override 23 | public String getMapPrefix() { 24 | return MAP_PREFIX; 25 | } 26 | 27 | @Override 28 | public String getMapSuffix() { 29 | return MAP_SUFFIX; 30 | } 31 | 32 | @Override 33 | public String getArrPrefix() { 34 | return ARR_PREFIX; 35 | } 36 | 37 | @Override 38 | public String getArrSuffix() { 39 | return ARR_SUFFIX; 40 | } 41 | 42 | @Override 43 | public boolean isPkgIncluded() { 44 | return false; 45 | } 46 | 47 | @Override 48 | public boolean isCanonical() { 49 | return false; 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/conversion/Format.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.conversion; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * 转换格式 7 | * 8 | * @author 杨昌沛 646742615@qq.com 9 | * @date 2018-04-18 15:07 10 | **/ 11 | public interface Format extends Serializable { 12 | 13 | String REF_PREFIX = "$/schemas/"; 14 | String REF_SUFFIX = ""; 15 | String MAP_PREFIX = "Dictionary deserialize(InputStream in) throws IOException; 17 | 18 | Map deserialize(Reader reader) throws IOException; 19 | 20 | } 21 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/exception/DocumentTranslationException.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.exception; 2 | 3 | /** 4 | * 文档翻译异常 5 | * 6 | * @author 杨昌沛 646742615@qq.com 7 | * @date 2018-04-19 16:05 8 | **/ 9 | public class DocumentTranslationException extends HttpdocException { 10 | private static final long serialVersionUID = -4164428123267841738L; 11 | 12 | public DocumentTranslationException() { 13 | } 14 | 15 | public DocumentTranslationException(String message) { 16 | super(message); 17 | } 18 | 19 | public DocumentTranslationException(String message, Throwable cause) { 20 | super(message, cause); 21 | } 22 | 23 | public DocumentTranslationException(Throwable cause) { 24 | super(cause); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/exception/HttpdocException.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.exception; 2 | 3 | public class HttpdocException extends Exception { 4 | private static final long serialVersionUID = -2890269220183901286L; 5 | 6 | public HttpdocException() { 7 | } 8 | 9 | public HttpdocException(String message) { 10 | super(message); 11 | } 12 | 13 | public HttpdocException(String message, Throwable cause) { 14 | super(message, cause); 15 | } 16 | 17 | public HttpdocException(Throwable cause) { 18 | super(cause); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/exception/HttpdocRuntimeException.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.exception; 2 | 3 | public class HttpdocRuntimeException extends RuntimeException { 4 | private static final long serialVersionUID = -3564185526541821107L; 5 | 6 | public HttpdocRuntimeException() { 7 | } 8 | 9 | public HttpdocRuntimeException(String message) { 10 | super(message); 11 | } 12 | 13 | public HttpdocRuntimeException(String message, Throwable cause) { 14 | super(message, cause); 15 | } 16 | 17 | public HttpdocRuntimeException(Throwable cause) { 18 | super(cause); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/exception/SchemaDesignException.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.exception; 2 | 3 | import io.httpdoc.core.Schema; 4 | import io.httpdoc.core.modeler.Modeler; 5 | 6 | /** 7 | * Schema 不可设计的异常 8 | * 9 | * @author 杨昌沛 646742615@qq.com 10 | * @date 2018-05-18 11:11 11 | **/ 12 | public class SchemaDesignException extends HttpdocRuntimeException { 13 | private static final long serialVersionUID = -4466227061085246982L; 14 | 15 | private final Modeler modeler; 16 | private final Schema schema; 17 | 18 | public SchemaDesignException(Modeler modeler, Schema schema) { 19 | this.modeler = modeler; 20 | this.schema = schema; 21 | } 22 | 23 | public SchemaDesignException(String message, Modeler modeler, Schema schema) { 24 | super(message); 25 | this.modeler = modeler; 26 | this.schema = schema; 27 | } 28 | 29 | public SchemaDesignException(String message, Throwable cause, Modeler modeler, Schema schema) { 30 | super(message, cause); 31 | this.modeler = modeler; 32 | this.schema = schema; 33 | } 34 | 35 | public SchemaDesignException(Throwable cause, Modeler modeler, Schema schema) { 36 | super(cause); 37 | this.modeler = modeler; 38 | this.schema = schema; 39 | } 40 | 41 | public Modeler getModeler() { 42 | return modeler; 43 | } 44 | 45 | public Schema getSchema() { 46 | return schema; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/exception/SchemaUnrecognizedException.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.exception; 2 | 3 | /** 4 | * 无法识别的Schema异常 5 | * 6 | * @author 杨昌沛 646742615@qq.com 7 | * @date 2018-04-17 11:28 8 | **/ 9 | public class SchemaUnrecognizedException extends HttpdocRuntimeException { 10 | private static final long serialVersionUID = -7434306557309703581L; 11 | 12 | private final String name; 13 | 14 | public SchemaUnrecognizedException(String name) { 15 | super("unrecognized schema named " + name); 16 | this.name = name; 17 | } 18 | 19 | public String getName() { 20 | return name; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/exception/SchemaUnsupportedException.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.exception; 2 | 3 | import java.lang.reflect.Type; 4 | 5 | /** 6 | * 不支持的Schema异常 7 | * 8 | * @author 杨昌沛 646742615@qq.com 9 | * @date 2018-04-17 11:28 10 | **/ 11 | public class SchemaUnsupportedException extends HttpdocRuntimeException { 12 | private static final long serialVersionUID = 3199452935883202550L; 13 | 14 | private final Type schema; 15 | 16 | public SchemaUnsupportedException(Type schema) { 17 | super("httpdoc not supports schema [" + schema + "] yet, may be it would be supported in later versions"); 18 | this.schema = schema; 19 | } 20 | 21 | public Type getSchema() { 22 | return schema; 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/export/Exporter.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.export; 2 | 3 | import io.httpdoc.core.Document; 4 | 5 | import java.io.IOException; 6 | 7 | /** 8 | * 导出器 9 | */ 10 | public interface Exporter { 11 | 12 | /** 13 | * @return 平台 14 | */ 15 | String platform(); 16 | 17 | /** 18 | * @return 框架 19 | */ 20 | String framework(); 21 | 22 | /** 23 | * 导出 24 | * 25 | * @param document 文档 26 | * @param folder 导出目录 27 | * @throws IOException I/O 异常 28 | */ 29 | void export(Document document, String folder) throws IOException; 30 | 31 | } 32 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/fragment/AssignmentFragment.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.fragment; 2 | 3 | import io.httpdoc.core.Preference; 4 | import io.httpdoc.core.appender.LineAppender; 5 | 6 | import java.io.IOException; 7 | import java.util.Collections; 8 | import java.util.LinkedHashSet; 9 | import java.util.Set; 10 | 11 | public class AssignmentFragment implements Fragment { 12 | private CharSequence sentence; 13 | private Set imports = new LinkedHashSet<>(); 14 | 15 | public AssignmentFragment() { 16 | } 17 | 18 | public AssignmentFragment(CharSequence sentence) { 19 | this.sentence = sentence; 20 | } 21 | 22 | public AssignmentFragment(CharSequence sentence, Set imports) { 23 | this.sentence = sentence; 24 | this.imports = imports; 25 | } 26 | 27 | @Override 28 | public > void joinTo(T appender, Preference preference) throws IOException { 29 | if (sentence != null && sentence.length() > 0) appender.append(" = ").append(sentence); 30 | } 31 | 32 | @Override 33 | public Set imports() { 34 | return imports != null ? imports : Collections.emptySet(); 35 | } 36 | 37 | public CharSequence getSentence() { 38 | return sentence; 39 | } 40 | 41 | public void setSentence(CharSequence sentence) { 42 | this.sentence = sentence; 43 | } 44 | 45 | public Set getImports() { 46 | return imports; 47 | } 48 | 49 | public void setImports(Set imports) { 50 | this.imports = imports; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/fragment/CommentFragment.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.fragment; 2 | 3 | import io.httpdoc.core.Preference; 4 | import io.httpdoc.core.appender.CommentAppender; 5 | import io.httpdoc.core.appender.LineAppender; 6 | 7 | import java.io.IOException; 8 | import java.util.Collections; 9 | import java.util.LinkedHashSet; 10 | import java.util.Set; 11 | 12 | /** 13 | * 注释碎片 14 | * 15 | * @author 杨昌沛 646742615@qq.com 16 | * @date 2018-04-27 16:41 17 | **/ 18 | public class CommentFragment implements Fragment { 19 | private String content; 20 | private Set imports = new LinkedHashSet<>(); 21 | 22 | public CommentFragment() { 23 | } 24 | 25 | public CommentFragment(String content) { 26 | this.content = content; 27 | } 28 | 29 | public CommentFragment(String content, Set imports) { 30 | this.content = content; 31 | this.imports = imports; 32 | } 33 | 34 | @Override 35 | public > void joinTo(T appender, Preference preference) throws IOException { 36 | if (content == null || content.trim().isEmpty()) return; 37 | new CommentAppender(appender).append(content).close(); 38 | appender.enter(); 39 | } 40 | 41 | @Override 42 | public Set imports() { 43 | return imports != null ? imports : Collections.emptySet(); 44 | } 45 | 46 | public String getContent() { 47 | return content; 48 | } 49 | 50 | public void setContent(String content) { 51 | this.content = content; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/fragment/ConstantFragment.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.fragment; 2 | 3 | import io.httpdoc.core.Preference; 4 | import io.httpdoc.core.appender.LineAppender; 5 | 6 | import java.io.IOException; 7 | import java.util.Collections; 8 | import java.util.Set; 9 | 10 | /** 11 | * 常量碎片 12 | * 13 | * @author 杨昌沛 646742615@qq.com 14 | * @date 2018-05-07 13:59 15 | **/ 16 | public class ConstantFragment implements Fragment { 17 | protected CommentFragment commentFragment; 18 | protected String name; 19 | 20 | public ConstantFragment() { 21 | } 22 | 23 | public ConstantFragment(String name) { 24 | this.name = name; 25 | } 26 | 27 | public ConstantFragment(CommentFragment commentFragment, String name) { 28 | this.commentFragment = commentFragment; 29 | this.name = name; 30 | } 31 | 32 | @Override 33 | public > void joinTo(T appender, Preference preference) throws IOException { 34 | if (commentFragment != null) commentFragment.joinTo(appender, preference); 35 | appender.append(name); 36 | } 37 | 38 | @Override 39 | public Set imports() { 40 | return Collections.emptySet(); 41 | } 42 | 43 | public CommentFragment getCommentFragment() { 44 | return commentFragment; 45 | } 46 | 47 | public void setCommentFragment(CommentFragment commentFragment) { 48 | this.commentFragment = commentFragment; 49 | } 50 | 51 | public String getName() { 52 | return name; 53 | } 54 | 55 | public void setName(String name) { 56 | this.name = name; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/fragment/ConstructorFragment.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.fragment; 2 | 3 | /** 4 | * 构造器碎片 5 | * 6 | * @author 杨昌沛 646742615@qq.com 7 | * @date 2018-04-27 16:36 8 | **/ 9 | public class ConstructorFragment extends MethodFragment { 10 | 11 | public ConstructorFragment() { 12 | } 13 | 14 | public ConstructorFragment(int modifier) { 15 | super(modifier); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/fragment/ExceptionFragment.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.fragment; 2 | 3 | import io.httpdoc.core.Preference; 4 | import io.httpdoc.core.appender.LineAppender; 5 | import io.httpdoc.core.type.HDClass; 6 | 7 | import java.io.IOException; 8 | import java.util.Collections; 9 | import java.util.Set; 10 | 11 | /** 12 | * 异常声明代码碎片 13 | * 14 | * @author 杨昌沛 646742615@qq.com 15 | * @date 2018-07-10 13:16 16 | **/ 17 | public class ExceptionFragment implements Fragment { 18 | private HDClass type; 19 | private String comment; 20 | 21 | public ExceptionFragment() { 22 | } 23 | 24 | public ExceptionFragment(HDClass type) { 25 | this.type = type; 26 | } 27 | 28 | @Override 29 | public Set imports() { 30 | return type != null ? type.imports() : Collections.emptySet(); 31 | } 32 | 33 | @Override 34 | public > void joinTo(T appender, Preference preference) throws IOException { 35 | if (type != null) appender.append(type); 36 | } 37 | 38 | public HDClass getType() { 39 | return type; 40 | } 41 | 42 | public void setType(HDClass type) { 43 | this.type = type; 44 | } 45 | 46 | public String getComment() { 47 | return comment; 48 | } 49 | 50 | public void setComment(String comment) { 51 | this.comment = comment; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/fragment/Fragment.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.fragment; 2 | 3 | import io.httpdoc.core.Importable; 4 | import io.httpdoc.core.Preference; 5 | import io.httpdoc.core.Src; 6 | 7 | /** 8 | * 碎片 9 | * 10 | * @author 杨昌沛 646742615@qq.com 11 | * @date 2018-04-27 16:26 12 | **/ 13 | public interface Fragment extends Src, Importable { 14 | 15 | } 16 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/fragment/GetterMethodFragment.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.fragment; 2 | 3 | import io.httpdoc.core.type.HDType; 4 | 5 | /** 6 | * Getter方法碎片 7 | * 8 | * @author 杨昌沛 646742615@qq.com 9 | * @date 2018-04-27 16:34 10 | **/ 11 | public class GetterMethodFragment extends MethodFragment { 12 | private static final HDType BOOLEAN_TYPE = HDType.valueOf(boolean.class); 13 | 14 | public GetterMethodFragment(HDType type, String name, String alias) { 15 | this.resultFragment = new ResultFragment(type); 16 | this.name = (BOOLEAN_TYPE.equals(type) ? "is" : "get") + name.substring(0, 1).toUpperCase() + name.substring(1); 17 | this.blockFragment = new BlockFragment("return " + alias + ";"); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/fragment/InstanceBlockFragment.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.fragment; 2 | 3 | /** 4 | * 实例代码块碎片 5 | * 6 | * @author 杨昌沛 646742615@qq.com 7 | * @date 2018-04-27 16:38 8 | **/ 9 | public class InstanceBlockFragment extends BlockFragment { 10 | 11 | } 12 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/fragment/SetterMethodFragment.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.fragment; 2 | 3 | import io.httpdoc.core.type.HDType; 4 | 5 | /** 6 | * Setter方法碎片 7 | * 8 | * @author 杨昌沛 646742615@qq.com 9 | * @date 2018-04-27 16:35 10 | **/ 11 | public class SetterMethodFragment extends MethodFragment { 12 | 13 | public SetterMethodFragment(HDType type, String name, String alias) { 14 | this.resultFragment = new ResultFragment(HDType.valueOf(void.class)); 15 | this.name = "set" + name.substring(0, 1).toUpperCase() + name.substring(1); 16 | ParameterFragment parameter = new ParameterFragment(type, alias); 17 | this.parameterFragments.add(parameter); 18 | this.blockFragment = new BlockFragment("this." + alias + " = " + alias + ";"); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/fragment/StaticBlockFragment.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.fragment; 2 | 3 | import io.httpdoc.core.Preference; 4 | import io.httpdoc.core.appender.LineAppender; 5 | 6 | import java.io.IOException; 7 | 8 | /** 9 | * 静待代码块碎片 10 | * 11 | * @author 杨昌沛 646742615@qq.com 12 | * @date 2018-04-27 16:38 13 | **/ 14 | public class StaticBlockFragment extends BlockFragment { 15 | 16 | @Override 17 | public > void joinTo(T appender, Preference preference) throws IOException { 18 | appender.append("static"); 19 | super.joinTo(appender, preference); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/fragment/TypeVariableFragment.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.fragment; 2 | 3 | import io.httpdoc.core.Preference; 4 | import io.httpdoc.core.appender.LineAppender; 5 | import io.httpdoc.core.type.HDTypeVariable; 6 | 7 | import java.io.IOException; 8 | import java.util.Collections; 9 | import java.util.Set; 10 | 11 | /** 12 | * 类型变量代码碎片 13 | * 14 | * @author 杨昌沛 646742615@qq.com 15 | * @date 2018-07-10 13:30 16 | **/ 17 | public class TypeVariableFragment implements Fragment { 18 | private HDTypeVariable typeVariable; 19 | private String comment; 20 | 21 | public TypeVariableFragment() { 22 | } 23 | 24 | public TypeVariableFragment(HDTypeVariable typeVariable) { 25 | this.typeVariable = typeVariable; 26 | } 27 | 28 | @Override 29 | public Set imports() { 30 | return typeVariable != null ? typeVariable.imports() : Collections.emptySet(); 31 | } 32 | 33 | @Override 34 | public > void joinTo(T appender, Preference preference) throws IOException { 35 | if (typeVariable != null) appender.append(typeVariable); 36 | } 37 | 38 | public HDTypeVariable getTypeVariable() { 39 | return typeVariable; 40 | } 41 | 42 | public void setTypeVariable(HDTypeVariable typeVariable) { 43 | this.typeVariable = typeVariable; 44 | } 45 | 46 | public String getComment() { 47 | return comment; 48 | } 49 | 50 | public void setComment(String comment) { 51 | this.comment = comment; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/fragment/annotation/HDAnnotationClass.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.fragment.annotation; 2 | 3 | import io.httpdoc.core.Preference; 4 | import io.httpdoc.core.appender.LineAppender; 5 | import io.httpdoc.core.type.HDClass; 6 | 7 | import java.io.IOException; 8 | import java.util.Set; 9 | 10 | public class HDAnnotationClass extends HDAnnotationConstant { 11 | private final HDClass clazz; 12 | 13 | public HDAnnotationClass(HDClass clazz) { 14 | if (clazz == null) throw new NullPointerException(); 15 | this.clazz = clazz; 16 | } 17 | 18 | public HDAnnotationClass(Class clazz) { 19 | this(clazz != null ? new HDClass(clazz) : null); 20 | } 21 | 22 | public HDAnnotationClass(String className) { 23 | this(className != null ? new HDClass(className) : null); 24 | } 25 | 26 | @Override 27 | public > void joinTo(T appender, Preference preference) throws IOException { 28 | appender.append(clazz).append(".class"); 29 | } 30 | 31 | @Override 32 | public Set imports() { 33 | return clazz.imports(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/fragment/annotation/HDAnnotationEnum.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.fragment.annotation; 2 | 3 | import io.httpdoc.core.Preference; 4 | import io.httpdoc.core.appender.LineAppender; 5 | import io.httpdoc.core.type.HDClass; 6 | 7 | import java.io.IOException; 8 | import java.util.Set; 9 | 10 | public class HDAnnotationEnum extends HDAnnotationConstant { 11 | private final HDClass type; 12 | private final String name; 13 | 14 | public HDAnnotationEnum(HDClass type, String name) { 15 | if (type == null || name == null) throw new NullPointerException(); 16 | if (name.trim().isEmpty()) throw new IllegalArgumentException("enum name is empty or blank"); 17 | this.type = type; 18 | this.name = name; 19 | } 20 | 21 | public HDAnnotationEnum(Enum e) { 22 | this(e != null ? new HDClass(e.getClass()) : null, e != null ? e.name() : null); 23 | } 24 | 25 | @Override 26 | public > void joinTo(T appender, Preference preference) throws IOException { 27 | appender.append(type).append(".").append(name); 28 | } 29 | 30 | @Override 31 | public Set imports() { 32 | return type.imports(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/fragment/annotation/HDAnnotationKey.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.fragment.annotation; 2 | 3 | public class HDAnnotationKey implements CharSequence { 4 | private final String name; 5 | private final boolean original; 6 | 7 | public HDAnnotationKey(String name) { 8 | this(name, false); 9 | } 10 | 11 | public HDAnnotationKey(String name, boolean original) { 12 | if (name == null) throw new NullPointerException(); 13 | this.name = name; 14 | this.original = original; 15 | } 16 | 17 | @Override 18 | public int length() { 19 | return name.length(); 20 | } 21 | 22 | @Override 23 | public char charAt(int index) { 24 | return name.charAt(index); 25 | } 26 | 27 | @Override 28 | public CharSequence subSequence(int beginIndex, int endIndex) { 29 | return name.subSequence(beginIndex, endIndex); 30 | } 31 | 32 | public String getName() { 33 | return name; 34 | } 35 | 36 | public boolean isOriginal() { 37 | return original; 38 | } 39 | 40 | @Override 41 | public boolean equals(Object o) { 42 | if (this == o) return true; 43 | if (o == null || getClass() != o.getClass()) return false; 44 | 45 | HDAnnotationKey that = (HDAnnotationKey) o; 46 | 47 | return name.equals(that.name); 48 | } 49 | 50 | @Override 51 | public int hashCode() { 52 | return name.hashCode(); 53 | } 54 | 55 | @Override 56 | public String toString() { 57 | return name; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/fragment/annotation/HDAnnotationPrimary.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.fragment.annotation; 2 | 3 | import io.httpdoc.core.Preference; 4 | import io.httpdoc.core.appender.LineAppender; 5 | 6 | import java.io.IOException; 7 | import java.util.Collections; 8 | import java.util.Set; 9 | 10 | public class HDAnnotationPrimary extends HDAnnotationConstant { 11 | private final Object primary; 12 | 13 | HDAnnotationPrimary(Object primary) { 14 | this.primary = primary; 15 | } 16 | 17 | public HDAnnotationPrimary(boolean b) { 18 | this.primary = b; 19 | } 20 | 21 | public HDAnnotationPrimary(byte b) { 22 | this.primary = b; 23 | } 24 | 25 | public HDAnnotationPrimary(short s) { 26 | this.primary = s; 27 | } 28 | 29 | public HDAnnotationPrimary(char c) { 30 | this.primary = c; 31 | } 32 | 33 | public HDAnnotationPrimary(int i) { 34 | this.primary = i; 35 | } 36 | 37 | public HDAnnotationPrimary(float f) { 38 | this.primary = f; 39 | } 40 | 41 | public HDAnnotationPrimary(long l) { 42 | this.primary = l; 43 | } 44 | 45 | public HDAnnotationPrimary(double d) { 46 | this.primary = d; 47 | } 48 | 49 | @Override 50 | public > void joinTo(T appender, Preference preference) throws IOException { 51 | appender.append(String.valueOf(primary)); 52 | } 53 | 54 | @Override 55 | public Set imports() { 56 | return Collections.emptySet(); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/fragment/annotation/HDAnnotationString.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.fragment.annotation; 2 | 3 | import io.httpdoc.core.Preference; 4 | import io.httpdoc.core.appender.LineAppender; 5 | 6 | import java.io.IOException; 7 | import java.util.Collections; 8 | import java.util.Set; 9 | 10 | public class HDAnnotationString extends HDAnnotationConstant { 11 | private final String string; 12 | 13 | public HDAnnotationString(String string) { 14 | if (string == null) throw new NullPointerException(); 15 | this.string = string; 16 | } 17 | 18 | @Override 19 | public > void joinTo(T appender, Preference preference) throws IOException { 20 | appender.append("\"").append(string).append("\""); 21 | } 22 | 23 | @Override 24 | public Set imports() { 25 | return Collections.emptySet(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/generation/ControllerGenerateContext.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.generation; 2 | 3 | import io.httpdoc.core.Controller; 4 | 5 | /** 6 | * Controller生成上下文 7 | * 8 | * @author 杨昌沛 646742615@qq.com 9 | * @date 2018-07-10 10:43 10 | **/ 11 | public class ControllerGenerateContext extends GenerateContext { 12 | private final Controller controller; 13 | 14 | public ControllerGenerateContext(Generation generation, Controller controller) { 15 | super(generation); 16 | this.controller = controller; 17 | } 18 | 19 | public Controller getController() { 20 | return controller; 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/generation/GenerateContext.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.generation; 2 | 3 | import io.httpdoc.core.Document; 4 | import io.httpdoc.core.strategy.Strategy; 5 | import io.httpdoc.core.supplier.Supplier; 6 | 7 | /** 8 | * 生成上下文 9 | * 10 | * @author 杨昌沛 646742615@qq.com 11 | * @date 2018-07-10 10:43 12 | **/ 13 | public abstract class GenerateContext { 14 | private final Generation generation; 15 | 16 | public GenerateContext(Generation generation) { 17 | this.generation = generation; 18 | } 19 | 20 | public Generation getGeneration() { 21 | return generation; 22 | } 23 | 24 | public Document getDocument() { 25 | return generation.getDocument(); 26 | } 27 | 28 | public String getDirectory() { 29 | return generation.getDirectory(); 30 | } 31 | 32 | public String getPkg() { 33 | return generation.getPkg(); 34 | } 35 | 36 | public boolean isPkgForced() { 37 | return generation.isPkgForced(); 38 | } 39 | 40 | public Supplier getSupplier() { 41 | return generation.getSupplier(); 42 | } 43 | 44 | public Strategy getStrategy() { 45 | return generation.getStrategy(); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/generation/Generator.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.generation; 2 | 3 | import java.io.IOException; 4 | 5 | /** 6 | * 代码生成器 7 | * 8 | * @author 杨昌沛 646742615@qq.com 9 | * @date 2018-04-19 15:48 10 | **/ 11 | public interface Generator { 12 | 13 | void generate(Generation generation) throws IOException; 14 | 15 | } 16 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/generation/OperationGenerateContext.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.generation; 2 | 3 | import io.httpdoc.core.Controller; 4 | import io.httpdoc.core.Operation; 5 | 6 | /** 7 | * Operation生成上下文 8 | * 9 | * @author 杨昌沛 646742615@qq.com 10 | * @date 2018-07-10 10:53 11 | **/ 12 | public class OperationGenerateContext extends ControllerGenerateContext { 13 | private final Operation operation; 14 | 15 | public OperationGenerateContext(Generation generation, Controller controller, Operation operation) { 16 | super(generation, controller); 17 | this.operation = operation; 18 | } 19 | 20 | public Operation getOperation() { 21 | return operation; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/generation/ParameterGenerateContext.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.generation; 2 | 3 | import io.httpdoc.core.Controller; 4 | import io.httpdoc.core.Operation; 5 | import io.httpdoc.core.Parameter; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * Parameter生成上下文 11 | * 12 | * @author 杨昌沛 646742615@qq.com 13 | * @date 2018-07-10 11:23 14 | **/ 15 | public class ParameterGenerateContext extends OperationGenerateContext { 16 | private final List parameters; 17 | 18 | public ParameterGenerateContext(Generation generation, Controller controller, Operation operation, List parameters) { 19 | super(generation, controller, operation); 20 | this.parameters = parameters; 21 | } 22 | 23 | public List getParameters() { 24 | return parameters; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/generation/SchemaGenerateContext.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.generation; 2 | 3 | import io.httpdoc.core.Schema; 4 | 5 | /** 6 | * Schema生成上下文 7 | * 8 | * @author 杨昌沛 646742615@qq.com 9 | * @date 2018-07-10 10:45 10 | **/ 11 | public class SchemaGenerateContext extends GenerateContext { 12 | private final Schema schema; 13 | 14 | public SchemaGenerateContext(Generation generation, Schema schema) { 15 | super(generation); 16 | this.schema = schema; 17 | } 18 | 19 | public Schema getSchema() { 20 | return schema; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/interpretation/ClassInterpretation.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.interpretation; 2 | 3 | /** 4 | * 类型注释 5 | * 6 | * @author 杨昌沛 646742615@qq.com 7 | * @date 2018-04-20 17:04 8 | **/ 9 | public class ClassInterpretation extends ExtendedInterpretation { 10 | 11 | public ClassInterpretation(String content, Note[] notes, String text) { 12 | super(content, notes, text); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/interpretation/DefaultInterpreter.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.interpretation; 2 | 3 | import java.beans.PropertyDescriptor; 4 | import java.lang.reflect.Field; 5 | import java.lang.reflect.Method; 6 | 7 | public class DefaultInterpreter implements Interpreter { 8 | 9 | @Override 10 | public ClassInterpretation interpret(Class clazz) { 11 | return null; 12 | } 13 | 14 | @Override 15 | public MethodInterpretation interpret(Method method) { 16 | return null; 17 | } 18 | 19 | @Override 20 | public FieldInterpretation interpret(Field field) { 21 | return null; 22 | } 23 | 24 | @Override 25 | public EnumInterpretation interpret(Enum constant) { 26 | return null; 27 | } 28 | 29 | @Override 30 | public FieldInterpretation interpret(PropertyDescriptor descriptor) { 31 | return null; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/interpretation/EnumInterpretation.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.interpretation; 2 | 3 | /** 4 | * 枚举常量解释 5 | * 6 | * @author 杨昌沛 646742615@qq.com 7 | * @date 2018-04-20 17:28 8 | **/ 9 | public class EnumInterpretation extends ExtendedInterpretation { 10 | 11 | public EnumInterpretation(String content, Note[] notes, String text) { 12 | super(content, notes, text); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/interpretation/FieldInterpretation.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.interpretation; 2 | 3 | /** 4 | * 字段解释 5 | * 6 | * @author 杨昌沛 646742615@qq.com 7 | * @date 2018-04-20 17:14 8 | **/ 9 | public class FieldInterpretation extends ExtendedInterpretation { 10 | 11 | public FieldInterpretation(String content, Note[] notes, String text) { 12 | super(content, notes, text); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/interpretation/Interpretation.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.interpretation; 2 | 3 | /** 4 | * 注释 5 | * 6 | * @author 杨昌沛 646742615@qq.com 7 | * @date 2018-04-20 16:55 8 | **/ 9 | public class Interpretation { 10 | protected final String content; 11 | protected final Note[] notes; 12 | protected final String text; 13 | 14 | protected Interpretation(String content, Note[] notes, String text) { 15 | this.content = content; 16 | this.notes = notes; 17 | this.text = text; 18 | } 19 | 20 | public String getContent() { 21 | return content; 22 | } 23 | 24 | public Note[] getNotes() { 25 | return notes; 26 | } 27 | 28 | public String getText() { 29 | return text; 30 | } 31 | 32 | @Override 33 | public String toString() { 34 | return String.valueOf(text); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/interpretation/Interpreter.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.interpretation; 2 | 3 | import java.beans.PropertyDescriptor; 4 | import java.lang.reflect.Field; 5 | import java.lang.reflect.Method; 6 | 7 | public interface Interpreter { 8 | 9 | ClassInterpretation interpret(Class clazz); 10 | 11 | MethodInterpretation interpret(Method method); 12 | 13 | FieldInterpretation interpret(Field field); 14 | 15 | EnumInterpretation interpret(Enum constant); 16 | 17 | Interpretation interpret(PropertyDescriptor descriptor); 18 | 19 | } 20 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/interpretation/MethodInterpretation.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.interpretation; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | /** 7 | * 方法解释 8 | * 9 | * @author 杨昌沛 646742615@qq.com 10 | * @date 2018-04-20 17:14 11 | **/ 12 | public class MethodInterpretation extends ExtendedInterpretation { 13 | 14 | public MethodInterpretation(String content, Note[] notes, String text) { 15 | super(content, notes, text); 16 | } 17 | 18 | public Note getReturnNote() { 19 | for (int i = 0; notes != null && i < notes.length; i++) if ("@return".equals(notes[i].getKind())) return notes[i]; 20 | return null; 21 | } 22 | 23 | public Note[] getParamNotes() { 24 | List list = new ArrayList<>(); 25 | for (int i = 0; notes != null && i < notes.length; i++) if ("@param".equals(notes[i].getKind())) list.add(notes[i]); 26 | return list.toArray(new Note[0]); 27 | } 28 | 29 | public Note[] getThrowsNotes() { 30 | List list = new ArrayList<>(); 31 | for (int i = 0; notes != null && i < notes.length; i++) if ("@throws".equals(notes[i].getKind())) list.add(notes[i]); 32 | return list.toArray(new Note[0]); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/interpretation/Note.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.interpretation; 2 | 3 | /** 4 | * 注释标签 5 | * 6 | * @author 杨昌沛 646742615@qq.com 7 | * @date 2018-04-20 16:55 8 | **/ 9 | public class Note { 10 | private String kind; 11 | private String name; 12 | private String text; 13 | 14 | public Note() { 15 | } 16 | 17 | public Note(String kind, String name, String text) { 18 | this.kind = kind; 19 | this.name = name; 20 | this.text = text; 21 | } 22 | 23 | public String getKind() { 24 | return kind; 25 | } 26 | 27 | public void setKind(String kind) { 28 | this.kind = kind; 29 | } 30 | 31 | public String getName() { 32 | return name; 33 | } 34 | 35 | public void setName(String name) { 36 | this.name = name; 37 | } 38 | 39 | public String getText() { 40 | return text; 41 | } 42 | 43 | public void setText(String text) { 44 | this.text = text; 45 | } 46 | 47 | @Override 48 | public String toString() { 49 | return String.valueOf(text); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/kit/CollectionKit.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.kit; 2 | 3 | import java.util.ArrayList; 4 | import java.util.LinkedHashSet; 5 | import java.util.List; 6 | import java.util.Set; 7 | 8 | public abstract class CollectionKit { 9 | 10 | public static List merge(List... lists) { 11 | List merged = new ArrayList<>(); 12 | for (List list : lists) merged.addAll(list); 13 | return merged; 14 | } 15 | 16 | public static Set merge(Set... sets) { 17 | Set merged = new LinkedHashSet<>(); 18 | for (Set list : sets) merged.addAll(list); 19 | return merged; 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/kit/StringKit.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.kit; 2 | 3 | public class StringKit { 4 | 5 | public static boolean isEmpty(String value) { 6 | return value == null || value.length() == 0; 7 | } 8 | 9 | public static boolean isBlank(String value) { 10 | return value == null || value.trim().length() == 0; 11 | } 12 | 13 | public static String join(char c, String... values) { 14 | StringBuilder builder = new StringBuilder(); 15 | for (String value : values) { 16 | if (builder.length() > 0) builder.append(c); 17 | builder.append(value); 18 | } 19 | return builder.toString(); 20 | } 21 | 22 | } -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/modeler/Modeler.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.modeler; 2 | 3 | import io.httpdoc.core.exception.SchemaDesignException; 4 | 5 | import java.util.Collection; 6 | 7 | /** 8 | * 模型师 9 | * 10 | * @author 杨昌沛 646742615@qq.com 11 | * @date 2018-05-18 10:48 12 | **/ 13 | public interface Modeler { 14 | 15 | /** 16 | * 设计 17 | * 18 | * @param archetype 原型 19 | * @return 模型 20 | * @throws SchemaDesignException Schema 不可设计的异常 21 | */ 22 | Collection design(Archetype archetype) throws SchemaDesignException; 23 | 24 | } 25 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/picker/AllPicker.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.picker; 2 | 3 | import java.util.Collection; 4 | 5 | /** 6 | * 与门逻辑混合挑选器 7 | * 8 | * @author Payne 646742615@qq.com 9 | * 2019/5/11 11:32 10 | */ 11 | public class AllPicker extends MixPicker { 12 | 13 | public AllPicker() { 14 | } 15 | 16 | public AllPicker(Collection pickers) { 17 | super(pickers); 18 | } 19 | 20 | @Override 21 | public MixPicker mix(Picker picker) { 22 | add(picker); 23 | return this; 24 | } 25 | 26 | @Override 27 | public boolean pick(PickContext pickContext) { 28 | Picker[] pickers = this.pickers.toArray(new Picker[0]); 29 | for (Picker picker : pickers) { 30 | if (!picker.pick(pickContext)) { 31 | return false; 32 | } 33 | } 34 | return true; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/picker/AnyPicker.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.picker; 2 | 3 | import java.util.Collection; 4 | 5 | /** 6 | * 或门逻辑混合挑选器 7 | * 8 | * @author Payne 646742615@qq.com 9 | * 2019/5/11 11:32 10 | */ 11 | public class AnyPicker extends MixPicker { 12 | 13 | public AnyPicker() { 14 | } 15 | 16 | public AnyPicker(Collection pickers) { 17 | super(pickers); 18 | } 19 | 20 | @Override 21 | public MixPicker mix(Picker picker) { 22 | add(picker); 23 | return this; 24 | } 25 | 26 | @Override 27 | public boolean pick(PickContext pickContext) { 28 | Picker[] pickers = this.pickers.toArray(new Picker[0]); 29 | for (Picker picker : pickers) { 30 | if (picker.pick(pickContext)) { 31 | return true; 32 | } 33 | } 34 | return false; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/picker/MixPicker.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.picker; 2 | 3 | import java.util.Collection; 4 | import java.util.LinkedHashSet; 5 | import java.util.Set; 6 | 7 | /** 8 | * 混合挑选器 9 | * 10 | * @author Payne 646742615@qq.com 11 | * 2019/5/11 11:29 12 | */ 13 | public abstract class MixPicker implements Picker { 14 | protected final Set pickers; 15 | 16 | protected MixPicker() { 17 | this(null); 18 | } 19 | 20 | protected MixPicker(Collection pickers) { 21 | this.pickers = pickers != null ? new LinkedHashSet<>(pickers) : new LinkedHashSet(); 22 | } 23 | 24 | public boolean add(Picker picker) { 25 | return pickers.add(picker); 26 | } 27 | 28 | public boolean remove(Picker picker) { 29 | return pickers.remove(picker); 30 | } 31 | 32 | public abstract MixPicker mix(Picker picker); 33 | 34 | } 35 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/picker/NotPicker.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.picker; 2 | 3 | /** 4 | * 非门逻辑混合挑选器 5 | * 6 | * @author Payne 646742615@qq.com 7 | * 2019/5/11 11:35 8 | */ 9 | public class NotPicker implements Picker { 10 | private final Picker delegate; 11 | 12 | public NotPicker(Picker delegate) { 13 | this.delegate = delegate; 14 | } 15 | 16 | @Override 17 | public boolean pick(PickContext pickContext) { 18 | return !delegate.pick(pickContext); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/picker/PickContext.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.picker; 2 | 3 | import io.httpdoc.core.Controller; 4 | import io.httpdoc.core.Operation; 5 | import io.httpdoc.core.translation.Translation; 6 | 7 | /** 8 | * 挑选上下文 9 | * 10 | * @author Payne 646742615@qq.com 11 | * 2019/5/11 11:23 12 | */ 13 | public class PickContext { 14 | private final Translation translation; 15 | private final Controller controller; 16 | private final Operation operation; 17 | 18 | public PickContext(Translation translation, Controller controller, Operation operation) { 19 | this.translation = translation; 20 | this.controller = controller; 21 | this.operation = operation; 22 | } 23 | 24 | public Translation getTranslation() { 25 | return translation; 26 | } 27 | 28 | public Controller getController() { 29 | return controller; 30 | } 31 | 32 | public Operation getOperation() { 33 | return operation; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/picker/Picker.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.picker; 2 | 3 | /** 4 | * 挑选器 5 | * 6 | * @author Payne 646742615@qq.com 7 | * 2019/5/11 11:14 8 | */ 9 | public interface Picker { 10 | 11 | /** 12 | * 全挑选 13 | */ 14 | Picker ALL = new Picker() { 15 | @Override 16 | public boolean pick(PickContext pickContext) { 17 | return true; 18 | } 19 | }; 20 | 21 | /** 22 | * 挑选 23 | * 24 | * @param pickContext 挑选上下文 25 | * @return 是否挑出 26 | */ 27 | boolean pick(PickContext pickContext); 28 | 29 | } 30 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/reflection/GenericArrayTypeImpl.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.reflection; 2 | 3 | import java.lang.reflect.GenericArrayType; 4 | import java.lang.reflect.Type; 5 | 6 | /** 7 | * 泛型数组类型 8 | * 9 | * @author 杨昌沛 646742615@qq.com 10 | * @date 2018-05-15 9:37 11 | **/ 12 | public class GenericArrayTypeImpl implements GenericArrayType { 13 | private final Type genericComponentType; 14 | 15 | public GenericArrayTypeImpl(Type genericComponentType) { 16 | if (genericComponentType == null) throw new NullPointerException(); 17 | this.genericComponentType = genericComponentType; 18 | } 19 | 20 | @Override 21 | public Type getGenericComponentType() { 22 | return genericComponentType; 23 | } 24 | 25 | @Override 26 | public boolean equals(Object o) { 27 | if (this == o) return true; 28 | if (o == null || getClass() != o.getClass()) return false; 29 | 30 | GenericArrayTypeImpl that = (GenericArrayTypeImpl) o; 31 | 32 | return genericComponentType.equals(that.genericComponentType); 33 | } 34 | 35 | @Override 36 | public int hashCode() { 37 | return genericComponentType.hashCode(); 38 | } 39 | 40 | @Override 41 | public String toString() { 42 | return genericComponentType.toString() + "[]"; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/serialization/Serializer.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.serialization; 2 | 3 | import java.io.IOException; 4 | import java.io.OutputStream; 5 | import java.io.Writer; 6 | import java.util.Map; 7 | 8 | /** 9 | * 文档序列化器 10 | * 11 | * @author 杨昌沛 646742615@qq.com 12 | * @date 2018-04-17 9:52 13 | **/ 14 | public interface Serializer { 15 | 16 | String getName(); 17 | 18 | String getType(); 19 | 20 | void serialize(Map doc, OutputStream out) throws IOException; 21 | 22 | void serialize(Map doc, Writer writer) throws IOException; 23 | 24 | } 25 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/strategy/FilterStrategy.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.strategy; 2 | 3 | import java.io.IOException; 4 | 5 | /** 6 | * 过滤器策略 7 | * 8 | * @author 杨昌沛 646742615@qq.com 9 | * @date 2018-07-09 13:28 10 | **/ 11 | public abstract class FilterStrategy implements Strategy { 12 | protected final Strategy strategy; 13 | 14 | protected FilterStrategy(Strategy strategy) { 15 | this.strategy = strategy; 16 | } 17 | 18 | @Override 19 | public void execute(Task task) throws IOException { 20 | strategy.execute(task); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/strategy/SkipStrategy.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.strategy; 2 | 3 | import io.httpdoc.core.Claxx; 4 | 5 | import java.io.File; 6 | import java.io.IOException; 7 | 8 | /** 9 | * 跳过已存在策略 10 | * 11 | * @author 杨昌沛 646742615@qq.com 12 | * @date 2018-07-04 20:35 13 | **/ 14 | public class SkipStrategy extends FilterStrategy implements Strategy { 15 | 16 | public SkipStrategy() { 17 | this(new OverrideStrategy()); 18 | } 19 | 20 | public SkipStrategy(Strategy strategy) { 21 | super(strategy); 22 | } 23 | 24 | @Override 25 | public void execute(Task task) throws IOException { 26 | String directory = task.getDirectory(); 27 | for (Claxx claxx : task) { 28 | String path = directory + claxx.getPath(); 29 | File file = new File(path); 30 | if (file.exists()) return; 31 | super.execute(new Task(directory, claxx)); 32 | } 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/strategy/Strategy.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.strategy; 2 | 3 | import java.io.IOException; 4 | 5 | /** 6 | * 生成策略 7 | * 8 | * @author 杨昌沛 646742615@qq.com 9 | * @date 2018-07-04 11:25 10 | **/ 11 | public interface Strategy { 12 | 13 | /** 14 | * 生成 15 | * 16 | * @param task 生成任务 17 | * @throws IOException IO 异常 18 | */ 19 | void execute(Task task) throws IOException; 20 | 21 | } 22 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/strategy/Task.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.strategy; 2 | 3 | import io.httpdoc.core.Claxx; 4 | 5 | import java.util.Collection; 6 | import java.util.Collections; 7 | import java.util.Iterator; 8 | 9 | /** 10 | * 生成任务 11 | * 12 | * @author 杨昌沛 646742615@qq.com 13 | * @date 2018-07-09 14:18 14 | **/ 15 | public class Task implements Iterable { 16 | private final String directory; 17 | private final Collection classes; 18 | 19 | public Task(String directory, Claxx claxx) { 20 | this(directory, Collections.singleton(claxx)); 21 | } 22 | 23 | public Task(String directory, Collection classes) { 24 | this.directory = directory; 25 | this.classes = classes; 26 | } 27 | 28 | @Override 29 | public Iterator iterator() { 30 | return classes != null ? classes.iterator() : Collections.emptyList().iterator(); 31 | } 32 | 33 | public String getDirectory() { 34 | return directory; 35 | } 36 | 37 | public Collection getClasses() { 38 | return classes; 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/supplier/Supplier.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.supplier; 2 | 3 | import io.httpdoc.core.Schema; 4 | 5 | import java.lang.reflect.Type; 6 | 7 | /** 8 | * 基本资源模型提供者 9 | * 10 | * @author 杨昌沛 646742615@qq.com 11 | * @date 2018-04-16 13:42 12 | **/ 13 | public interface Supplier { 14 | 15 | boolean contains(Type type); 16 | 17 | Schema acquire(Type type); 18 | 19 | boolean contains(Schema schema); 20 | 21 | Type acquire(Schema schema); 22 | 23 | } 24 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/translation/AbstractContainer.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.translation; 2 | 3 | import java.util.Enumeration; 4 | import java.util.LinkedHashMap; 5 | import java.util.Map; 6 | 7 | public abstract class AbstractContainer implements Container { 8 | 9 | @Override 10 | public Map get(Class type) { 11 | Map map = new LinkedHashMap<>(); 12 | Enumeration names = names(); 13 | while (names.hasMoreElements()) { 14 | String name = names.nextElement(); 15 | Object bean = get(name); 16 | if (type.isInstance(bean)) map.put(name, type.cast(bean)); 17 | } 18 | return map; 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/translation/Container.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.translation; 2 | 3 | import java.util.Enumeration; 4 | import java.util.Map; 5 | 6 | /** 7 | * 应用容器 8 | * 9 | * @author 杨昌沛 646742615@qq.com 10 | * @date 2018-04-23 15:56 11 | **/ 12 | public interface Container { 13 | 14 | Object get(String name); 15 | 16 | Map get(Class type); 17 | 18 | Enumeration names(); 19 | 20 | void remove(String name); 21 | 22 | void set(String name, Object value); 23 | 24 | } 25 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/java/io/httpdoc/core/translation/Translator.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.core.translation; 2 | 3 | import io.httpdoc.core.Document; 4 | import io.httpdoc.core.exception.DocumentTranslationException; 5 | 6 | /** 7 | * 文档翻译器 8 | * 9 | * @author 杨昌沛 646742615@qq.com 10 | * @date 2018-04-19 15:48 11 | **/ 12 | public interface Translator { 13 | 14 | Document translate(Translation translation) throws DocumentTranslationException; 15 | 16 | String normalize(String path); 17 | 18 | } 19 | -------------------------------------------------------------------------------- /httpdoc-core/src/main/resources/httpdoc/converter.properties: -------------------------------------------------------------------------------- 1 | standard=io.httpdoc.core.conversion.StandardConverter -------------------------------------------------------------------------------- /httpdoc-core/src/main/resources/httpdoc/interpreter.properties: -------------------------------------------------------------------------------- 1 | default=io.httpdoc.core.interpretation.DefaultInterpreter 2 | source=io.httpdoc.core.interpretation.SourceInterpreter -------------------------------------------------------------------------------- /httpdoc-core/src/main/resources/httpdoc/modeler.properties: -------------------------------------------------------------------------------- 1 | java-simple=io.httpdoc.core.modeler.SimpleModeler -------------------------------------------------------------------------------- /httpdoc-core/src/main/resources/httpdoc/supplier.properties: -------------------------------------------------------------------------------- 1 | system=io.httpdoc.core.supplier.SystemSupplier -------------------------------------------------------------------------------- /httpdoc-gson/src/main/java/io/httpdoc/gson/deserialization/GsonDeserializer.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.gson.deserialization; 2 | 3 | import com.google.gson.Gson; 4 | import com.google.gson.reflect.TypeToken; 5 | import io.httpdoc.core.deserialization.Deserializer; 6 | 7 | import java.io.IOException; 8 | import java.io.InputStream; 9 | import java.io.InputStreamReader; 10 | import java.io.Reader; 11 | import java.util.Map; 12 | 13 | /** 14 | * Gson 文档反序列化器 15 | * 16 | * @author 杨昌沛 646742615@qq.com 17 | * @date 2018-04-24 13:18 18 | **/ 19 | public class GsonDeserializer implements Deserializer { 20 | 21 | @Override 22 | public Map deserialize(InputStream in) throws IOException { 23 | Reader reader = null; 24 | try { 25 | reader = new InputStreamReader(in); 26 | Gson gson = new Gson(); 27 | return gson.fromJson(reader, new TypeToken>() { 28 | }.getType()); 29 | } finally { 30 | if (reader != null) reader.close(); 31 | } 32 | } 33 | 34 | @Override 35 | public Map deserialize(Reader reader) throws IOException { 36 | Gson gson = new Gson(); 37 | return gson.fromJson(reader, new TypeToken>() { 38 | }.getType()); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /httpdoc-gson/src/main/java/io/httpdoc/gson/serialization/GsonSerializer.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.gson.serialization; 2 | 3 | import com.google.gson.Gson; 4 | import io.httpdoc.core.serialization.Serializer; 5 | 6 | import java.io.IOException; 7 | import java.io.OutputStream; 8 | import java.io.OutputStreamWriter; 9 | import java.io.Writer; 10 | import java.util.Map; 11 | 12 | /** 13 | * gson 文档序列化器 14 | * 15 | * @author 杨昌沛 646742615@qq.com 16 | * @date 2018-04-24 13:12 17 | **/ 18 | public class GsonSerializer implements Serializer { 19 | 20 | @Override 21 | public String getName() { 22 | return "gson"; 23 | } 24 | 25 | @Override 26 | public String getType() { 27 | return "application/json"; 28 | } 29 | 30 | @Override 31 | public void serialize(Map doc, OutputStream out) throws IOException { 32 | Writer writer = null; 33 | try { 34 | writer = new OutputStreamWriter(out); 35 | Gson gson = new Gson(); 36 | gson.toJson(doc, writer); 37 | } finally { 38 | if (writer != null) writer.close(); 39 | } 40 | } 41 | 42 | @Override 43 | public void serialize(Map doc, Writer writer) throws IOException { 44 | Gson gson = new Gson(); 45 | gson.toJson(doc, writer); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /httpdoc-gson/src/main/resources/httpdoc/deserializer.properties: -------------------------------------------------------------------------------- 1 | gson=io.httpdoc.gson.deserialization.GsonDeserializer -------------------------------------------------------------------------------- /httpdoc-gson/src/main/resources/httpdoc/serializer.properties: -------------------------------------------------------------------------------- 1 | gson=io.httpdoc.gson.serialization.GsonSerializer -------------------------------------------------------------------------------- /httpdoc-jackson/src/main/java/io/httpdoc/jackson/deserialization/JsonDeserializer.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.jackson.deserialization; 2 | 3 | import com.fasterxml.jackson.core.JsonFactory; 4 | import com.fasterxml.jackson.core.type.TypeReference; 5 | import com.fasterxml.jackson.databind.ObjectMapper; 6 | import io.httpdoc.core.deserialization.Deserializer; 7 | 8 | import java.io.IOException; 9 | import java.io.InputStream; 10 | import java.io.Reader; 11 | import java.util.Map; 12 | 13 | /** 14 | * Object反序列化器 15 | * 16 | * @author 杨昌沛 646742615@qq.com 17 | * @date 2018-04-17 10:29 18 | **/ 19 | public class JsonDeserializer implements Deserializer { 20 | private final ObjectMapper mapper; 21 | 22 | public JsonDeserializer() { 23 | this(new JsonFactory()); 24 | } 25 | 26 | public JsonDeserializer(JsonFactory factory) { 27 | this(new ObjectMapper(factory)); 28 | } 29 | 30 | public JsonDeserializer(ObjectMapper mapper) { 31 | this.mapper = mapper; 32 | } 33 | 34 | @Override 35 | public Map deserialize(InputStream in) throws IOException { 36 | return mapper.readValue(in, new TypeReference>() { 37 | }); 38 | } 39 | 40 | @Override 41 | public Map deserialize(Reader reader) throws IOException { 42 | return mapper.readValue(reader, new TypeReference>() { 43 | }); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /httpdoc-jackson/src/main/java/io/httpdoc/jackson/deserialization/XmlDeserializer.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.jackson.deserialization; 2 | 3 | import com.fasterxml.jackson.core.type.TypeReference; 4 | import com.fasterxml.jackson.dataformat.xml.XmlFactory; 5 | import com.fasterxml.jackson.dataformat.xml.XmlMapper; 6 | import io.httpdoc.core.deserialization.Deserializer; 7 | 8 | import java.io.IOException; 9 | import java.io.InputStream; 10 | import java.io.Reader; 11 | import java.util.Map; 12 | 13 | /** 14 | * Xml反序列化器 15 | * 16 | * @author 杨昌沛 646742615@qq.com 17 | * @date 2018-04-17 10:29 18 | **/ 19 | public class XmlDeserializer implements Deserializer { 20 | private final XmlMapper mapper; 21 | 22 | public XmlDeserializer() { 23 | this(new XmlFactory()); 24 | } 25 | 26 | public XmlDeserializer(XmlFactory factory) { 27 | this(new XmlMapper(factory)); 28 | } 29 | 30 | public XmlDeserializer(XmlMapper mapper) { 31 | this.mapper = mapper; 32 | } 33 | 34 | @Override 35 | public Map deserialize(InputStream in) throws IOException { 36 | return mapper.readValue(in, new TypeReference>() { 37 | }); 38 | } 39 | 40 | @Override 41 | public Map deserialize(Reader reader) throws IOException { 42 | return mapper.readValue(reader, new TypeReference>() { 43 | }); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /httpdoc-jackson/src/main/java/io/httpdoc/jackson/deserialization/YamlDeserializer.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.jackson.deserialization; 2 | 3 | import com.fasterxml.jackson.core.type.TypeReference; 4 | import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; 5 | import com.fasterxml.jackson.dataformat.yaml.YAMLMapper; 6 | import io.httpdoc.core.deserialization.Deserializer; 7 | 8 | import java.io.IOException; 9 | import java.io.InputStream; 10 | import java.io.Reader; 11 | import java.util.Map; 12 | 13 | /** 14 | * YAML反序列化器 15 | * 16 | * @author 杨昌沛 646742615@qq.com 17 | * @date 2018-04-17 10:29 18 | **/ 19 | public class YamlDeserializer implements Deserializer { 20 | private final YAMLMapper mapper; 21 | 22 | public YamlDeserializer() { 23 | this(new YAMLFactory()); 24 | } 25 | 26 | public YamlDeserializer(YAMLFactory factory) { 27 | this(new YAMLMapper(factory)); 28 | } 29 | 30 | public YamlDeserializer(YAMLMapper mapper) { 31 | this.mapper = mapper; 32 | } 33 | 34 | @Override 35 | public Map deserialize(InputStream in) throws IOException { 36 | return mapper.readValue(in, new TypeReference>() { 37 | }); 38 | } 39 | 40 | @Override 41 | public Map deserialize(Reader reader) throws IOException { 42 | return mapper.readValue(reader, new TypeReference>() { 43 | }); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /httpdoc-jackson/src/main/java/io/httpdoc/jackson/serialization/JsonSerializer.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.jackson.serialization; 2 | 3 | import com.fasterxml.jackson.core.JsonFactory; 4 | import com.fasterxml.jackson.databind.ObjectMapper; 5 | import io.httpdoc.core.serialization.Serializer; 6 | 7 | import java.io.IOException; 8 | import java.io.OutputStream; 9 | import java.io.Writer; 10 | import java.util.Map; 11 | 12 | /** 13 | * JSON 文档序列化器 14 | * 15 | * @author 杨昌沛 646742615@qq.com 16 | * @date 2018-04-24 12:30 17 | **/ 18 | public class JsonSerializer implements Serializer { 19 | private final ObjectMapper mapper; 20 | 21 | public JsonSerializer() { 22 | this(new JsonFactory()); 23 | } 24 | 25 | public JsonSerializer(JsonFactory factory) { 26 | this(new ObjectMapper(factory)); 27 | } 28 | 29 | public JsonSerializer(ObjectMapper mapper) { 30 | this.mapper = mapper; 31 | } 32 | 33 | @Override 34 | public String getName() { 35 | return "json"; 36 | } 37 | 38 | @Override 39 | public String getType() { 40 | return "application/json"; 41 | } 42 | 43 | @Override 44 | public void serialize(Map doc, OutputStream out) throws IOException { 45 | mapper.writeValue(out, doc); 46 | } 47 | 48 | @Override 49 | public void serialize(Map doc, Writer writer) throws IOException { 50 | mapper.writeValue(writer, doc); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /httpdoc-jackson/src/main/java/io/httpdoc/jackson/serialization/XmlSerializer.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.jackson.serialization; 2 | 3 | import com.fasterxml.jackson.dataformat.xml.XmlFactory; 4 | import com.fasterxml.jackson.dataformat.xml.XmlMapper; 5 | import io.httpdoc.core.serialization.Serializer; 6 | 7 | import java.io.IOException; 8 | import java.io.OutputStream; 9 | import java.io.Writer; 10 | import java.util.Map; 11 | 12 | /** 13 | * Xml文档序列化器 14 | * 15 | * @author 杨昌沛 646742615@qq.com 16 | * @date 2018-04-24 12:27 17 | **/ 18 | public class XmlSerializer implements Serializer { 19 | private final XmlMapper mapper; 20 | 21 | public XmlSerializer() { 22 | this(new XmlFactory()); 23 | } 24 | 25 | public XmlSerializer(XmlFactory factory) { 26 | this(new XmlMapper(factory)); 27 | } 28 | 29 | public XmlSerializer(XmlMapper mapper) { 30 | this.mapper = mapper; 31 | } 32 | 33 | @Override 34 | public String getName() { 35 | return "xml"; 36 | } 37 | 38 | @Override 39 | public String getType() { 40 | return "application/xml"; 41 | } 42 | 43 | @Override 44 | public void serialize(Map doc, OutputStream out) throws IOException { 45 | mapper.writeValue(out, doc); 46 | } 47 | 48 | @Override 49 | public void serialize(Map doc, Writer writer) throws IOException { 50 | mapper.writeValue(writer, doc); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /httpdoc-jackson/src/main/resources/httpdoc/deserializer.properties: -------------------------------------------------------------------------------- 1 | json=io.httpdoc.jackson.deserialization.JsonDeserializer 2 | xml=io.httpdoc.jackson.deserialization.XmlDeserializer 3 | yaml=io.httpdoc.jackson.deserialization.YamlDeserializer -------------------------------------------------------------------------------- /httpdoc-jackson/src/main/resources/httpdoc/serializer.properties: -------------------------------------------------------------------------------- 1 | json=io.httpdoc.jackson.serialization.JsonSerializer 2 | xml=io.httpdoc.jackson.serialization.XmlSerializer 3 | yaml=io.httpdoc.jackson.serialization.YamlSerializer -------------------------------------------------------------------------------- /httpdoc-jestful-client/src/main/java/io/httpdoc/jestful/client/JestfulModeler.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.jestful.client; 2 | 3 | import io.httpdoc.core.fragment.ClassFragment; 4 | import io.httpdoc.core.modeler.Modeler; 5 | 6 | /** 7 | * Jestful模型师 8 | * 9 | * @author Payne 646742615@qq.com 10 | * 2019/3/29 14:45 11 | */ 12 | public interface JestfulModeler extends Modeler { 13 | } 14 | -------------------------------------------------------------------------------- /httpdoc-jestful-client/src/main/java/io/httpdoc/jestful/client/JestfulSimpleModeler.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.jestful.client; 2 | 3 | import io.httpdoc.core.modeler.SimpleModeler; 4 | 5 | /** 6 | * Jestful简单模型师 7 | * 8 | * @author Payne 646742615@qq.com 9 | * 2019/3/29 14:45 10 | */ 11 | public class JestfulSimpleModeler extends SimpleModeler implements JestfulModeler { 12 | } 13 | -------------------------------------------------------------------------------- /httpdoc-jestful-client/src/main/java/io/httpdoc/jestful/client/JestfulSupplier.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.jestful.client; 2 | 3 | import io.httpdoc.core.Schema; 4 | import io.httpdoc.core.supplier.Supplier; 5 | import io.httpdoc.core.supplier.SystemSupplier; 6 | import org.qfox.jestful.client.Part; 7 | 8 | import java.lang.reflect.Type; 9 | 10 | /** 11 | * Jestful 类型提供器 12 | * 13 | * @author 杨昌沛 646742615@qq.com 14 | * @date 2018-05-16 13:39 15 | **/ 16 | public class JestfulSupplier implements Supplier { 17 | private final Supplier supplier; 18 | 19 | public JestfulSupplier() { 20 | this(new SystemSupplier()); 21 | } 22 | 23 | public JestfulSupplier(Supplier supplier) { 24 | this.supplier = supplier; 25 | } 26 | 27 | @Override 28 | public boolean contains(Type type) { 29 | return supplier.contains(type); 30 | } 31 | 32 | @Override 33 | public Schema acquire(Type type) { 34 | return supplier.acquire(type); 35 | } 36 | 37 | @Override 38 | public boolean contains(Schema schema) { 39 | return supplier.contains(schema); 40 | } 41 | 42 | @Override 43 | public Type acquire(Schema schema) { 44 | if ("File".equals(schema.getName())) return Part.class; 45 | return supplier.acquire(schema); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /httpdoc-jestful-client/src/main/resources/httpdoc/exporter.properties: -------------------------------------------------------------------------------- 1 | Jestful=io.httpdoc.jestful.client.JestfulExporter -------------------------------------------------------------------------------- /httpdoc-jestful-client/src/main/resources/httpdoc/generator.properties: -------------------------------------------------------------------------------- 1 | standard=io.httpdoc.jestful.client.JestfulStandardGenerator 2 | callback=io.httpdoc.jestful.client.JestfulCallbackGenerator 3 | entity=io.httpdoc.jestful.client.JestfulEntityGenerator 4 | future=io.httpdoc.jestful.client.JestfulFutureGenerator 5 | guava=io.httpdoc.jestful.client.JestfulGuavaGenerator 6 | header=io.httpdoc.jestful.client.JestfulHeaderGenerator 7 | java8=io.httpdoc.jestful.client.JestfulJava8Generator 8 | lambda=io.httpdoc.jestful.client.JestfulLambdaGenerator 9 | message=io.httpdoc.jestful.client.JestfulMessageGenerator 10 | rxjava=io.httpdoc.jestful.client.JestfulRxJavaGenerator -------------------------------------------------------------------------------- /httpdoc-jestful-client/src/main/resources/httpdoc/modeler.properties: -------------------------------------------------------------------------------- 1 | simple=io.httpdoc.jestful.client.JestfulSimpleModeler -------------------------------------------------------------------------------- /httpdoc-jestful-server/src/main/java/io/httpdoc/jestful/server/ControllerTranslation.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.jestful.server; 2 | 3 | import io.httpdoc.core.Document; 4 | import io.httpdoc.core.translation.Translation; 5 | 6 | public class ControllerTranslation extends JestfulTranslation { 7 | private final Document document; 8 | 9 | public ControllerTranslation(Translation translation, Document document) { 10 | super(translation); 11 | this.document = document; 12 | } 13 | 14 | public Document getDocument() { 15 | return document; 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /httpdoc-jestful-server/src/main/java/io/httpdoc/jestful/server/JestfulHttpdocContainer.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.jestful.server; 2 | 3 | import io.httpdoc.core.translation.AbstractContainer; 4 | import io.httpdoc.core.translation.Container; 5 | 6 | import javax.servlet.ServletContext; 7 | import java.util.Enumeration; 8 | 9 | /** 10 | * Httpdoc Servlet Container 11 | * 12 | * @author 杨昌沛 646742615@qq.com 13 | * @date 2018-04-23 16:14 14 | **/ 15 | public class JestfulHttpdocContainer extends AbstractContainer implements Container { 16 | private final ServletContext servletContext; 17 | 18 | JestfulHttpdocContainer(ServletContext servletContext) { 19 | this.servletContext = servletContext; 20 | } 21 | 22 | @Override 23 | public Object get(String name) { 24 | return servletContext.getAttribute(name); 25 | } 26 | 27 | @Override 28 | public Enumeration names() { 29 | return servletContext.getAttributeNames(); 30 | } 31 | 32 | @Override 33 | public void remove(String name) { 34 | servletContext.removeAttribute(name); 35 | } 36 | 37 | @Override 38 | public void set(String name, Object value) { 39 | servletContext.setAttribute(name, value); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /httpdoc-jestful-server/src/main/java/io/httpdoc/jestful/server/JestfulTranslation.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.jestful.server; 2 | 3 | import io.httpdoc.core.interpretation.Interpreter; 4 | import io.httpdoc.core.supplier.Supplier; 5 | import io.httpdoc.core.translation.Container; 6 | import io.httpdoc.core.translation.Translation; 7 | 8 | public abstract class JestfulTranslation { 9 | private final Translation translation; 10 | 11 | protected JestfulTranslation(Translation translation) { 12 | this.translation = translation; 13 | } 14 | 15 | protected JestfulTranslation(JestfulTranslation parent) { 16 | this.translation = parent.translation; 17 | } 18 | 19 | public String getHttpdoc() { 20 | return translation.getHttpdoc(); 21 | } 22 | 23 | public String getProtocol() { 24 | return translation.getProtocol(); 25 | } 26 | 27 | public String getHostname() { 28 | return translation.getHostname(); 29 | } 30 | 31 | public Integer getPort() { 32 | return translation.getPort(); 33 | } 34 | 35 | public String getContext() { 36 | return translation.getContext(); 37 | } 38 | 39 | public String getVersion() { 40 | return translation.getVersion(); 41 | } 42 | 43 | public Container getContainer() { 44 | return translation.getContainer(); 45 | } 46 | 47 | public Supplier getSupplier() { 48 | return translation.getSupplier(); 49 | } 50 | 51 | public Interpreter getInterpreter() { 52 | return translation.getInterpreter(); 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /httpdoc-jestful-server/src/main/java/io/httpdoc/jestful/server/Module.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.jestful.server; 2 | 3 | import io.httpdoc.core.Build; 4 | 5 | import java.io.Serializable; 6 | 7 | /** 8 | * Created by payne on 2017/3/28. 9 | */ 10 | public class Module extends Build implements Serializable { 11 | private static final long serialVersionUID = 8979830823718754930L; 12 | 13 | private static volatile Module instance; 14 | 15 | private String name; 16 | private String version; 17 | private String parentName; 18 | private String parentVersion; 19 | 20 | private Module() { 21 | } 22 | 23 | public static Module getInstance() { 24 | if (instance != null) return instance; 25 | synchronized (Module.class) { 26 | if (instance != null) return instance; 27 | return instance = new Module(); 28 | } 29 | } 30 | 31 | public String getName() { 32 | return name; 33 | } 34 | 35 | public String getVersion() { 36 | return version; 37 | } 38 | 39 | public String getParentName() { 40 | return parentName; 41 | } 42 | 43 | public String getParentVersion() { 44 | return parentVersion; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /httpdoc-jestful-server/src/main/java/io/httpdoc/jestful/server/OperationTranslation.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.jestful.server; 2 | 3 | import io.httpdoc.core.Controller; 4 | import org.qfox.jestful.core.Mapping; 5 | 6 | import java.lang.reflect.Method; 7 | 8 | public class OperationTranslation extends JestfulTranslation { 9 | private final Mapping mapping; 10 | private final Method method; 11 | private final Controller controller; 12 | 13 | public OperationTranslation(JestfulTranslation parent, Mapping mapping, Method method, Controller controller) { 14 | super(parent); 15 | this.mapping = mapping; 16 | this.method = method; 17 | this.controller = controller; 18 | } 19 | 20 | public Mapping getMapping() { 21 | return mapping; 22 | } 23 | 24 | public Method getMethod() { 25 | return method; 26 | } 27 | 28 | public Controller getController() { 29 | return controller; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /httpdoc-jestful-server/src/main/java/io/httpdoc/jestful/server/ParameterTranslation.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.jestful.server; 2 | 3 | import io.httpdoc.core.Controller; 4 | import io.httpdoc.core.Operation; 5 | import org.qfox.jestful.core.Mapping; 6 | 7 | import java.lang.reflect.Method; 8 | 9 | public class ParameterTranslation extends JestfulTranslation { 10 | private final Mapping mapping; 11 | private final Method method; 12 | private final Controller controller; 13 | private final Operation operation; 14 | 15 | public ParameterTranslation(JestfulTranslation parent, Mapping mapping, Method method, Controller controller, Operation operation) { 16 | super(parent); 17 | this.mapping = mapping; 18 | this.method = method; 19 | this.controller = controller; 20 | this.operation = operation; 21 | } 22 | 23 | public Mapping getMapping() { 24 | return mapping; 25 | } 26 | 27 | public Method getMethod() { 28 | return method; 29 | } 30 | 31 | public Controller getController() { 32 | return controller; 33 | } 34 | 35 | public Operation getOperation() { 36 | return operation; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /httpdoc-jestful-server/src/main/resources/httpdoc/translator.properties: -------------------------------------------------------------------------------- 1 | jestful-server=io.httpdoc.jestful.server.JestfulTranslator -------------------------------------------------------------------------------- /httpdoc-jestful-server/src/main/resources/io/httpdoc/jestful/server/Module.properties: -------------------------------------------------------------------------------- 1 | name=${project.artifactId} 2 | version=${project.version} 3 | parentName=${project.parent.artifactId} 4 | parentVersion=${project.parent.version} -------------------------------------------------------------------------------- /httpdoc-nutz/src/main/resources/httpdoc/translator.properties: -------------------------------------------------------------------------------- 1 | nutz=io.httpdoc.nutz.NutzTranslator -------------------------------------------------------------------------------- /httpdoc-objc/src/main/java/io/httpdoc/objc/ObjC.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.objc; 2 | 3 | /** 4 | * ObjC 系统类型 5 | * 6 | * @author 杨昌沛 646742615@qq.com 7 | * @date 2018-07-27 14:10 8 | **/ 9 | public interface ObjC { 10 | 11 | String FOUNDATION = ""; 12 | 13 | String getName(); 14 | 15 | Kind getKind(); 16 | 17 | Reference getReference(); 18 | 19 | String getLocation(); 20 | 21 | boolean isExternal(); 22 | 23 | enum Kind { 24 | CLASS, 25 | PROTOCOL, 26 | PRIMITIVE, 27 | TYPEDEF, 28 | BLOCK, 29 | GENERIC 30 | } 31 | 32 | enum Reference { 33 | STRONG, 34 | WEAK, 35 | COPY, 36 | ASSIGN 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /httpdoc-objc/src/main/java/io/httpdoc/objc/ObjCFile.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.objc; 2 | 3 | import io.httpdoc.core.Preference; 4 | import io.httpdoc.core.Src; 5 | import io.httpdoc.core.appender.LineAppender; 6 | import io.httpdoc.core.fragment.Fragment; 7 | 8 | import java.io.IOException; 9 | 10 | /** 11 | * ObjC源文件 12 | * 13 | * @author 杨昌沛 646742615@qq.com 14 | * @date 2018-07-25 16:49 15 | **/ 16 | public class ObjCFile implements Src { 17 | private final String pkg; 18 | private final String name; 19 | private final Type type; 20 | private final Fragment fragment; 21 | 22 | public ObjCFile(String pkg, String name, Type type, Fragment fragment) { 23 | this.pkg = pkg; 24 | this.name = name; 25 | this.type = type; 26 | this.fragment = fragment; 27 | } 28 | 29 | @Override 30 | public > void joinTo(T appender, Preference preference) throws IOException { 31 | fragment.joinTo(appender, preference); 32 | } 33 | 34 | public String getPkg() { 35 | return pkg; 36 | } 37 | 38 | public Fragment getFragment() { 39 | return fragment; 40 | } 41 | 42 | public String getName() { 43 | return name; 44 | } 45 | 46 | public Type getType() { 47 | return type; 48 | } 49 | 50 | public enum Type { 51 | INTERFACE(".h"), IMPLEMENTATION(".m"); 52 | 53 | public final String extension; 54 | 55 | Type(String extension) { 56 | this.extension = extension; 57 | } 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /httpdoc-objc/src/main/java/io/httpdoc/objc/ObjCModeler.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.objc; 2 | 3 | import io.httpdoc.core.modeler.Modeler; 4 | 5 | /** 6 | * ObjC模型师 7 | * 8 | * @author Payne 646742615@qq.com 9 | * 2019/3/29 14:44 10 | */ 11 | public interface ObjCModeler extends Modeler { 12 | } 13 | -------------------------------------------------------------------------------- /httpdoc-objc/src/main/java/io/httpdoc/objc/ObjCSELDefaultNamingStrategy.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.objc; 2 | 3 | import io.httpdoc.core.Preference; 4 | import io.httpdoc.core.appender.LineAppender; 5 | import io.httpdoc.core.appender.TitleCasedAppender; 6 | import io.httpdoc.objc.fragment.ObjCParameterFragment; 7 | 8 | import java.io.IOException; 9 | import java.util.Set; 10 | 11 | /** 12 | * 默认的Selector命名策略 13 | * 14 | * @author Payne 646742615@qq.com 15 | * 2019/3/29 15:45 16 | */ 17 | public class ObjCSELDefaultNamingStrategy implements ObjCSELNamingStrategy { 18 | 19 | @Override 20 | public > void joinTo(T appender, Preference preference, String name, Set parameterFragments) throws IOException { 21 | appender.append(name); 22 | TitleCasedAppender tca = new TitleCasedAppender(appender); 23 | int index = 0; 24 | for (ObjCParameterFragment parameterFragment : parameterFragments) { 25 | if (index++ == 0) appender.append("With"); 26 | else appender.enter().append(" "); 27 | parameterFragment.joinTo(tca, preference); 28 | } 29 | tca.close(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /httpdoc-objc/src/main/java/io/httpdoc/objc/ObjCSELNamingStrategy.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.objc; 2 | 3 | import io.httpdoc.core.Preference; 4 | import io.httpdoc.core.appender.LineAppender; 5 | import io.httpdoc.objc.fragment.ObjCParameterFragment; 6 | 7 | import java.io.IOException; 8 | import java.util.Set; 9 | 10 | /** 11 | * Selector 命名策略 12 | * 13 | * @author Payne 646742615@qq.com 14 | * 2019/3/29 15:37 15 | */ 16 | public interface ObjCSELNamingStrategy { 17 | 18 | /** 19 | * 将方法命名并拼接到拼接器上 20 | * 21 | * @param appender 拼接器 22 | * @param preference 偏好设置 23 | * @param name 方法名 24 | * @param parameterFragments 参数碎片 25 | * @param 拼接器类型 26 | * @throws IOException I/O 异常 27 | */ 28 | > void joinTo(T appender, Preference preference, String name, Set parameterFragments) throws IOException; 29 | 30 | } 31 | -------------------------------------------------------------------------------- /httpdoc-objc/src/main/java/io/httpdoc/objc/ObjCSELUnderlineNamingStrategy.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.objc; 2 | 3 | import io.httpdoc.core.Preference; 4 | import io.httpdoc.core.appender.LineAppender; 5 | import io.httpdoc.objc.fragment.ObjCParameterFragment; 6 | 7 | import java.io.IOException; 8 | import java.util.Set; 9 | 10 | /** 11 | * 下划线Selector命名策略 12 | * 13 | * @author Payne 646742615@qq.com 14 | * 2019/3/29 16:17 15 | */ 16 | public class ObjCSELUnderlineNamingStrategy implements ObjCSELNamingStrategy { 17 | 18 | @Override 19 | public > void joinTo(T appender, Preference preference, String name, Set parameterFragments) throws IOException { 20 | appender.append(name); 21 | int index = 0; 22 | for (ObjCParameterFragment parameterFragment : parameterFragments) { 23 | if (index++ == 0) appender.append("_"); 24 | else appender.enter().append(" "); 25 | parameterFragment.joinTo(appender, preference); 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /httpdoc-objc/src/main/java/io/httpdoc/objc/core/ObjCResult.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.objc.core; 2 | 3 | import io.httpdoc.core.Result; 4 | import io.httpdoc.core.Schema; 5 | 6 | public class ObjCResult extends Result { 7 | private static final long serialVersionUID = -7309271115590827870L; 8 | private final String prefix; 9 | private final Result result; 10 | 11 | public ObjCResult(String prefix, Result result) { 12 | this.prefix = prefix; 13 | this.result = result; 14 | } 15 | 16 | @Override 17 | public Schema getType() { 18 | Schema type = result.getType(); 19 | if (type == null) return null; 20 | return new ObjCSchema(prefix, type); 21 | } 22 | 23 | @Override 24 | public void setType(Schema type) { 25 | result.setType(type); 26 | } 27 | 28 | @Override 29 | public String getDescription() { 30 | return result.getDescription(); 31 | } 32 | 33 | @Override 34 | public void setDescription(String description) { 35 | result.setDescription(description); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /httpdoc-objc/src/main/java/io/httpdoc/objc/external/AFHTTPSessionManager.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.objc.external; 2 | 3 | import io.httpdoc.objc.ObjC; 4 | 5 | public class AFHTTPSessionManager implements ObjC { 6 | 7 | @Override 8 | public String getName() { 9 | return this.getClass().getSimpleName(); 10 | } 11 | 12 | @Override 13 | public Kind getKind() { 14 | return Kind.CLASS; 15 | } 16 | 17 | @Override 18 | public Reference getReference() { 19 | return Reference.STRONG; 20 | } 21 | 22 | @Override 23 | public String getLocation() { 24 | return "AFNetworking.h"; 25 | } 26 | 27 | @Override 28 | public boolean isExternal() { 29 | return true; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /httpdoc-objc/src/main/java/io/httpdoc/objc/external/RSCall.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.objc.external; 2 | 3 | import io.httpdoc.objc.ObjC; 4 | 5 | public class RSCall implements ObjC { 6 | 7 | @Override 8 | public String getName() { 9 | return this.getClass().getSimpleName(); 10 | } 11 | 12 | @Override 13 | public Kind getKind() { 14 | return Kind.PROTOCOL; 15 | } 16 | 17 | @Override 18 | public Reference getReference() { 19 | return Reference.STRONG; 20 | } 21 | 22 | @Override 23 | public String getLocation() { 24 | return "RSNetworking.h"; 25 | } 26 | 27 | @Override 28 | public boolean isExternal() { 29 | return true; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /httpdoc-objc/src/main/java/io/httpdoc/objc/external/RSClient.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.objc.external; 2 | 3 | import io.httpdoc.objc.ObjC; 4 | 5 | public class RSClient implements ObjC { 6 | 7 | @Override 8 | public String getName() { 9 | return this.getClass().getSimpleName(); 10 | } 11 | 12 | @Override 13 | public Kind getKind() { 14 | return Kind.PROTOCOL; 15 | } 16 | 17 | @Override 18 | public Reference getReference() { 19 | return Reference.STRONG; 20 | } 21 | 22 | @Override 23 | public String getLocation() { 24 | return "RSNetworking.h"; 25 | } 26 | 27 | @Override 28 | public boolean isExternal() { 29 | return true; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /httpdoc-objc/src/main/java/io/httpdoc/objc/external/RSInvocation.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.objc.external; 2 | 3 | import io.httpdoc.objc.ObjC; 4 | 5 | public class RSInvocation implements ObjC { 6 | @Override 7 | public String getName() { 8 | return this.getClass().getSimpleName(); 9 | } 10 | 11 | @Override 12 | public Kind getKind() { 13 | return Kind.CLASS; 14 | } 15 | 16 | @Override 17 | public Reference getReference() { 18 | return Reference.STRONG; 19 | } 20 | 21 | @Override 22 | public String getLocation() { 23 | return "RSNetworking.h"; 24 | } 25 | 26 | @Override 27 | public boolean isExternal() { 28 | return true; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /httpdoc-objc/src/main/java/io/httpdoc/objc/external/RSPart.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.objc.external; 2 | 3 | import io.httpdoc.objc.ObjC; 4 | 5 | /** 6 | * RSPart 7 | * 8 | * @author 杨昌沛 646742615@qq.com 9 | * @date 2018-07-30 10:26 10 | **/ 11 | public class RSPart implements ObjC { 12 | @Override 13 | public String getName() { 14 | return this.getClass().getSimpleName(); 15 | } 16 | 17 | @Override 18 | public Kind getKind() { 19 | return Kind.CLASS; 20 | } 21 | 22 | @Override 23 | public Reference getReference() { 24 | return Reference.STRONG; 25 | } 26 | 27 | @Override 28 | public String getLocation() { 29 | return "RSNetworking.h"; 30 | } 31 | 32 | @Override 33 | public boolean isExternal() { 34 | return true; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /httpdoc-objc/src/main/java/io/httpdoc/objc/foundation/Cbool.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.objc.foundation; 2 | 3 | import io.httpdoc.objc.ObjC; 4 | 5 | /** 6 | * BOOL 7 | * 8 | * @author 杨昌沛 646742615@qq.com 9 | * @date 2018-07-25 15:56 10 | **/ 11 | public class Cbool implements ObjC { 12 | 13 | @Override 14 | public String getName() { 15 | return "BOOL"; 16 | } 17 | 18 | @Override 19 | public Kind getKind() { 20 | return Kind.PRIMITIVE; 21 | } 22 | 23 | @Override 24 | public Reference getReference() { 25 | return Reference.ASSIGN; 26 | } 27 | 28 | @Override 29 | public String getLocation() { 30 | return FOUNDATION; 31 | } 32 | 33 | @Override 34 | public boolean isExternal() { 35 | return true; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /httpdoc-objc/src/main/java/io/httpdoc/objc/foundation/Cchar.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.objc.foundation; 2 | 3 | import io.httpdoc.objc.ObjC; 4 | 5 | /** 6 | * char 7 | * 8 | * @author 杨昌沛 646742615@qq.com 9 | * @date 2018-07-25 16:06 10 | **/ 11 | public class Cchar implements ObjC { 12 | 13 | @Override 14 | public String getName() { 15 | return "char"; 16 | } 17 | 18 | @Override 19 | public Kind getKind() { 20 | return Kind.PRIMITIVE; 21 | } 22 | 23 | @Override 24 | public Reference getReference() { 25 | return Reference.ASSIGN; 26 | } 27 | 28 | @Override 29 | public String getLocation() { 30 | return FOUNDATION; 31 | } 32 | 33 | @Override 34 | public boolean isExternal() { 35 | return true; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /httpdoc-objc/src/main/java/io/httpdoc/objc/foundation/Cdouble.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.objc.foundation; 2 | 3 | import io.httpdoc.objc.ObjC; 4 | 5 | /** 6 | * double 7 | * 8 | * @author 杨昌沛 646742615@qq.com 9 | * @date 2018-07-25 16:08 10 | **/ 11 | public class Cdouble implements ObjC { 12 | 13 | @Override 14 | public String getName() { 15 | return "double"; 16 | } 17 | 18 | @Override 19 | public Kind getKind() { 20 | return Kind.PRIMITIVE; 21 | } 22 | 23 | @Override 24 | public Reference getReference() { 25 | return Reference.ASSIGN; 26 | } 27 | 28 | @Override 29 | public String getLocation() { 30 | return FOUNDATION; 31 | } 32 | 33 | @Override 34 | public boolean isExternal() { 35 | return true; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /httpdoc-objc/src/main/java/io/httpdoc/objc/foundation/Cfloat.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.objc.foundation; 2 | 3 | import io.httpdoc.objc.ObjC; 4 | 5 | /** 6 | * float 7 | * 8 | * @author 杨昌沛 646742615@qq.com 9 | * @date 2018-07-25 16:07 10 | **/ 11 | public class Cfloat implements ObjC { 12 | 13 | @Override 14 | public String getName() { 15 | return "float"; 16 | } 17 | 18 | @Override 19 | public Kind getKind() { 20 | return Kind.PRIMITIVE; 21 | } 22 | 23 | @Override 24 | public Reference getReference() { 25 | return Reference.ASSIGN; 26 | } 27 | 28 | @Override 29 | public String getLocation() { 30 | return FOUNDATION; 31 | } 32 | 33 | @Override 34 | public boolean isExternal() { 35 | return true; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /httpdoc-objc/src/main/java/io/httpdoc/objc/foundation/Cid.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.objc.foundation; 2 | 3 | import io.httpdoc.objc.ObjC; 4 | 5 | /** 6 | * id 7 | * 8 | * @author 杨昌沛 646742615@qq.com 9 | * @date 2018-07-25 16:13 10 | **/ 11 | public class Cid implements ObjC { 12 | 13 | @Override 14 | public String getName() { 15 | return "id"; 16 | } 17 | 18 | @Override 19 | public Kind getKind() { 20 | return Kind.TYPEDEF; 21 | } 22 | 23 | @Override 24 | public Reference getReference() { 25 | return Reference.STRONG; 26 | } 27 | 28 | @Override 29 | public String getLocation() { 30 | return FOUNDATION; 31 | } 32 | 33 | @Override 34 | public boolean isExternal() { 35 | return true; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /httpdoc-objc/src/main/java/io/httpdoc/objc/foundation/Cinstancetype.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.objc.foundation; 2 | 3 | import io.httpdoc.objc.ObjC; 4 | 5 | /** 6 | * instancetype 7 | * 8 | * @author 杨昌沛 646742615@qq.com 9 | * @date 2018-07-25 16:13 10 | **/ 11 | public class Cinstancetype implements ObjC { 12 | 13 | @Override 14 | public String getName() { 15 | return "instancetype"; 16 | } 17 | 18 | @Override 19 | public Kind getKind() { 20 | return Kind.TYPEDEF; 21 | } 22 | 23 | @Override 24 | public Reference getReference() { 25 | return Reference.WEAK; 26 | } 27 | 28 | @Override 29 | public String getLocation() { 30 | return FOUNDATION; 31 | } 32 | 33 | @Override 34 | public boolean isExternal() { 35 | return true; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /httpdoc-objc/src/main/java/io/httpdoc/objc/foundation/Cint.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.objc.foundation; 2 | 3 | import io.httpdoc.objc.ObjC; 4 | 5 | /** 6 | * int 7 | * 8 | * @author 杨昌沛 646742615@qq.com 9 | * @date 2018-07-25 16:01 10 | **/ 11 | public class Cint implements ObjC { 12 | 13 | @Override 14 | public String getName() { 15 | return "int"; 16 | } 17 | 18 | @Override 19 | public Kind getKind() { 20 | return Kind.PRIMITIVE; 21 | } 22 | 23 | @Override 24 | public Reference getReference() { 25 | return Reference.ASSIGN; 26 | } 27 | 28 | @Override 29 | public String getLocation() { 30 | return FOUNDATION; 31 | } 32 | 33 | @Override 34 | public boolean isExternal() { 35 | return true; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /httpdoc-objc/src/main/java/io/httpdoc/objc/foundation/Clong.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.objc.foundation; 2 | 3 | import io.httpdoc.objc.ObjC; 4 | 5 | /** 6 | * long 7 | * 8 | * @author 杨昌沛 646742615@qq.com 9 | * @date 2018-07-25 16:07 10 | **/ 11 | public class Clong implements ObjC { 12 | 13 | @Override 14 | public String getName() { 15 | return "long"; 16 | } 17 | 18 | @Override 19 | public Kind getKind() { 20 | return Kind.PRIMITIVE; 21 | } 22 | 23 | @Override 24 | public Reference getReference() { 25 | return Reference.ASSIGN; 26 | } 27 | 28 | @Override 29 | public String getLocation() { 30 | return FOUNDATION; 31 | } 32 | 33 | @Override 34 | public boolean isExternal() { 35 | return true; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /httpdoc-objc/src/main/java/io/httpdoc/objc/foundation/Cshort.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.objc.foundation; 2 | 3 | import io.httpdoc.objc.ObjC; 4 | 5 | /** 6 | * short 7 | * 8 | * @author 杨昌沛 646742615@qq.com 9 | * @date 2018-07-25 16:06 10 | **/ 11 | public class Cshort implements ObjC { 12 | 13 | @Override 14 | public String getName() { 15 | return "short"; 16 | } 17 | 18 | @Override 19 | public Kind getKind() { 20 | return Kind.PRIMITIVE; 21 | } 22 | 23 | @Override 24 | public Reference getReference() { 25 | return Reference.ASSIGN; 26 | } 27 | 28 | @Override 29 | public String getLocation() { 30 | return FOUNDATION; 31 | } 32 | 33 | @Override 34 | public boolean isExternal() { 35 | return true; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /httpdoc-objc/src/main/java/io/httpdoc/objc/foundation/Cvoid.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.objc.foundation; 2 | 3 | import io.httpdoc.objc.ObjC; 4 | 5 | /** 6 | * void 7 | * 8 | * @author 杨昌沛 646742615@qq.com 9 | * @date 2018-07-25 16:10 10 | **/ 11 | public class Cvoid implements ObjC { 12 | 13 | @Override 14 | public String getName() { 15 | return "void"; 16 | } 17 | 18 | @Override 19 | public Kind getKind() { 20 | return Kind.PRIMITIVE; 21 | } 22 | 23 | @Override 24 | public Reference getReference() { 25 | return Reference.ASSIGN; 26 | } 27 | 28 | @Override 29 | public String getLocation() { 30 | return FOUNDATION; 31 | } 32 | 33 | @Override 34 | public boolean isExternal() { 35 | return true; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /httpdoc-objc/src/main/java/io/httpdoc/objc/foundation/NSArray.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.objc.foundation; 2 | 3 | import io.httpdoc.objc.ObjC; 4 | 5 | /** 6 | * NSArray 7 | * 8 | * @author 杨昌沛 646742615@qq.com 9 | * @date 2018-07-25 16:12 10 | **/ 11 | public class NSArray implements ObjC { 12 | 13 | @Override 14 | public String getName() { 15 | return this.getClass().getSimpleName(); 16 | } 17 | 18 | @Override 19 | public Kind getKind() { 20 | return Kind.CLASS; 21 | } 22 | 23 | @Override 24 | public Reference getReference() { 25 | return Reference.COPY; 26 | } 27 | 28 | @Override 29 | public String getLocation() { 30 | return FOUNDATION; 31 | } 32 | 33 | @Override 34 | public boolean isExternal() { 35 | return true; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /httpdoc-objc/src/main/java/io/httpdoc/objc/foundation/NSData.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.objc.foundation; 2 | 3 | import io.httpdoc.objc.ObjC; 4 | 5 | /** 6 | * NSData 7 | * 8 | * @author 杨昌沛 646742615@qq.com 9 | * @date 2018-07-25 16:11 10 | **/ 11 | public class NSData implements ObjC { 12 | 13 | @Override 14 | public String getName() { 15 | return this.getClass().getSimpleName(); 16 | } 17 | 18 | @Override 19 | public Kind getKind() { 20 | return Kind.CLASS; 21 | } 22 | 23 | @Override 24 | public Reference getReference() { 25 | return Reference.STRONG; 26 | } 27 | 28 | @Override 29 | public String getLocation() { 30 | return FOUNDATION; 31 | } 32 | 33 | @Override 34 | public boolean isExternal() { 35 | return true; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /httpdoc-objc/src/main/java/io/httpdoc/objc/foundation/NSDate.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.objc.foundation; 2 | 3 | import io.httpdoc.objc.ObjC; 4 | 5 | /** 6 | * NSDate 7 | * 8 | * @author 杨昌沛 646742615@qq.com 9 | * @date 2018-07-25 16:11 10 | **/ 11 | public class NSDate implements ObjC { 12 | 13 | @Override 14 | public String getName() { 15 | return this.getClass().getSimpleName(); 16 | } 17 | 18 | @Override 19 | public Kind getKind() { 20 | return Kind.CLASS; 21 | } 22 | 23 | @Override 24 | public Reference getReference() { 25 | return Reference.STRONG; 26 | } 27 | 28 | @Override 29 | public String getLocation() { 30 | return FOUNDATION; 31 | } 32 | 33 | @Override 34 | public boolean isExternal() { 35 | return true; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /httpdoc-objc/src/main/java/io/httpdoc/objc/foundation/NSDictionary.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.objc.foundation; 2 | 3 | import io.httpdoc.objc.ObjC; 4 | 5 | /** 6 | * NSDictionary 7 | * 8 | * @author 杨昌沛 646742615@qq.com 9 | * @date 2018-07-25 16:12 10 | **/ 11 | public class NSDictionary implements ObjC { 12 | 13 | @Override 14 | public String getName() { 15 | return this.getClass().getSimpleName(); 16 | } 17 | 18 | @Override 19 | public Kind getKind() { 20 | return Kind.CLASS; 21 | } 22 | 23 | @Override 24 | public Reference getReference() { 25 | return Reference.COPY; 26 | } 27 | 28 | @Override 29 | public String getLocation() { 30 | return FOUNDATION; 31 | } 32 | 33 | @Override 34 | public boolean isExternal() { 35 | return true; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /httpdoc-objc/src/main/java/io/httpdoc/objc/foundation/NSError.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.objc.foundation; 2 | 3 | import io.httpdoc.objc.ObjC; 4 | 5 | /** 6 | * NSError 7 | * 8 | * @author 杨昌沛 646742615@qq.com 9 | * @date 2018-07-25 16:12 10 | **/ 11 | public class NSError implements ObjC { 12 | 13 | @Override 14 | public String getName() { 15 | return this.getClass().getSimpleName(); 16 | } 17 | 18 | @Override 19 | public Kind getKind() { 20 | return Kind.CLASS; 21 | } 22 | 23 | @Override 24 | public Reference getReference() { 25 | return Reference.STRONG; 26 | } 27 | 28 | @Override 29 | public String getLocation() { 30 | return FOUNDATION; 31 | } 32 | 33 | @Override 34 | public boolean isExternal() { 35 | return true; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /httpdoc-objc/src/main/java/io/httpdoc/objc/foundation/NSNumber.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.objc.foundation; 2 | 3 | import io.httpdoc.objc.ObjC; 4 | 5 | /** 6 | * NSNumber 7 | * 8 | * @author 杨昌沛 646742615@qq.com 9 | * @date 2018-07-25 16:10 10 | **/ 11 | public class NSNumber implements ObjC { 12 | 13 | @Override 14 | public String getName() { 15 | return this.getClass().getSimpleName(); 16 | } 17 | 18 | @Override 19 | public Kind getKind() { 20 | return Kind.CLASS; 21 | } 22 | 23 | @Override 24 | public Reference getReference() { 25 | return Reference.STRONG; 26 | } 27 | 28 | @Override 29 | public String getLocation() { 30 | return FOUNDATION; 31 | } 32 | 33 | @Override 34 | public boolean isExternal() { 35 | return true; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /httpdoc-objc/src/main/java/io/httpdoc/objc/foundation/NSObject.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.objc.foundation; 2 | 3 | import io.httpdoc.objc.ObjC; 4 | 5 | /** 6 | * NSObject 7 | * 8 | * @author 杨昌沛 646742615@qq.com 9 | * @date 2018-07-25 16:12 10 | **/ 11 | public class NSObject implements ObjC { 12 | 13 | @Override 14 | public String getName() { 15 | return this.getClass().getSimpleName(); 16 | } 17 | 18 | @Override 19 | public Kind getKind() { 20 | return Kind.CLASS; 21 | } 22 | 23 | @Override 24 | public Reference getReference() { 25 | return Reference.STRONG; 26 | } 27 | 28 | @Override 29 | public String getLocation() { 30 | return FOUNDATION; 31 | } 32 | 33 | @Override 34 | public boolean isExternal() { 35 | return true; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /httpdoc-objc/src/main/java/io/httpdoc/objc/foundation/NSString.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.objc.foundation; 2 | 3 | import io.httpdoc.objc.ObjC; 4 | 5 | /** 6 | * NSString 7 | * 8 | * @author 杨昌沛 646742615@qq.com 9 | * @date 2018-07-25 16:11 10 | **/ 11 | public class NSString implements ObjC { 12 | 13 | @Override 14 | public String getName() { 15 | return this.getClass().getSimpleName(); 16 | } 17 | 18 | @Override 19 | public Kind getKind() { 20 | return Kind.CLASS; 21 | } 22 | 23 | @Override 24 | public Reference getReference() { 25 | return Reference.COPY; 26 | } 27 | 28 | @Override 29 | public String getLocation() { 30 | return FOUNDATION; 31 | } 32 | 33 | @Override 34 | public boolean isExternal() { 35 | return true; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /httpdoc-objc/src/main/java/io/httpdoc/objc/foundation/NSURL.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.objc.foundation; 2 | 3 | import io.httpdoc.objc.ObjC; 4 | 5 | public class NSURL implements ObjC { 6 | 7 | @Override 8 | public String getName() { 9 | return this.getClass().getSimpleName(); 10 | } 11 | 12 | @Override 13 | public Kind getKind() { 14 | return Kind.CLASS; 15 | } 16 | 17 | @Override 18 | public Reference getReference() { 19 | return Reference.COPY; 20 | } 21 | 22 | @Override 23 | public String getLocation() { 24 | return FOUNDATION; 25 | } 26 | 27 | @Override 28 | public boolean isExternal() { 29 | return true; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /httpdoc-objc/src/main/resources/httpdoc-sdk/objc-sdk/MJExtension/MJExtension.h: -------------------------------------------------------------------------------- 1 | // 2 | // MJExtension.h 3 | // MJExtension 4 | // 5 | // Created by mj on 14-1-15. 6 | // Copyright (c) 2014年 小码哥. All rights reserved. 7 | // 代码地址:https://github.com/CoderMJLee/MJExtension 8 | // 代码地址:http://code4app.com/ios/%E5%AD%97%E5%85%B8-JSON-%E4%B8%8E%E6%A8%A1%E5%9E%8B%E7%9A%84%E8%BD%AC%E6%8D%A2/5339992a933bf062608b4c57 9 | 10 | #import "NSObject+MJCoding.h" 11 | #import "NSObject+MJProperty.h" 12 | #import "NSObject+MJClass.h" 13 | #import "NSObject+MJKeyValue.h" 14 | #import "NSString+MJExtension.h" 15 | #import "MJExtensionConst.h" -------------------------------------------------------------------------------- /httpdoc-objc/src/main/resources/httpdoc-sdk/objc-sdk/MJExtension/MJExtensionConst.m: -------------------------------------------------------------------------------- 1 | #ifndef __MJExtensionConst__M__ 2 | #define __MJExtensionConst__M__ 3 | 4 | #import 5 | 6 | /** 7 | * 成员变量类型(属性类型) 8 | */ 9 | NSString *const MJPropertyTypeInt = @"i"; 10 | NSString *const MJPropertyTypeShort = @"s"; 11 | NSString *const MJPropertyTypeFloat = @"f"; 12 | NSString *const MJPropertyTypeDouble = @"d"; 13 | NSString *const MJPropertyTypeLong = @"l"; 14 | NSString *const MJPropertyTypeLongLong = @"q"; 15 | NSString *const MJPropertyTypeChar = @"c"; 16 | NSString *const MJPropertyTypeBOOL1 = @"c"; 17 | NSString *const MJPropertyTypeBOOL2 = @"b"; 18 | NSString *const MJPropertyTypePointer = @"*"; 19 | 20 | NSString *const MJPropertyTypeIvar = @"^{objc_ivar=}"; 21 | NSString *const MJPropertyTypeMethod = @"^{objc_method=}"; 22 | NSString *const MJPropertyTypeBlock = @"@?"; 23 | NSString *const MJPropertyTypeClass = @"#"; 24 | NSString *const MJPropertyTypeSEL = @":"; 25 | NSString *const MJPropertyTypeId = @"@"; 26 | 27 | #endif -------------------------------------------------------------------------------- /httpdoc-objc/src/main/resources/httpdoc-sdk/objc-sdk/MJExtension/MJFoundation.h: -------------------------------------------------------------------------------- 1 | // 2 | // MJFoundation.h 3 | // MJExtensionExample 4 | // 5 | // Created by MJ Lee on 14/7/16. 6 | // Copyright (c) 2014年 小码哥. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface MJFoundation : NSObject 12 | + (BOOL)isClassFromFoundation:(Class)c; 13 | @end 14 | -------------------------------------------------------------------------------- /httpdoc-objc/src/main/resources/httpdoc-sdk/objc-sdk/MJExtension/MJFoundation.m: -------------------------------------------------------------------------------- 1 | // 2 | // MJFoundation.m 3 | // MJExtensionExample 4 | // 5 | // Created by MJ Lee on 14/7/16. 6 | // Copyright (c) 2014年 小码哥. All rights reserved. 7 | // 8 | 9 | #import "MJFoundation.h" 10 | #import "MJExtensionConst.h" 11 | #import 12 | 13 | @implementation MJFoundation 14 | 15 | + (BOOL)isClassFromFoundation:(Class)c 16 | { 17 | if (c == [NSObject class] || c == [NSManagedObject class]) return YES; 18 | 19 | static NSSet *foundationClasses; 20 | static dispatch_once_t onceToken; 21 | dispatch_once(&onceToken, ^{ 22 | // 集合中没有NSObject,因为几乎所有的类都是继承自NSObject,具体是不是NSObject需要特殊判断 23 | foundationClasses = [NSSet setWithObjects: 24 | [NSURL class], 25 | [NSDate class], 26 | [NSValue class], 27 | [NSData class], 28 | [NSError class], 29 | [NSArray class], 30 | [NSDictionary class], 31 | [NSString class], 32 | [NSAttributedString class], nil]; 33 | }); 34 | 35 | __block BOOL result = NO; 36 | [foundationClasses enumerateObjectsUsingBlock:^(Class foundationClass, BOOL *stop) { 37 | if ([c isSubclassOfClass:foundationClass]) { 38 | result = YES; 39 | *stop = YES; 40 | } 41 | }]; 42 | return result; 43 | } 44 | @end 45 | -------------------------------------------------------------------------------- /httpdoc-objc/src/main/resources/httpdoc-sdk/objc-sdk/MJExtension/MJProperty.h: -------------------------------------------------------------------------------- 1 | // 2 | // MJProperty.h 3 | // MJExtensionExample 4 | // 5 | // Created by MJ Lee on 15/4/17. 6 | // Copyright (c) 2015年 小码哥. All rights reserved. 7 | // 包装一个成员属性 8 | 9 | #import 10 | #import 11 | #import "MJPropertyType.h" 12 | #import "MJPropertyKey.h" 13 | 14 | /** 15 | * 包装一个成员 16 | */ 17 | @interface MJProperty : NSObject 18 | /** 成员属性 */ 19 | @property (nonatomic, assign) objc_property_t property; 20 | /** 成员属性的名字 */ 21 | @property (nonatomic, readonly) NSString *name; 22 | 23 | /** 成员属性的类型 */ 24 | @property (nonatomic, readonly) MJPropertyType *type; 25 | /** 成员属性来源于哪个类(可能是父类) */ 26 | @property (nonatomic, assign) Class srcClass; 27 | 28 | /**** 同一个成员属性 - 父类和子类的行为可能不一致(originKey、propertyKeys、objectClassInArray) ****/ 29 | /** 设置最原始的key */ 30 | - (void)setOriginKey:(id)originKey forClass:(Class)c; 31 | /** 对应着字典中的多级key(里面存放的数组,数组里面都是MJPropertyKey对象) */ 32 | - (NSArray *)propertyKeysForClass:(Class)c; 33 | 34 | /** 模型数组中的模型类型 */ 35 | - (void)setObjectClassInArray:(Class)objectClass forClass:(Class)c; 36 | - (Class)objectClassInArrayForClass:(Class)c; 37 | /**** 同一个成员变量 - 父类和子类的行为可能不一致(key、keys、objectClassInArray) ****/ 38 | 39 | /** 40 | * 设置object的成员变量值 41 | */ 42 | - (void)setValue:(id)value forObject:(id)object; 43 | /** 44 | * 得到object的成员属性值 45 | */ 46 | - (id)valueForObject:(id)object; 47 | 48 | /** 49 | * 初始化 50 | */ 51 | + (instancetype)cachedPropertyWithProperty:(objc_property_t)property; 52 | 53 | @end 54 | -------------------------------------------------------------------------------- /httpdoc-objc/src/main/resources/httpdoc-sdk/objc-sdk/MJExtension/MJPropertyKey.h: -------------------------------------------------------------------------------- 1 | // 2 | // MJPropertyKey.h 3 | // MJExtensionExample 4 | // 5 | // Created by MJ Lee on 15/8/11. 6 | // Copyright (c) 2015年 小码哥. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | typedef enum { 12 | MJPropertyKeyTypeDictionary = 0, // 字典的key 13 | MJPropertyKeyTypeArray // 数组的key 14 | } MJPropertyKeyType; 15 | 16 | /** 17 | * 属性的key 18 | */ 19 | @interface MJPropertyKey : NSObject 20 | /** key的名字 */ 21 | @property (copy, nonatomic) NSString *name; 22 | /** key的种类,可能是@"10",可能是@"age" */ 23 | @property (assign, nonatomic) MJPropertyKeyType type; 24 | 25 | /** 26 | * 根据当前的key,也就是name,从object(字典或者数组)中取值 27 | */ 28 | - (id)valueInObject:(id)object; 29 | 30 | @end 31 | -------------------------------------------------------------------------------- /httpdoc-objc/src/main/resources/httpdoc-sdk/objc-sdk/MJExtension/MJPropertyKey.m: -------------------------------------------------------------------------------- 1 | // 2 | // MJPropertyKey.m 3 | // MJExtensionExample 4 | // 5 | // Created by MJ Lee on 15/8/11. 6 | // Copyright (c) 2015年 小码哥. All rights reserved. 7 | // 8 | 9 | #import "MJPropertyKey.h" 10 | 11 | @implementation MJPropertyKey 12 | 13 | - (id)valueInObject:(id)object 14 | { 15 | if ([object isKindOfClass:[NSDictionary class]] && self.type == MJPropertyKeyTypeDictionary) { 16 | return object[self.name]; 17 | } else if ([object isKindOfClass:[NSArray class]] && self.type == MJPropertyKeyTypeArray) { 18 | NSArray *array = object; 19 | NSUInteger index = self.name.intValue; 20 | if (index < array.count) return array[index]; 21 | return nil; 22 | } 23 | return nil; 24 | } 25 | @end 26 | -------------------------------------------------------------------------------- /httpdoc-objc/src/main/resources/httpdoc-sdk/objc-sdk/MJExtension/MJPropertyType.h: -------------------------------------------------------------------------------- 1 | // 2 | // MJPropertyType.h 3 | // MJExtension 4 | // 5 | // Created by mj on 14-1-15. 6 | // Copyright (c) 2014年 小码哥. All rights reserved. 7 | // 包装一种类型 8 | 9 | #import 10 | 11 | /** 12 | * 包装一种类型 13 | */ 14 | @interface MJPropertyType : NSObject 15 | /** 类型标识符 */ 16 | @property (nonatomic, copy) NSString *code; 17 | 18 | /** 是否为id类型 */ 19 | @property (nonatomic, readonly, getter=isIdType) BOOL idType; 20 | 21 | /** 是否为基本数字类型:int、float等 */ 22 | @property (nonatomic, readonly, getter=isNumberType) BOOL numberType; 23 | 24 | /** 是否为BOOL类型 */ 25 | @property (nonatomic, readonly, getter=isBoolType) BOOL boolType; 26 | 27 | /** 对象类型(如果是基本数据类型,此值为nil) */ 28 | @property (nonatomic, readonly) Class typeClass; 29 | 30 | /** 类型是否来自于Foundation框架,比如NSString、NSArray */ 31 | @property (nonatomic, readonly, getter = isFromFoundation) BOOL fromFoundation; 32 | /** 类型是否不支持KVC */ 33 | @property (nonatomic, readonly, getter = isKVCDisabled) BOOL KVCDisabled; 34 | 35 | /** 36 | * 获得缓存的类型对象 37 | */ 38 | + (instancetype)cachedTypeWithCode:(NSString *)code; 39 | @end -------------------------------------------------------------------------------- /httpdoc-objc/src/main/resources/httpdoc-sdk/objc-sdk/MJExtension/NSObject+MJCoding.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSObject+MJCoding.h 3 | // MJExtension 4 | // 5 | // Created by mj on 14-1-15. 6 | // Copyright (c) 2014年 小码哥. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "MJExtensionConst.h" 11 | 12 | /** 13 | * Codeing协议 14 | */ 15 | @protocol MJCoding 16 | @optional 17 | /** 18 | * 这个数组中的属性名才会进行归档 19 | */ 20 | + (NSArray *)mj_allowedCodingPropertyNames; 21 | /** 22 | * 这个数组中的属性名将会被忽略:不进行归档 23 | */ 24 | + (NSArray *)mj_ignoredCodingPropertyNames; 25 | @end 26 | 27 | @interface NSObject (MJCoding) 28 | /** 29 | * 解码(从文件中解析对象) 30 | */ 31 | - (void)mj_decode:(NSCoder *)decoder; 32 | /** 33 | * 编码(将对象写入文件中) 34 | */ 35 | - (void)mj_encode:(NSCoder *)encoder; 36 | @end 37 | 38 | /** 39 | 归档的实现 40 | */ 41 | #define MJCodingImplementation \ 42 | - (id)initWithCoder:(NSCoder *)decoder \ 43 | { \ 44 | if (self = [super init]) { \ 45 | [self mj_decode:decoder]; \ 46 | } \ 47 | return self; \ 48 | } \ 49 | \ 50 | - (void)encodeWithCoder:(NSCoder *)encoder \ 51 | { \ 52 | [self mj_encode:encoder]; \ 53 | } 54 | 55 | #define MJExtensionCodingImplementation MJCodingImplementation -------------------------------------------------------------------------------- /httpdoc-objc/src/main/resources/httpdoc-sdk/objc-sdk/MJExtension/NSString+MJExtension.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+MJExtension.h 3 | // MJExtensionExample 4 | // 5 | // Created by MJ Lee on 15/6/7. 6 | // Copyright (c) 2015年 小码哥. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "MJExtensionConst.h" 11 | 12 | @interface NSString (MJExtension) 13 | /** 14 | * 驼峰转下划线(loveYou -> love_you) 15 | */ 16 | - (NSString *)mj_underlineFromCamel; 17 | /** 18 | * 下划线转驼峰(love_you -> loveYou) 19 | */ 20 | - (NSString *)mj_camelFromUnderline; 21 | /** 22 | * 首字母变大写 23 | */ 24 | - (NSString *)mj_firstCharUpper; 25 | /** 26 | * 首字母变小写 27 | */ 28 | - (NSString *)mj_firstCharLower; 29 | 30 | - (BOOL)mj_isPureInt; 31 | 32 | - (NSURL *)mj_url; 33 | @end 34 | 35 | @interface NSString (MJExtensionDeprecated_v_2_5_16) 36 | - (NSString *)underlineFromCamel MJExtensionDeprecated("请在方法名前面加上mj_前缀,使用mj_***"); 37 | - (NSString *)camelFromUnderline MJExtensionDeprecated("请在方法名前面加上mj_前缀,使用mj_***"); 38 | - (NSString *)firstCharUpper MJExtensionDeprecated("请在方法名前面加上mj_前缀,使用mj_***"); 39 | - (NSString *)firstCharLower MJExtensionDeprecated("请在方法名前面加上mj_前缀,使用mj_***"); 40 | - (BOOL)isPureInt MJExtensionDeprecated("请在方法名前面加上mj_前缀,使用mj_***"); 41 | - (NSURL *)url MJExtensionDeprecated("请在方法名前面加上mj_前缀,使用mj_***"); 42 | @end 43 | -------------------------------------------------------------------------------- /httpdoc-objc/src/main/resources/httpdoc-sdk/objc-sdk/RSNetworking/NSArray+RSJoining.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSArray+RSJoining.h 3 | // RSNetworking 4 | // 5 | // Created by 杨昌沛 on 2018/7/20. 6 | // Copyright © 2018年 杨昌沛. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface NSArray (RSJoining) 12 | 13 | - (NSString *)join; 14 | 15 | - (NSString *)joinWithDelimiter:(NSString *)delimiter; 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /httpdoc-objc/src/main/resources/httpdoc-sdk/objc-sdk/RSNetworking/NSArray+RSJoining.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSArray+RSJoining.m 3 | // RSNetworking 4 | // 5 | // Created by 杨昌沛 on 2018/7/20. 6 | // Copyright © 2018年 杨昌沛. All rights reserved. 7 | // 8 | 9 | #import "NSArray+RSJoining.h" 10 | 11 | @implementation NSArray (RSJoining) 12 | 13 | - (NSString *)join 14 | { 15 | return [self joinWithDelimiter:@","]; 16 | } 17 | 18 | - (NSString *)joinWithDelimiter:(NSString *)delimiter 19 | { 20 | NSMutableString *joined = [NSMutableString string]; 21 | NSArray *array = (NSArray *)self; 22 | for (NSUInteger i = 0; i < array.count; i++) { 23 | if (i > 0) [joined appendString:delimiter]; 24 | NSObject *item = [array objectAtIndex:i]; 25 | [joined appendString:[item description]]; 26 | } 27 | return [NSString stringWithString:joined]; 28 | } 29 | 30 | @end 31 | -------------------------------------------------------------------------------- /httpdoc-objc/src/main/resources/httpdoc-sdk/objc-sdk/RSNetworking/NSArray+RSURLEncoder.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSArray+RSURLEncoder.h 3 | // RSNetworking 4 | // 5 | // Created by 杨昌沛 on 2018/7/19. 6 | // Copyright © 2018年 杨昌沛. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface NSArray (RSURLEncoder) 12 | 13 | - (NSArray *)URLEncodeds; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /httpdoc-objc/src/main/resources/httpdoc-sdk/objc-sdk/RSNetworking/NSArray+RSURLEncoder.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSArray+RSURLEncoder.m 3 | // RSNetworking 4 | // 5 | // Created by 杨昌沛 on 2018/7/19. 6 | // Copyright © 2018年 杨昌沛. All rights reserved. 7 | // 8 | 9 | #import "NSArray+RSURLEncoder.h" 10 | #import "NSString+RSURLEncoder.h" 11 | 12 | @implementation NSArray (RSURLEncoder) 13 | 14 | - (NSArray *)URLEncodeds 15 | { 16 | NSMutableArray *encodeds = [NSMutableArray arrayWithCapacity:self.count]; 17 | for (id url in self) { 18 | [encodeds addObject:[[url description] URLEncoded]]; 19 | } 20 | return [NSArray arrayWithArray:encodeds]; 21 | } 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /httpdoc-objc/src/main/resources/httpdoc-sdk/objc-sdk/RSNetworking/NSObject+RSJSON.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSObject+RSJSON.h 3 | // RSNetworking 4 | // 5 | // Created by 杨昌沛 on 2018/7/19. 6 | // Copyright © 2018年 杨昌沛. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface NSObject (RSJSON) 12 | 13 | - (NSString *)toJSONString; 14 | 15 | - (id)toJSONObject; 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /httpdoc-objc/src/main/resources/httpdoc-sdk/objc-sdk/RSNetworking/NSObject+RSMultipart.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSObject+RSMultipart.h 3 | // RSNetworking 4 | // 5 | // Created by 杨昌沛 on 2018/7/30. 6 | // Copyright © 2018年 杨昌沛. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "RSInvocation.h" 11 | 12 | @interface NSObject (RSMultipart) 13 | 14 | - (RSPart *)toMultipartForName:(NSString *)name mimeType:(NSString *)mimeType filename:(NSString *)filename; 15 | 16 | - (bool)isMultipart; 17 | 18 | - (bool)isMultipartFile; 19 | 20 | - (bool)isMultipartArray; 21 | 22 | - (bool)isMultipartDictionary; 23 | 24 | @end 25 | -------------------------------------------------------------------------------- /httpdoc-objc/src/main/resources/httpdoc-sdk/objc-sdk/RSNetworking/NSString+RSURLEncoder.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+URLEncoder.h 3 | // RSNetworking 4 | // 5 | // Created by 杨昌沛 on 2018/7/19. 6 | // Copyright © 2018年 杨昌沛. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface NSString (RSURLEncoder) 12 | 13 | - (NSString *)URLEncoded; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /httpdoc-objc/src/main/resources/httpdoc-sdk/objc-sdk/RSNetworking/NSString+RSURLEncoder.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+URLEncoder.m 3 | // RSNetworking 4 | // 5 | // Created by 杨昌沛 on 2018/7/19. 6 | // Copyright © 2018年 杨昌沛. All rights reserved. 7 | // 8 | 9 | #import "NSString+RSURLEncoder.h" 10 | 11 | @implementation NSString (RSURLEncoder) 12 | 13 | - (NSString *)URLEncoded 14 | { 15 | return [self stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLPathAllowedCharacterSet]]; 16 | } 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /httpdoc-objc/src/main/resources/httpdoc-sdk/objc-sdk/RSNetworking/RSBodyHandler.h: -------------------------------------------------------------------------------- 1 | // 2 | // RSBodyHandler.h 3 | // RSNetworking 4 | // 5 | // Created by 杨昌沛 on 2018/7/19. 6 | // Copyright © 2018年 杨昌沛. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "RSInvocation.h" 11 | 12 | @interface RSBodyHandler : NSObject 13 | 14 | @end 15 | -------------------------------------------------------------------------------- /httpdoc-objc/src/main/resources/httpdoc-sdk/objc-sdk/RSNetworking/RSClient.h: -------------------------------------------------------------------------------- 1 | // 2 | // RSClient.h 3 | // RSNetworking 4 | // 5 | // Created by 杨昌沛 on 2018/7/19. 6 | // Copyright © 2018年 杨昌沛. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "RSInvocation.h" 11 | #import "AFNetworking.h" 12 | 13 | @protocol RSCall 14 | 15 | - (void)resume; 16 | 17 | - (void)resume:(void (^)(BOOL success, id result, NSError *error))callback; 18 | 19 | @end 20 | 21 | @protocol RSClient 22 | 23 | - (id)invoke:(RSInvocation *)invocation callback:(void (^)(BOOL success, id result, NSError *error))callback; 24 | 25 | - (void)addForeInterceptor:(id)interceptor; 26 | 27 | - (void)addBackInterceptor:(id)interceptor; 28 | 29 | @end 30 | 31 | @interface RSAFNetworkingCall : NSObject 32 | 33 | @end 34 | 35 | @interface RSAFNetworkingClient : NSObject 36 | 37 | - (instancetype)initWithSessionManager:(AFHTTPSessionManager *)sessionManager; 38 | 39 | @end 40 | -------------------------------------------------------------------------------- /httpdoc-objc/src/main/resources/httpdoc-sdk/objc-sdk/RSNetworking/RSConversion.h: -------------------------------------------------------------------------------- 1 | // 2 | // RSConversion.h 3 | // RSNetworking 4 | // 5 | // Created by 杨昌沛 on 2018/7/19. 6 | // Copyright © 2018年 杨昌沛. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | // 转换器 12 | @protocol RSConverter 13 | 14 | - (NSDateFormatter *)getDateFormatter; 15 | 16 | - (void)setDateFormatter:(NSDateFormatter *)dateFormatter; 17 | 18 | - (BOOL)atomic:(Class)type; 19 | 20 | - (NSDictionary *> *)convertValue:(id)value forName:(NSString *)name; 21 | 22 | @end 23 | 24 | // 规约器 25 | @protocol RSReducer 26 | 27 | - (BOOL)atomic; 28 | 29 | - (BOOL)supports:(Class)type; 30 | 31 | - (NSDictionary *> *)reduceValue:(id)value forName:(NSString *)name byConverter:(id) converter; 32 | 33 | @end 34 | 35 | @interface RSDefaultConverter : NSObject 36 | 37 | + (instancetype)converter; 38 | 39 | @end 40 | 41 | @interface RSStringReducer : NSObject 42 | 43 | @end; 44 | 45 | @interface RSNumberReducer : NSObject 46 | 47 | @end; 48 | 49 | @interface RSDateReducer : NSObject 50 | 51 | @end; 52 | 53 | @interface RSArrayReducer : NSObject 54 | 55 | @end; 56 | 57 | @interface RSSetReducer : NSObject 58 | 59 | @end 60 | 61 | @interface RSDictionaryReducer : NSObject 62 | 63 | @end; 64 | -------------------------------------------------------------------------------- /httpdoc-objc/src/main/resources/httpdoc-sdk/objc-sdk/RSNetworking/RSCookieHandler.h: -------------------------------------------------------------------------------- 1 | // 2 | // RSCookieHandler.h 3 | // RSNetworking 4 | // 5 | // Created by 杨昌沛 on 2018/7/19. 6 | // Copyright © 2018年 杨昌沛. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "RSInvocation.h" 11 | 12 | @interface RSCookieHandler : NSObject 13 | 14 | @end 15 | -------------------------------------------------------------------------------- /httpdoc-objc/src/main/resources/httpdoc-sdk/objc-sdk/RSNetworking/RSErrors.h: -------------------------------------------------------------------------------- 1 | // 2 | // RSErrors.h 3 | // RSNetworking 4 | // 5 | // Created by 杨昌沛 on 2018/7/21. 6 | // Copyright © 2018年 杨昌沛. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | FOUNDATION_EXPORT NSErrorDomain const RSNetworkingErrorDomain; 12 | 13 | FOUNDATION_EXPORT NSErrorUserInfoKey const RSErrorUserInfoNameKey; 14 | FOUNDATION_EXPORT NSErrorUserInfoKey const RSErrorUserInfoReasonKey; 15 | 16 | typedef NS_ENUM(NSInteger, RSErrorCode) { 17 | RSErrorCodeUnknownFailure = 1, 18 | RSErrorCodeInvalidArgument 19 | }; 20 | -------------------------------------------------------------------------------- /httpdoc-objc/src/main/resources/httpdoc-sdk/objc-sdk/RSNetworking/RSErrors.m: -------------------------------------------------------------------------------- 1 | // 2 | // RSErrors.m 3 | // RSNetworking 4 | // 5 | // Created by 杨昌沛 on 2018/7/21. 6 | // Copyright © 2018年 杨昌沛. All rights reserved. 7 | // 8 | 9 | #import "RSErrors.h" 10 | 11 | NSErrorDomain const RSNetworkingErrorDomain = @"RSNetworkingErrorDomain"; 12 | 13 | NSErrorUserInfoKey const RSErrorUserInfoNameKey = @"RSErrorUserInfoNameKey"; 14 | NSErrorUserInfoKey const RSErrorUserInfoReasonKey = @"RSErrorUserInfoReasonKey"; 15 | -------------------------------------------------------------------------------- /httpdoc-objc/src/main/resources/httpdoc-sdk/objc-sdk/RSNetworking/RSHeaderHandler.h: -------------------------------------------------------------------------------- 1 | // 2 | // RSHeaderHandler.h 3 | // RSNetworking 4 | // 5 | // Created by 杨昌沛 on 2018/7/19. 6 | // Copyright © 2018年 杨昌沛. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "RSInvocation.h" 11 | 12 | @interface RSHeaderHandler : NSObject 13 | 14 | @end 15 | -------------------------------------------------------------------------------- /httpdoc-objc/src/main/resources/httpdoc-sdk/objc-sdk/RSNetworking/RSHeaderHandler.m: -------------------------------------------------------------------------------- 1 | // 2 | // RSHeaderHandler.m 3 | // RSNetworking 4 | // 5 | // Created by 杨昌沛 on 2018/7/19. 6 | // Copyright © 2018年 杨昌沛. All rights reserved. 7 | // 8 | 9 | #import "RSHeaderHandler.h" 10 | #import "RSConversion.h" 11 | #import "NSString+RSURLEncoder.h" 12 | 13 | @interface RSHeaderHandler () 14 | 15 | @property (nonatomic, strong) id converter; 16 | 17 | @end 18 | 19 | @implementation RSHeaderHandler 20 | 21 | - (instancetype)init 22 | { 23 | self = [super init]; 24 | if (self) { 25 | _converter = [RSDefaultConverter converter]; 26 | } 27 | return self; 28 | } 29 | 30 | - (void)intercept:(RSInvocation *)invocation interception:(RSInterception *)interception callback:(void (^)(BOOL, id, NSError *))callback { 31 | for (RSParameter *parameter in invocation.parameters) { 32 | if (parameter.scope != RSScopeHEADER || parameter.value == nil) continue; 33 | NSString *name = parameter.name; 34 | id value = parameter.value; 35 | NSDictionary *> *dictionary = [_converter convertValue:value forName:name]; 36 | [dictionary enumerateKeysAndObjectsUsingBlock:^(NSString * _Nonnull key, NSArray * _Nonnull obj, BOOL * _Nonnull stop) { 37 | NSArray *values = obj; 38 | for (NSString *value in values) { 39 | [invocation.headers setObject:[value URLEncoded] forKey:[key URLEncoded]]; 40 | } 41 | }]; 42 | } 43 | [interception doNext:invocation callback:callback]; 44 | } 45 | 46 | @end 47 | -------------------------------------------------------------------------------- /httpdoc-objc/src/main/resources/httpdoc-sdk/objc-sdk/RSNetworking/RSNetworking.h: -------------------------------------------------------------------------------- 1 | // 2 | // RSNetworking.h 3 | // RSNetworking 4 | // 5 | // Created by 杨昌沛 on 2018/7/19. 6 | // Copyright © 2018年 杨昌沛. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #ifndef _RSNETWORKING_ 12 | #define _RSNETWORKING_ 13 | #import "RSErrors.h" 14 | #import "RSConversion.h" 15 | #import "RSInvocation.h" 16 | #import "RSClient.h" 17 | #import "NSString+RSURLEncoder.h" 18 | #import "NSArray+RSURLEncoder.h" 19 | #import "NSObject+RSJSON.h" 20 | #import "NSArray+RSJoining.h" 21 | #import "NSObject+RSMultipart.h" 22 | #endif 23 | -------------------------------------------------------------------------------- /httpdoc-objc/src/main/resources/httpdoc-sdk/objc-sdk/RSNetworking/RSPathHandler.h: -------------------------------------------------------------------------------- 1 | // 2 | // RSPathHandler.h 3 | // RSNetworking 4 | // 5 | // Created by 杨昌沛 on 2018/7/19. 6 | // Copyright © 2018年 杨昌沛. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "RSInvocation.h" 11 | 12 | @interface RSPathHandler : NSObject 13 | 14 | @end 15 | -------------------------------------------------------------------------------- /httpdoc-objc/src/main/resources/httpdoc-sdk/objc-sdk/RSNetworking/RSQueryHandler.h: -------------------------------------------------------------------------------- 1 | // 2 | // RSQueryHandler.h 3 | // RSNetworking 4 | // 5 | // Created by 杨昌沛 on 2018/7/19. 6 | // Copyright © 2018年 杨昌沛. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "RSInvocation.h" 11 | 12 | @interface RSQueryHandler : NSObject 13 | 14 | @end 15 | -------------------------------------------------------------------------------- /httpdoc-objc/src/main/resources/httpdoc-sdk/objc-sdk/RSNetworking/RSResultHandler.h: -------------------------------------------------------------------------------- 1 | // 2 | // RSResultHandler.h 3 | // RSNetworking 4 | // 5 | // Created by 杨昌沛 on 2018/7/19. 6 | // Copyright © 2018年 杨昌沛. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "RSInvocation.h" 11 | 12 | @interface RSResultHandler : NSObject 13 | 14 | @end 15 | -------------------------------------------------------------------------------- /httpdoc-objc/src/main/resources/httpdoc-sdk/objc-sdk/RSNetworking/RSResultHandler.m: -------------------------------------------------------------------------------- 1 | // 2 | // RSResultHandler.m 3 | // RSNetworking 4 | // 5 | // Created by 杨昌沛 on 2018/7/19. 6 | // Copyright © 2018年 杨昌沛. All rights reserved. 7 | // 8 | 9 | #import "RSResultHandler.h" 10 | #import "MJExtension.h" 11 | 12 | @implementation RSResultHandler 13 | 14 | - (void)intercept:(RSInvocation *)invocation interception:(RSInterception *)interception callback:(void (^)(BOOL, id, NSError *))callback { 15 | [interception doNext:invocation callback:^(BOOL success, id result, NSError *error) { 16 | Class resultType = invocation.resultType; 17 | if (!success || resultType == nil) { 18 | callback(success, result, error); 19 | return; 20 | } 21 | if ([result isKindOfClass:[NSArray class]]) { 22 | id objs = [resultType mj_objectArrayWithKeyValuesArray:result]; 23 | callback(success, objs, error); 24 | } else { 25 | id obj = [resultType mj_objectWithKeyValues:result]; 26 | callback(success, obj, error); 27 | } 28 | }]; 29 | } 30 | 31 | @end 32 | -------------------------------------------------------------------------------- /httpdoc-objc/src/main/resources/httpdoc/exporter.properties: -------------------------------------------------------------------------------- 1 | ObjC=io.httpdoc.objc.ObjCExporter -------------------------------------------------------------------------------- /httpdoc-objc/src/main/resources/httpdoc/modeler.properties: -------------------------------------------------------------------------------- 1 | MJExtension=io.httpdoc.objc.ObjCMJExtensionModeler -------------------------------------------------------------------------------- /httpdoc-objc/src/main/resources/httpdoc/selector-naming-strategy.properties: -------------------------------------------------------------------------------- 1 | default=io.httpdoc.objc.ObjCSELDefaultNamingStrategy 2 | underline=io.httpdoc.objc.ObjCSELUnderlineNamingStrategy -------------------------------------------------------------------------------- /httpdoc-retrofit/src/main/java/io/httpdoc/retrofit/RetrofitModeler.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.retrofit; 2 | 3 | import io.httpdoc.core.fragment.ClassFragment; 4 | import io.httpdoc.core.modeler.Modeler; 5 | 6 | /** 7 | * Retrofit模型师 8 | * 9 | * @author Payne 646742615@qq.com 10 | * 2019/3/29 14:39 11 | */ 12 | public interface RetrofitModeler extends Modeler { 13 | } 14 | -------------------------------------------------------------------------------- /httpdoc-retrofit/src/main/java/io/httpdoc/retrofit/RetrofitSimpleModeler.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.retrofit; 2 | 3 | import io.httpdoc.core.modeler.SimpleModeler; 4 | 5 | /** 6 | * Retrofit简单模型师 7 | * 8 | * @author Payne 646742615@qq.com 9 | * 2019/3/29 14:43 10 | */ 11 | public class RetrofitSimpleModeler extends SimpleModeler implements RetrofitModeler { 12 | } 13 | -------------------------------------------------------------------------------- /httpdoc-retrofit/src/main/java/io/httpdoc/retrofit/RetrofitSupplier.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.retrofit; 2 | 3 | import io.httpdoc.core.Schema; 4 | import io.httpdoc.core.supplier.Supplier; 5 | import io.httpdoc.core.supplier.SystemSupplier; 6 | import okhttp3.RequestBody; 7 | 8 | import java.lang.reflect.Type; 9 | 10 | /** 11 | * Retrofit 类型提供器 12 | * 13 | * @author 杨昌沛 646742615@qq.com 14 | * @date 2018-05-16 13:39 15 | **/ 16 | public class RetrofitSupplier implements Supplier { 17 | private final Supplier supplier; 18 | 19 | public RetrofitSupplier() { 20 | this(new SystemSupplier()); 21 | } 22 | 23 | public RetrofitSupplier(Supplier supplier) { 24 | this.supplier = supplier; 25 | } 26 | 27 | @Override 28 | public boolean contains(Type type) { 29 | return supplier.contains(type); 30 | } 31 | 32 | @Override 33 | public Schema acquire(Type type) { 34 | return supplier.acquire(type); 35 | } 36 | 37 | @Override 38 | public boolean contains(Schema schema) { 39 | return supplier.contains(schema); 40 | } 41 | 42 | @Override 43 | public Type acquire(Schema schema) { 44 | if ("File".equals(schema.getName())) return RequestBody.class; 45 | else return supplier.acquire(schema); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /httpdoc-retrofit/src/main/resources/httpdoc-sdk/retrofit-sdk/src/test/java/io/httpdoc/SDKGenerator.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc; 2 | 3 | import io.httpdoc.core.Document; 4 | import io.httpdoc.core.generation.Generation; 5 | import io.httpdoc.jackson.deserialization.JsonDeserializer; 6 | import io.httpdoc.retrofit.RetrofitMergedGenerator; 7 | import io.httpdoc.retrofit.RetrofitSupplier; 8 | import org.junit.Test; 9 | 10 | import java.net.URL; 11 | 12 | public class SDKGenerator { 13 | 14 | @Test 15 | public void generate() throws Exception { 16 | RetrofitMergedGenerator generator = new RetrofitMergedGenerator(); 17 | // generator.include(RetrofitStandardGenerator.class); 18 | // generator.include(RetrofitCallbackGenerator.class); 19 | // generator.include(RetrofitRxJavaGenerator.class); 20 | 21 | Document document = Document.from(new URL("http://localhost:8080/httpdoc.json"), new JsonDeserializer()); 22 | Generation generation = new Generation(document); 23 | generation.setDirectory(System.getProperty("user.dir") + "/src/main/java"); // set generate directory 24 | generation.setSupplier(new RetrofitSupplier()); // set type supplier 25 | // generation.setPkg(); // set default package 26 | // generation.setPkgForced(); // set forced package 27 | // generation.setStrategy(); // set generate strategy 28 | 29 | generator.generate(generation); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /httpdoc-retrofit/src/main/resources/httpdoc/exporter.properties: -------------------------------------------------------------------------------- 1 | Retrofit=io.httpdoc.retrofit.RetrofitExporter -------------------------------------------------------------------------------- /httpdoc-retrofit/src/main/resources/httpdoc/generator.properties: -------------------------------------------------------------------------------- 1 | standard=io.httpdoc.retrofit.RetrofitStandardGenerator 2 | callback=io.httpdoc.retrofit.RetrofitCallbackGenerator 3 | rxjava=io.httpdoc.retrofit.RetrofitRxJavaGenerator -------------------------------------------------------------------------------- /httpdoc-retrofit/src/main/resources/httpdoc/modeler.properties: -------------------------------------------------------------------------------- 1 | simple=io.httpdoc.retrofit.RetrofitSimpleModeler -------------------------------------------------------------------------------- /httpdoc-retrofit2/src/main/java/io/httpdoc/retrofit2/Retrofit2Modeler.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.retrofit2; 2 | 3 | import io.httpdoc.core.fragment.ClassFragment; 4 | import io.httpdoc.core.modeler.Modeler; 5 | 6 | /** 7 | * Retrofit模型师 8 | * 9 | * @author Payne 646742615@qq.com 10 | * 2019/3/29 14:39 11 | */ 12 | public interface Retrofit2Modeler extends Modeler { 13 | } 14 | -------------------------------------------------------------------------------- /httpdoc-retrofit2/src/main/java/io/httpdoc/retrofit2/Retrofit2SimpleModeler.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.retrofit2; 2 | 3 | import io.httpdoc.core.modeler.SimpleModeler; 4 | 5 | /** 6 | * Retrofit简单模型师 7 | * 8 | * @author Payne 646742615@qq.com 9 | * 2019/3/29 14:43 10 | */ 11 | public class Retrofit2SimpleModeler extends SimpleModeler implements Retrofit2Modeler { 12 | } 13 | -------------------------------------------------------------------------------- /httpdoc-retrofit2/src/main/java/io/httpdoc/retrofit2/Retrofit2Supplier.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.retrofit2; 2 | 3 | import io.httpdoc.core.Schema; 4 | import io.httpdoc.core.supplier.Supplier; 5 | import io.httpdoc.core.supplier.SystemSupplier; 6 | import okhttp3.RequestBody; 7 | 8 | import java.lang.reflect.Type; 9 | 10 | /** 11 | * Retrofit 类型提供器 12 | * 13 | * @author 杨昌沛 646742615@qq.com 14 | * @date 2018-05-16 13:39 15 | **/ 16 | public class Retrofit2Supplier implements Supplier { 17 | private final Supplier supplier; 18 | 19 | public Retrofit2Supplier() { 20 | this(new SystemSupplier()); 21 | } 22 | 23 | public Retrofit2Supplier(Supplier supplier) { 24 | this.supplier = supplier; 25 | } 26 | 27 | @Override 28 | public boolean contains(Type type) { 29 | return supplier.contains(type); 30 | } 31 | 32 | @Override 33 | public Schema acquire(Type type) { 34 | return supplier.acquire(type); 35 | } 36 | 37 | @Override 38 | public boolean contains(Schema schema) { 39 | return supplier.contains(schema); 40 | } 41 | 42 | @Override 43 | public Type acquire(Schema schema) { 44 | if ("File".equals(schema.getName())) return RequestBody.class; 45 | else return supplier.acquire(schema); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /httpdoc-retrofit2/src/main/resources/httpdoc/exporter.properties: -------------------------------------------------------------------------------- 1 | Retrofit2=io.httpdoc.retrofit2.Retrofit2Exporter -------------------------------------------------------------------------------- /httpdoc-retrofit2/src/main/resources/httpdoc/generator.properties: -------------------------------------------------------------------------------- 1 | call=io.httpdoc.retrofit2.Retrofit2CallGenerator 2 | guava=io.httpdoc.retrofit2.Retrofit2GuavaGenerator 3 | java8=io.httpdoc.retrofit2.Retrofit2Java8Generator 4 | rxjava=io.httpdoc.retrofit2.Retrofit2RxJavaGenerator 5 | rxjava2=io.httpdoc.retrofit2.Retrofit2RxJava2Generator -------------------------------------------------------------------------------- /httpdoc-retrofit2/src/main/resources/httpdoc/modeler.properties: -------------------------------------------------------------------------------- 1 | simple=io.httpdoc.retrofit2.Retrofit2SimpleModeler -------------------------------------------------------------------------------- /httpdoc-sample/src/main/java/io/httpdoc/sample/ApiResult.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.sample; 2 | 3 | /** 4 | * API结果超类 5 | * 6 | * @author 杨昌沛 646742615@qq.com 7 | * 2018/11/5 8 | */ 9 | public class ApiResult { 10 | /** 11 | * 状态码,0代表成功,非0则代表失败,且不同的状态码对应不同的错误类型 12 | */ 13 | private int code = 0; 14 | /** 15 | * 消息 16 | */ 17 | private String message = "OK"; 18 | 19 | public int getCode() { 20 | return code; 21 | } 22 | 23 | public void setCode(int code) { 24 | this.code = code; 25 | } 26 | 27 | public String getMessage() { 28 | return message; 29 | } 30 | 31 | public void setMessage(String message) { 32 | this.message = message; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /httpdoc-sample/src/main/java/io/httpdoc/sample/LoginResult.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.sample; 2 | 3 | import io.httpdoc.sample.user.User; 4 | 5 | /** 6 | * 登陆结果 7 | */ 8 | public class LoginResult extends ApiResult { 9 | /** 10 | * 用户数据,登录失败时该字段为null 11 | */ 12 | private User user; 13 | 14 | public User getUser() { 15 | return user; 16 | } 17 | 18 | public void setUser(User user) { 19 | this.user = user; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /httpdoc-sample/src/main/java/io/httpdoc/sample/order/Order.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.sample.order; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * 订单 7 | * 8 | * @author 杨昌沛 646742615@qq.com 9 | * 2018/11/16 10 | * @style normal 11 | */ 12 | public class Order { 13 | /** 14 | * 用户ID 15 | * 16 | * @order 1 17 | */ 18 | private String userId; 19 | /** 20 | * 收货地址 21 | * 22 | * @order 2 23 | */ 24 | private String address; 25 | /** 26 | * 电话 27 | * 28 | * @order 3 29 | */ 30 | private String telephone; 31 | /** 32 | * 订单项 33 | * 34 | * @order 4 35 | * @style table 36 | */ 37 | private List items; 38 | 39 | public String getUserId() { 40 | return userId; 41 | } 42 | 43 | public void setUserId(String userId) { 44 | this.userId = userId; 45 | } 46 | 47 | public String getAddress() { 48 | return address; 49 | } 50 | 51 | public void setAddress(String address) { 52 | this.address = address; 53 | } 54 | 55 | public String getTelephone() { 56 | return telephone; 57 | } 58 | 59 | public void setTelephone(String telephone) { 60 | this.telephone = telephone; 61 | } 62 | 63 | public List getItems() { 64 | return items; 65 | } 66 | 67 | public void setItems(List items) { 68 | this.items = items; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /httpdoc-sample/src/main/java/io/httpdoc/sample/order/OrderCreateResult.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.sample.order; 2 | 3 | import io.httpdoc.sample.ApiResult; 4 | 5 | import java.math.BigDecimal; 6 | 7 | /** 8 | * 订单创建结果 9 | * 10 | * @author 杨昌沛 646742615@qq.com 11 | * 2018/11/16 12 | */ 13 | public class OrderCreateResult extends ApiResult { 14 | /** 15 | * 订单ID 16 | */ 17 | private Long orderId; 18 | /** 19 | * 总金额 20 | */ 21 | private BigDecimal amount; 22 | 23 | public Long getOrderId() { 24 | return orderId; 25 | } 26 | 27 | public void setOrderId(Long orderId) { 28 | this.orderId = orderId; 29 | } 30 | 31 | public BigDecimal getAmount() { 32 | return amount; 33 | } 34 | 35 | public void setAmount(BigDecimal amount) { 36 | this.amount = amount; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /httpdoc-sample/src/main/java/io/httpdoc/sample/order/OrderItem.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.sample.order; 2 | 3 | /** 4 | * 订单项 5 | * 6 | * @author 杨昌沛 646742615@qq.com 7 | * 2018/11/16 8 | */ 9 | public class OrderItem { 10 | /** 11 | * SKU条码 12 | */ 13 | private String barcode; 14 | /** 15 | * 数量 16 | */ 17 | private int quantity; 18 | 19 | public String getBarcode() { 20 | return barcode; 21 | } 22 | 23 | public void setBarcode(String barcode) { 24 | this.barcode = barcode; 25 | } 26 | 27 | public int getQuantity() { 28 | return quantity; 29 | } 30 | 31 | public void setQuantity(int quantity) { 32 | this.quantity = quantity; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /httpdoc-sample/src/main/java/io/httpdoc/sample/product/Brand.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.sample.product; 2 | 3 | /** 4 | * 品牌 5 | * @style grid 6 | */ 7 | public class Brand { 8 | /** 9 | * 品牌ID 10 | */ 11 | private Long id; 12 | /** 13 | * 品牌名称 14 | */ 15 | private String name; 16 | 17 | public Long getId() { 18 | return id; 19 | } 20 | 21 | public void setId(Long id) { 22 | this.id = id; 23 | } 24 | 25 | public String getName() { 26 | return name; 27 | } 28 | 29 | public void setName(String name) { 30 | this.name = name; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /httpdoc-sample/src/main/java/io/httpdoc/sample/product/Category.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.sample.product; 2 | 3 | /** 4 | * 类别 5 | * 6 | * @author 杨昌沛 646742615@qq.com 7 | * 2018/11/16 8 | */ 9 | public class Category { 10 | /** 11 | * 类别ID 12 | */ 13 | private Long id; 14 | /** 15 | * 类别名称 16 | */ 17 | private String name; 18 | /** 19 | * 父类别,自引用/递归属性 20 | */ 21 | private Category parent; 22 | 23 | public Long getId() { 24 | return id; 25 | } 26 | 27 | public void setId(Long id) { 28 | this.id = id; 29 | } 30 | 31 | public String getName() { 32 | return name; 33 | } 34 | 35 | public void setName(String name) { 36 | this.name = name; 37 | } 38 | 39 | public Category getParent() { 40 | return parent; 41 | } 42 | 43 | public void setParent(Category parent) { 44 | this.parent = parent; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /httpdoc-sample/src/main/java/io/httpdoc/sample/product/ProductCreateResult.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.sample.product; 2 | 3 | import io.httpdoc.sample.ApiResult; 4 | 5 | /** 6 | * 产品创建结果 7 | */ 8 | public class ProductCreateResult extends ApiResult { 9 | private Long productId; 10 | 11 | public Long getProductId() { 12 | return productId; 13 | } 14 | 15 | public void setProductId(Long productId) { 16 | this.productId = productId; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /httpdoc-sample/src/main/java/io/httpdoc/sample/product/ProductDeleteResult.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.sample.product; 2 | 3 | import io.httpdoc.sample.ApiResult; 4 | 5 | /** 6 | * 产品删除结果 7 | */ 8 | public class ProductDeleteResult extends ApiResult { 9 | 10 | } 11 | -------------------------------------------------------------------------------- /httpdoc-sample/src/main/java/io/httpdoc/sample/product/ProductQueryResult.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.sample.product; 2 | 3 | import io.httpdoc.sample.ApiResult; 4 | 5 | /** 6 | * 产品查询结果 7 | */ 8 | public class ProductQueryResult extends ApiResult { 9 | private Product product; 10 | 11 | public Product getProduct() { 12 | return product; 13 | } 14 | 15 | public void setProduct(Product product) { 16 | this.product = product; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /httpdoc-sample/src/main/java/io/httpdoc/sample/product/ProductUpdateResult.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.sample.product; 2 | 3 | import io.httpdoc.sample.ApiResult; 4 | 5 | /** 6 | * 产品创建结果 7 | */ 8 | public class ProductUpdateResult extends ApiResult { 9 | } 10 | -------------------------------------------------------------------------------- /httpdoc-sample/src/main/java/io/httpdoc/sample/product/Sku.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.sample.product; 2 | 3 | /** 4 | * SKU 5 | */ 6 | public class Sku { 7 | /** 8 | * 条码 9 | */ 10 | private String barcode; 11 | /** 12 | * 颜色 13 | */ 14 | private String color; 15 | /** 16 | * 尺码 17 | */ 18 | private String size; 19 | 20 | public String getBarcode() { 21 | return barcode; 22 | } 23 | 24 | public void setBarcode(String barcode) { 25 | this.barcode = barcode; 26 | } 27 | 28 | public String getColor() { 29 | return color; 30 | } 31 | 32 | public void setColor(String color) { 33 | this.color = color; 34 | } 35 | 36 | public String getSize() { 37 | return size; 38 | } 39 | 40 | public void setSize(String size) { 41 | this.size = size; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /httpdoc-sample/src/main/java/io/httpdoc/sample/user/Gender.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.sample.user; 2 | 3 | /** 4 | * 性别 5 | */ 6 | public enum Gender { 7 | 8 | /** 9 | * 男 10 | */ 11 | MALE, 12 | /** 13 | * 女 14 | */ 15 | FEMALE 16 | 17 | } 18 | -------------------------------------------------------------------------------- /httpdoc-sample/src/main/java/io/httpdoc/sample/user/UserCreateResult.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.sample.user; 2 | 3 | import io.httpdoc.sample.ApiResult; 4 | 5 | /** 6 | * 用户创建结果 7 | */ 8 | public class UserCreateResult extends ApiResult { 9 | /** 10 | * 新建用户的ID,当请求失败时该字段为null 11 | */ 12 | private Long userId; 13 | 14 | public Long getUserId() { 15 | return userId; 16 | } 17 | 18 | public void setUserId(Long userId) { 19 | this.userId = userId; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /httpdoc-sample/src/main/java/io/httpdoc/sample/user/UserDeleteResult.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.sample.user; 2 | 3 | import io.httpdoc.sample.ApiResult; 4 | 5 | /** 6 | * 用户删除结果 7 | */ 8 | public class UserDeleteResult extends ApiResult { 9 | } 10 | -------------------------------------------------------------------------------- /httpdoc-sample/src/main/java/io/httpdoc/sample/user/UserQueryResult.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.sample.user; 2 | 3 | import io.httpdoc.sample.ApiResult; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * 用户分页查询结果 9 | */ 10 | public class UserQueryResult extends ApiResult { 11 | /** 12 | * 总条数 13 | */ 14 | private int total; 15 | /** 16 | * 当前页面用户列表 17 | */ 18 | private List users; 19 | 20 | public int getTotal() { 21 | return total; 22 | } 23 | 24 | public void setTotal(int total) { 25 | this.total = total; 26 | } 27 | 28 | public List getUsers() { 29 | return users; 30 | } 31 | 32 | public void setUsers(List users) { 33 | this.users = users; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /httpdoc-sample/src/main/java/io/httpdoc/sample/user/UserUpdateResult.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.sample.user; 2 | 3 | import io.httpdoc.sample.ApiResult; 4 | 5 | /** 6 | * 用户更新结果 7 | */ 8 | public class UserUpdateResult extends ApiResult { 9 | } 10 | -------------------------------------------------------------------------------- /httpdoc-sample/src/main/resources/spring-context.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /httpdoc-sample/src/main/webapp/index.jsp: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /httpdoc-spring-boot/src/main/java/io/httpdoc/spring/boot/Param.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.spring.boot; 2 | 3 | import java.lang.annotation.*; 4 | 5 | /** 6 | * Filter Init Parameter 7 | * 8 | * @author 杨昌沛 646742615@qq.com 9 | * @date 2018-08-08 10:39 10 | **/ 11 | @Target(ElementType.ANNOTATION_TYPE) 12 | @Retention(RetentionPolicy.RUNTIME) 13 | @Inherited 14 | @Documented 15 | public @interface Param { 16 | 17 | /** 18 | * @return Filter Init Parameter Name 19 | */ 20 | String name(); 21 | 22 | /** 23 | * @return Filter Init Parameter Value 24 | */ 25 | String value(); 26 | 27 | } 28 | -------------------------------------------------------------------------------- /httpdoc-spring-mvc/src/main/java/io/httpdoc/spring/mvc/ControllerTranslation.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.spring.mvc; 2 | 3 | import io.httpdoc.core.Document; 4 | import io.httpdoc.core.translation.Translation; 5 | 6 | public class ControllerTranslation extends SpringMVCTranslation { 7 | private final Document document; 8 | 9 | public ControllerTranslation(Translation translation, Document document) { 10 | super(translation); 11 | this.document = document; 12 | } 13 | 14 | public Document getDocument() { 15 | return document; 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /httpdoc-spring-mvc/src/main/java/io/httpdoc/spring/mvc/Module.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.spring.mvc; 2 | 3 | import io.httpdoc.core.Build; 4 | 5 | import java.io.Serializable; 6 | 7 | /** 8 | * Created by payne on 2017/3/28. 9 | */ 10 | public class Module extends Build implements Serializable { 11 | private static final long serialVersionUID = 8979830823718754930L; 12 | 13 | private static volatile Module instance; 14 | 15 | private String name; 16 | private String version; 17 | private String parentName; 18 | private String parentVersion; 19 | 20 | private Module() { 21 | } 22 | 23 | public static Module getInstance() { 24 | if (instance != null) return instance; 25 | synchronized (Module.class) { 26 | if (instance != null) return instance; 27 | return instance = new Module(); 28 | } 29 | } 30 | 31 | public String getName() { 32 | return name; 33 | } 34 | 35 | public String getVersion() { 36 | return version; 37 | } 38 | 39 | public String getParentName() { 40 | return parentName; 41 | } 42 | 43 | public String getParentVersion() { 44 | return parentVersion; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /httpdoc-spring-mvc/src/main/java/io/httpdoc/spring/mvc/OperationTranslation.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.spring.mvc; 2 | 3 | import io.httpdoc.core.Controller; 4 | import org.springframework.web.method.HandlerMethod; 5 | import org.springframework.web.servlet.mvc.method.RequestMappingInfo; 6 | 7 | import java.lang.reflect.Method; 8 | 9 | public class OperationTranslation extends SpringMVCTranslation { 10 | private final RequestMappingInfo mapping; 11 | private final HandlerMethod handler; 12 | private final Method method; 13 | private final Controller controller; 14 | 15 | public OperationTranslation(SpringMVCTranslation parent, RequestMappingInfo mapping, HandlerMethod handler, Method method, Controller controller) { 16 | super(parent); 17 | this.mapping = mapping; 18 | this.handler = handler; 19 | this.method = method; 20 | this.controller = controller; 21 | } 22 | 23 | public RequestMappingInfo getMapping() { 24 | return mapping; 25 | } 26 | 27 | public HandlerMethod getHandler() { 28 | return handler; 29 | } 30 | 31 | public Method getMethod() { 32 | return method; 33 | } 34 | 35 | public Controller getController() { 36 | return controller; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /httpdoc-spring-mvc/src/main/java/io/httpdoc/spring/mvc/ParameterTranslation.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.spring.mvc; 2 | 3 | import io.httpdoc.core.Controller; 4 | import io.httpdoc.core.Operation; 5 | import org.springframework.web.method.HandlerMethod; 6 | import org.springframework.web.servlet.mvc.method.RequestMappingInfo; 7 | 8 | import java.lang.reflect.Method; 9 | 10 | public class ParameterTranslation extends SpringMVCTranslation { 11 | private final RequestMappingInfo mapping; 12 | private final HandlerMethod handler; 13 | private final Method method; 14 | private final Controller controller; 15 | private final Operation operation; 16 | 17 | public ParameterTranslation(SpringMVCTranslation parent, RequestMappingInfo mapping, HandlerMethod handler, Method method, Controller controller, Operation operation) { 18 | super(parent); 19 | this.mapping = mapping; 20 | this.handler = handler; 21 | this.method = method; 22 | this.controller = controller; 23 | this.operation = operation; 24 | } 25 | 26 | public RequestMappingInfo getMapping() { 27 | return mapping; 28 | } 29 | 30 | public HandlerMethod getHandler() { 31 | return handler; 32 | } 33 | 34 | public Method getMethod() { 35 | return method; 36 | } 37 | 38 | public Controller getController() { 39 | return controller; 40 | } 41 | 42 | public Operation getOperation() { 43 | return operation; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /httpdoc-spring-mvc/src/main/java/io/httpdoc/spring/mvc/SpringMVCHttpdocContainer.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.spring.mvc; 2 | 3 | import io.httpdoc.core.translation.AbstractContainer; 4 | import io.httpdoc.core.translation.Container; 5 | 6 | import javax.servlet.ServletContext; 7 | import java.util.Enumeration; 8 | 9 | /** 10 | * Httpdoc Servlet Container 11 | * 12 | * @author 杨昌沛 646742615@qq.com 13 | * @date 2018-04-23 16:14 14 | **/ 15 | public class SpringMVCHttpdocContainer extends AbstractContainer implements Container { 16 | private final ServletContext servletContext; 17 | 18 | SpringMVCHttpdocContainer(ServletContext servletContext) { 19 | this.servletContext = servletContext; 20 | } 21 | 22 | @Override 23 | public Object get(String name) { 24 | return servletContext.getAttribute(name); 25 | } 26 | 27 | @Override 28 | public Enumeration names() { 29 | return servletContext.getAttributeNames(); 30 | } 31 | 32 | @Override 33 | public void remove(String name) { 34 | servletContext.removeAttribute(name); 35 | } 36 | 37 | @Override 38 | public void set(String name, Object value) { 39 | servletContext.setAttribute(name, value); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /httpdoc-spring-mvc/src/main/java/io/httpdoc/spring/mvc/SpringMVCTranslation.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.spring.mvc; 2 | 3 | import io.httpdoc.core.interpretation.Interpreter; 4 | import io.httpdoc.core.supplier.Supplier; 5 | import io.httpdoc.core.translation.Container; 6 | import io.httpdoc.core.translation.Translation; 7 | 8 | public abstract class SpringMVCTranslation { 9 | private final Translation translation; 10 | 11 | protected SpringMVCTranslation(Translation translation) { 12 | this.translation = translation; 13 | } 14 | 15 | protected SpringMVCTranslation(SpringMVCTranslation parent) { 16 | this.translation = parent.translation; 17 | } 18 | 19 | public String getHttpdoc() { 20 | return translation.getHttpdoc(); 21 | } 22 | 23 | public String getProtocol() { 24 | return translation.getProtocol(); 25 | } 26 | 27 | public String getHostname() { 28 | return translation.getHostname(); 29 | } 30 | 31 | public Integer getPort() { 32 | return translation.getPort(); 33 | } 34 | 35 | public String getContext() { 36 | return translation.getContext(); 37 | } 38 | 39 | public String getVersion() { 40 | return translation.getVersion(); 41 | } 42 | 43 | public Container getContainer() { 44 | return translation.getContainer(); 45 | } 46 | 47 | public Supplier getSupplier() { 48 | return translation.getSupplier(); 49 | } 50 | 51 | public Interpreter getInterpreter() { 52 | return translation.getInterpreter(); 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /httpdoc-spring-mvc/src/main/resources/httpdoc/translator.properties: -------------------------------------------------------------------------------- 1 | spring-mvc=io.httpdoc.spring.mvc.SpringMVCTranslator -------------------------------------------------------------------------------- /httpdoc-spring-mvc/src/main/resources/io/httpdoc/spring/mvc/Module.properties: -------------------------------------------------------------------------------- 1 | name=${project.artifactId} 2 | version=${project.version} 3 | parentName=${project.parent.artifactId} 4 | parentVersion=${project.parent.version} -------------------------------------------------------------------------------- /httpdoc-ui/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | httpdoc 7 | io.httpdoc 8 | v1.8.1 9 | 10 | 4.0.0 11 | 12 | httpdoc-ui 13 | httpdoc-ui 14 | 15 | 16 | 17 | 18 | src/main/resources 19 | false 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /httpdoc-ui/src/main/resources/META-INF/resources/httpdoc-ui-v1/fonts/glyphicons-halflings-regular.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/core-lib/httpdoc/9e83b307a3bae0b857f6bad61a11c19ce4245254/httpdoc-ui/src/main/resources/META-INF/resources/httpdoc-ui-v1/fonts/glyphicons-halflings-regular.eot -------------------------------------------------------------------------------- /httpdoc-ui/src/main/resources/META-INF/resources/httpdoc-ui-v1/fonts/glyphicons-halflings-regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/core-lib/httpdoc/9e83b307a3bae0b857f6bad61a11c19ce4245254/httpdoc-ui/src/main/resources/META-INF/resources/httpdoc-ui-v1/fonts/glyphicons-halflings-regular.ttf -------------------------------------------------------------------------------- /httpdoc-ui/src/main/resources/META-INF/resources/httpdoc-ui-v1/fonts/glyphicons-halflings-regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/core-lib/httpdoc/9e83b307a3bae0b857f6bad61a11c19ce4245254/httpdoc-ui/src/main/resources/META-INF/resources/httpdoc-ui-v1/fonts/glyphicons-halflings-regular.woff -------------------------------------------------------------------------------- /httpdoc-ui/src/main/resources/META-INF/resources/httpdoc-ui-v1/fonts/glyphicons-halflings-regular.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/core-lib/httpdoc/9e83b307a3bae0b857f6bad61a11c19ce4245254/httpdoc-ui/src/main/resources/META-INF/resources/httpdoc-ui-v1/fonts/glyphicons-halflings-regular.woff2 -------------------------------------------------------------------------------- /httpdoc-ui/src/main/resources/META-INF/resources/httpdoc-ui/fonts/glyphicons-halflings-regular.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/core-lib/httpdoc/9e83b307a3bae0b857f6bad61a11c19ce4245254/httpdoc-ui/src/main/resources/META-INF/resources/httpdoc-ui/fonts/glyphicons-halflings-regular.eot -------------------------------------------------------------------------------- /httpdoc-ui/src/main/resources/META-INF/resources/httpdoc-ui/fonts/glyphicons-halflings-regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/core-lib/httpdoc/9e83b307a3bae0b857f6bad61a11c19ce4245254/httpdoc-ui/src/main/resources/META-INF/resources/httpdoc-ui/fonts/glyphicons-halflings-regular.ttf -------------------------------------------------------------------------------- /httpdoc-ui/src/main/resources/META-INF/resources/httpdoc-ui/fonts/glyphicons-halflings-regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/core-lib/httpdoc/9e83b307a3bae0b857f6bad61a11c19ce4245254/httpdoc-ui/src/main/resources/META-INF/resources/httpdoc-ui/fonts/glyphicons-halflings-regular.woff -------------------------------------------------------------------------------- /httpdoc-ui/src/main/resources/META-INF/resources/httpdoc-ui/fonts/glyphicons-halflings-regular.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/core-lib/httpdoc/9e83b307a3bae0b857f6bad61a11c19ce4245254/httpdoc-ui/src/main/resources/META-INF/resources/httpdoc-ui/fonts/glyphicons-halflings-regular.woff2 -------------------------------------------------------------------------------- /httpdoc-web/src/main/java/io/httpdoc/web/Handler.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.web; 2 | 3 | import io.httpdoc.core.Document; 4 | 5 | import javax.servlet.http.HttpServletRequest; 6 | import javax.servlet.http.HttpServletResponse; 7 | 8 | public interface Handler { 9 | 10 | void handle(Document document, HttpServletRequest request, HttpServletResponse response) throws Exception; 11 | 12 | } 13 | -------------------------------------------------------------------------------- /httpdoc-web/src/main/java/io/httpdoc/web/HttpdocConversionProvider.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.web; 2 | 3 | import io.httpdoc.web.conversion.*; 4 | 5 | import java.util.Arrays; 6 | 7 | /** 8 | * Httpdoc配置类转换提供器 9 | * 10 | * @author 杨昌沛 646742615@qq.com 11 | * @date 2018-06-27 10:27 12 | **/ 13 | public class HttpdocConversionProvider extends StandardConversionProvider { 14 | 15 | public HttpdocConversionProvider() { 16 | super(Arrays.asList( 17 | new PrimaryConverter(), 18 | new WrapperConverter(), 19 | new NumberConverter(), 20 | new StringConverter(), 21 | new DateConverter(), 22 | new EnumConverter(), 23 | new ArrayConverter(), 24 | new ListConverter(), 25 | new SetConverter(), 26 | new MapConverter() 27 | )); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /httpdoc-web/src/main/java/io/httpdoc/web/HttpdocFilterConfig.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.web; 2 | 3 | import javax.servlet.FilterConfig; 4 | import javax.servlet.ServletContext; 5 | import java.util.Enumeration; 6 | 7 | /** 8 | * Httpdoc Filter 配置 9 | * 10 | * @author 杨昌沛 646742615@qq.com 11 | * @date 2018-04-24 11:26 12 | **/ 13 | public class HttpdocFilterConfig implements HttpdocWebConfig { 14 | private final FilterConfig config; 15 | 16 | HttpdocFilterConfig(FilterConfig config) { 17 | this.config = config; 18 | } 19 | 20 | @Override 21 | public String getName() { 22 | return config.getFilterName(); 23 | } 24 | 25 | @Override 26 | public ServletContext getServletContext() { 27 | return config.getServletContext(); 28 | } 29 | 30 | @Override 31 | public String getInitParameter(String name) { 32 | return config.getInitParameter(name); 33 | } 34 | 35 | @Override 36 | public Enumeration getInitParameterNames() { 37 | return config.getInitParameterNames(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /httpdoc-web/src/main/java/io/httpdoc/web/HttpdocFilterSupport.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.web; 2 | 3 | import javax.servlet.*; 4 | import java.io.IOException; 5 | 6 | /** 7 | * Httpdoc Filter 支持 8 | * 9 | * @author 杨昌沛 646742615@qq.com 10 | * @date 2018-04-20 12:13 11 | **/ 12 | public class HttpdocFilterSupport extends HttpdocWebSupport implements Filter { 13 | 14 | @Override 15 | public void init(FilterConfig config) throws ServletException { 16 | super.init(new HttpdocFilterConfig(config)); 17 | } 18 | 19 | @Override 20 | public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { 21 | super.handle(request, response); 22 | } 23 | 24 | @Override 25 | public void destroy() { 26 | super.destroy(); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /httpdoc-web/src/main/java/io/httpdoc/web/HttpdocServletConfig.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.web; 2 | 3 | import javax.servlet.ServletConfig; 4 | import javax.servlet.ServletContext; 5 | import java.util.Enumeration; 6 | 7 | /** 8 | * Httpdoc Servlet 配置 9 | * 10 | * @author 杨昌沛 646742615@qq.com 11 | * @date 2018-04-24 11:27 12 | **/ 13 | public class HttpdocServletConfig implements HttpdocWebConfig { 14 | private final ServletConfig config; 15 | 16 | HttpdocServletConfig(ServletConfig config) { 17 | this.config = config; 18 | } 19 | 20 | @Override 21 | public String getName() { 22 | return config.getServletName(); 23 | } 24 | 25 | @Override 26 | public ServletContext getServletContext() { 27 | return config.getServletContext(); 28 | } 29 | 30 | @Override 31 | public String getInitParameter(String name) { 32 | return config.getInitParameter(name); 33 | } 34 | 35 | @Override 36 | public Enumeration getInitParameterNames() { 37 | return config.getInitParameterNames(); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /httpdoc-web/src/main/java/io/httpdoc/web/HttpdocServletSupport.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.web; 2 | 3 | import javax.servlet.*; 4 | import java.io.IOException; 5 | 6 | /** 7 | * Httpdoc Servlet 支持 8 | * 9 | * @author 杨昌沛 646742615@qq.com 10 | * @date 2018-04-24 11:21 11 | **/ 12 | public class HttpdocServletSupport extends HttpdocWebSupport implements Servlet { 13 | private ServletConfig config; 14 | 15 | @Override 16 | public void init(ServletConfig config) throws ServletException { 17 | super.init(new HttpdocServletConfig(this.config = config)); 18 | } 19 | 20 | @Override 21 | public ServletConfig getServletConfig() { 22 | return config; 23 | } 24 | 25 | @Override 26 | public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException { 27 | super.handle(req, res); 28 | } 29 | 30 | @Override 31 | public String getServletInfo() { 32 | return config.getServletName(); 33 | } 34 | 35 | @Override 36 | public void destroy() { 37 | super.destroy(); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /httpdoc-web/src/main/java/io/httpdoc/web/HttpdocThreadLocal.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.web; 2 | 3 | import javax.servlet.http.HttpServletRequest; 4 | import javax.servlet.http.HttpServletResponse; 5 | 6 | /** 7 | * Httpdoc 线程本地变量 8 | * 9 | * @author 杨昌沛 646742615@qq.com 10 | * @date 2018-04-24 14:37 11 | **/ 12 | public class HttpdocThreadLocal { 13 | private static final ThreadLocal REQUEST = new ThreadLocal<>(); 14 | private static final ThreadLocal RESPONSE = new ThreadLocal<>(); 15 | 16 | public static HttpServletRequest getRequest() { 17 | return REQUEST.get(); 18 | } 19 | 20 | public static HttpServletResponse getResponse() { 21 | return RESPONSE.get(); 22 | } 23 | 24 | static void bind(HttpServletRequest request, HttpServletResponse response) { 25 | REQUEST.set(request); 26 | RESPONSE.set(response); 27 | } 28 | 29 | static void clear() { 30 | REQUEST.remove(); 31 | RESPONSE.remove(); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /httpdoc-web/src/main/java/io/httpdoc/web/HttpdocWebConfig.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.web; 2 | 3 | import io.httpdoc.core.Config; 4 | 5 | import javax.servlet.ServletContext; 6 | 7 | /** 8 | * Httpdoc web 配置 9 | * 10 | * @author 杨昌沛 646742615@qq.com 11 | * @date 2018-04-24 11:23 12 | **/ 13 | public interface HttpdocWebConfig extends Config { 14 | 15 | String getName(); 16 | 17 | ServletContext getServletContext(); 18 | 19 | } 20 | -------------------------------------------------------------------------------- /httpdoc-web/src/main/java/io/httpdoc/web/HttpdocWebContainer.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.web; 2 | 3 | import io.httpdoc.core.translation.AbstractContainer; 4 | import io.httpdoc.core.translation.Container; 5 | 6 | import javax.servlet.ServletContext; 7 | import java.util.Enumeration; 8 | 9 | /** 10 | * Httpdoc Servlet Container 11 | * 12 | * @author 杨昌沛 646742615@qq.com 13 | * @date 2018-04-23 16:14 14 | **/ 15 | public class HttpdocWebContainer extends AbstractContainer implements Container { 16 | private final ServletContext servletContext; 17 | 18 | HttpdocWebContainer(ServletContext servletContext) { 19 | this.servletContext = servletContext; 20 | } 21 | 22 | @Override 23 | public Object get(String name) { 24 | return servletContext.getAttribute(name); 25 | } 26 | 27 | @Override 28 | public Enumeration names() { 29 | return servletContext.getAttributeNames(); 30 | } 31 | 32 | @Override 33 | public void remove(String name) { 34 | servletContext.removeAttribute(name); 35 | } 36 | 37 | @Override 38 | public void set(String name, Object value) { 39 | servletContext.setAttribute(name, value); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /httpdoc-web/src/main/java/io/httpdoc/web/Module.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.web; 2 | 3 | import io.httpdoc.core.Build; 4 | 5 | import java.io.Serializable; 6 | 7 | /** 8 | * Created by payne on 2017/3/28. 9 | */ 10 | public class Module extends Build implements Serializable { 11 | private static final long serialVersionUID = 8979830823718754930L; 12 | 13 | private static volatile Module instance; 14 | 15 | private String name; 16 | private String version; 17 | private String parentName; 18 | private String parentVersion; 19 | 20 | private Module() { 21 | } 22 | 23 | public static Module getInstance() { 24 | if (instance != null) return instance; 25 | synchronized (Module.class) { 26 | if (instance != null) return instance; 27 | return instance = new Module(); 28 | } 29 | } 30 | 31 | public String getName() { 32 | return name; 33 | } 34 | 35 | public String getVersion() { 36 | return version; 37 | } 38 | 39 | public String getParentName() { 40 | return parentName; 41 | } 42 | 43 | public String getParentVersion() { 44 | return parentVersion; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /httpdoc-web/src/main/java/io/httpdoc/web/conversion/ConversionProvider.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.web.conversion; 2 | 3 | import java.text.DateFormat; 4 | import java.util.Map; 5 | 6 | /** 7 | * 转换提供器 8 | * 9 | * @author 杨昌沛 646742615@qq.com 10 | * @date 2018-06-04 10:10 11 | **/ 12 | public interface ConversionProvider { 13 | 14 | DateFormat getSerializationDateFormat(); 15 | 16 | void setSerializationDateFormat(DateFormat dateFormat); 17 | 18 | DateFormat getDeserializationDateFormat(); 19 | 20 | void setDeserializationDateFormat(DateFormat dateFormat); 21 | 22 | /** 23 | * 是否支持该类型的转换 24 | * 25 | * @param type 类型 26 | * @return 支持:true 否则:false 27 | */ 28 | boolean supports(Class type); 29 | 30 | /** 31 | * 黑盒转换 32 | * 33 | * @param name 参数名称 34 | * @param value 参数值 35 | * @return 转换后的结果 36 | * @throws ConvertingException 转换异常 37 | */ 38 | Map convert(String name, Object value) throws ConvertingException; 39 | 40 | /** 41 | * 是否支持该转换动作 42 | * 43 | * @param conversion 转换动作 44 | * @return 支持:true 否则:false 45 | */ 46 | boolean supports(Conversion conversion); 47 | 48 | /** 49 | * 黑盒转换, 屏蔽所有细节,提供所有类型的转换 50 | * 51 | * @param conversion 转换动作 52 | * @return 转换后的结果 53 | * @throws ConvertingException 转换异常 54 | */ 55 | Object convert(Conversion conversion) throws ConvertingException; 56 | 57 | } 58 | -------------------------------------------------------------------------------- /httpdoc-web/src/main/java/io/httpdoc/web/conversion/Converter.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.web.conversion; 2 | 3 | import java.util.Map; 4 | 5 | /** 6 | * 转换器 7 | * 8 | * @author 杨昌沛 646742615@qq.com 9 | * @date 2018-06-04 10:21 10 | **/ 11 | public interface Converter { 12 | 13 | /** 14 | * 为了递归的缺省键 15 | */ 16 | String KEY = "KEY"; 17 | 18 | boolean supports(Class type); 19 | 20 | Map convert(String name, T value, ConversionProvider provider) throws Exception; 21 | 22 | /** 23 | * 是否支持该转换动作 24 | * 25 | * @param conversion 转换动作 26 | * @return 支持:true 否则:false 27 | */ 28 | boolean supports(Conversion conversion); 29 | 30 | /** 31 | * 转换 32 | * 33 | * @param conversion 转换动作 34 | * @param provider 转换提供器 35 | * @return 转换后的结果 36 | * @throws ConvertingException 转换异常 37 | */ 38 | T convert(Conversion conversion, ConversionProvider provider) throws Exception; 39 | 40 | } 41 | -------------------------------------------------------------------------------- /httpdoc-web/src/main/java/io/httpdoc/web/conversion/ConvertingException.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.web.conversion; 2 | 3 | /** 4 | * 转换异常 5 | * 6 | * @author 杨昌沛 646742615@qq.com 7 | * @date 2018-06-04 10:16 8 | **/ 9 | public class ConvertingException extends Exception { 10 | private static final long serialVersionUID = -1469979177747097062L; 11 | 12 | private final Conversion conversion; 13 | 14 | public ConvertingException() { 15 | this.conversion = null; 16 | } 17 | 18 | public ConvertingException(String message) { 19 | super(message); 20 | this.conversion = null; 21 | } 22 | 23 | public ConvertingException(String message, Throwable cause) { 24 | super(message, cause); 25 | this.conversion = null; 26 | } 27 | 28 | public ConvertingException(Throwable cause) { 29 | super(cause); 30 | this.conversion = null; 31 | } 32 | 33 | public ConvertingException(Conversion conversion) { 34 | this.conversion = conversion; 35 | } 36 | 37 | public ConvertingException(String message, Conversion conversion) { 38 | super(message); 39 | this.conversion = conversion; 40 | } 41 | 42 | public ConvertingException(String message, Throwable cause, Conversion conversion) { 43 | super(message, cause); 44 | this.conversion = conversion; 45 | } 46 | 47 | public ConvertingException(Throwable cause, Conversion conversion) { 48 | super(cause); 49 | this.conversion = conversion; 50 | } 51 | 52 | 53 | public Conversion getConversion() { 54 | return conversion; 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /httpdoc-web/src/main/java/io/httpdoc/web/conversion/DateConverter.java: -------------------------------------------------------------------------------- 1 | package io.httpdoc.web.conversion; 2 | 3 | import java.net.URLDecoder; 4 | import java.util.Collections; 5 | import java.util.Date; 6 | import java.util.Map; 7 | 8 | /** 9 | * 日期转换器 10 | * 11 | * @author 杨昌沛 646742615@qq.com 12 | * @date 2018-06-04 10:58 13 | **/ 14 | public class DateConverter implements Converter { 15 | 16 | @Override 17 | public boolean supports(Class type) { 18 | return Date.class.isAssignableFrom(type); 19 | } 20 | 21 | @Override 22 | public Map convert(String name, Date value, ConversionProvider provider) throws Exception { 23 | return Collections.singletonMap(name, new String[]{provider.getSerializationDateFormat().format(value)}); 24 | } 25 | 26 | @Override 27 | public boolean supports(Conversion conversion) { 28 | return conversion.type == Date.class; 29 | } 30 | 31 | @Override 32 | public Date convert(Conversion conversion, ConversionProvider provider) throws Exception { 33 | if (!supports(conversion) || !conversion.name.equals(conversion.expression)) return (Date) conversion.value; 34 | String[] values = conversion.values; 35 | boolean decoded = conversion.decoded; 36 | String charset = conversion.charset; 37 | String value = values != null && values.length > 0 ? values[0] : null; 38 | if (value == null) return (Date) conversion.value; 39 | if (!decoded) value = URLDecoder.decode(value, charset); 40 | return provider.getDeserializationDateFormat().parse(value); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /httpdoc-web/src/main/resources/httpdoc/handler.properties: -------------------------------------------------------------------------------- 1 | export=io.httpdoc.web.HttpdocExportHandler -------------------------------------------------------------------------------- /httpdoc-web/src/main/resources/io/httpdoc/web/Module.properties: -------------------------------------------------------------------------------- 1 | name=${project.artifactId} 2 | version=${project.version} 3 | parentName=${project.parent.artifactId} 4 | parentVersion=${project.parent.version} --------------------------------------------------------------------------------