├── .gitignore ├── .travis.yml ├── CHANGELOG.md ├── LICENSE ├── README.md ├── annotations ├── forbidden-apis.signatures ├── pom.xml └── src │ ├── main │ ├── java │ │ └── org │ │ │ └── leandreck │ │ │ └── endpoints │ │ │ ├── annotations │ │ │ ├── TypeScriptEndpoint.java │ │ │ ├── TypeScriptIgnore.java │ │ │ ├── TypeScriptTemplatesConfiguration.java │ │ │ └── TypeScriptType.java │ │ │ └── processor │ │ │ ├── TypeScriptEndpointProcessor.java │ │ │ ├── config │ │ │ ├── MultipleConfigurationsFoundException.java │ │ │ └── TemplateConfiguration.java │ │ │ ├── model │ │ │ ├── EndpointNode.java │ │ │ ├── EndpointNodeFactory.java │ │ │ ├── EnumValue.java │ │ │ ├── InitTypeNodeFactoriesException.java │ │ │ ├── MethodNode.java │ │ │ ├── MethodNodeFactory.java │ │ │ ├── PrintConfiguration.java │ │ │ ├── RequestMapping.java │ │ │ ├── RequestMappingFactory.java │ │ │ ├── StringUtil.java │ │ │ ├── TypeNode.java │ │ │ ├── TypeNodeFactory.java │ │ │ ├── UnkownTypeProcessingException.java │ │ │ ├── VariableAnnotations.java │ │ │ └── typefactories │ │ │ │ ├── ArrayTypeNodeFactory.java │ │ │ │ ├── CollectionTypeNodeFactory.java │ │ │ │ ├── ConcreteTypeNodeFactory.java │ │ │ │ ├── EnumTypeNodeFactory.java │ │ │ │ ├── MapTypeNodeFactory.java │ │ │ │ ├── MappedTypeNodeFactory.java │ │ │ │ ├── MissingConfigurationTemplateException.java │ │ │ │ ├── NullTypeNodeFactory.java │ │ │ │ ├── OptionalTypeNodeFactory.java │ │ │ │ ├── SimpleTypeNodeFactory.java │ │ │ │ ├── TypeNodeKind.java │ │ │ │ ├── TypeNodeUtils.java │ │ │ │ └── TypeVarTypeNodeFactory.java │ │ │ └── printer │ │ │ ├── Engine.java │ │ │ └── TypesPackage.java │ └── resources │ │ ├── META-INF │ │ └── services │ │ │ └── javax.annotation.processing.Processor │ │ └── org │ │ └── leandreck │ │ └── endpoints │ │ └── templates │ │ └── typescript │ │ ├── apimodule.ftl │ │ ├── enum.ftl │ │ ├── index.ftl │ │ ├── interface.ftl │ │ ├── service.ftl │ │ └── serviceconfig.ftl │ └── test │ ├── groovy │ └── org │ │ └── leandreck │ │ └── endpoints │ │ └── processor │ │ ├── TypeScriptEndpointProcessorErrorSpec.groovy │ │ ├── TypeScriptEndpointProcessorSpec.groovy │ │ ├── TypeScriptEndpointProcessorUnitSpec.groovy │ │ ├── config │ │ └── TemplateConfigurationUnitSpec.groovy │ │ └── model │ │ ├── RequestMappingFactorySpec.groovy │ │ ├── RequestMappingSpec.groovy │ │ └── typefactories │ │ └── TypeNodeUtilsUnitSpec.groovy │ ├── java │ └── org │ │ └── leandreck │ │ └── endpoints │ │ └── processor │ │ ├── CompilerTestHelper.java │ │ └── CompleteRootType.java │ ├── resources │ └── org │ │ └── leandreck │ │ └── endpoints │ │ └── templates │ │ ├── errtemplate │ │ └── service.ftl │ │ └── testing │ │ ├── enum.ftl │ │ ├── interface.ftl │ │ └── service.ftl │ └── testcases │ └── org │ └── leandreck │ └── endpoints │ ├── case1 │ └── Endpoint.gstring │ ├── complex │ ├── Endpoint.java │ └── SimpleRootType.gstring │ ├── composed │ └── Endpoint.gstring │ ├── enums │ ├── DeclaredEnum.gstring │ ├── Endpoint.java │ └── SimpleRootType.java │ ├── epname │ └── Endpoint.java │ ├── errtemplate │ └── Endpoint.java │ ├── generics │ ├── Endpoint.gstring │ └── SimpleRootType.java │ ├── httpmethods │ └── Endpoint.gstring │ ├── ignored │ ├── Annotated.java │ ├── NoJson.java │ ├── NoJsonMultiple.java │ ├── NoMapping.java │ ├── PackageMethod.java │ ├── PrivateMethod.java │ └── ProtectedMethod.java │ ├── interfaces │ └── Endpoint.gstring │ ├── lombok │ ├── DataType.gstring │ ├── Endpoint.java │ └── ValueType.gstring │ ├── notemplate │ └── Endpoint.java │ ├── pathvariable │ └── Endpoint.gstring │ ├── returnref │ ├── Endpoint.gstring │ └── SimpleRootType.java │ └── returnvoid │ ├── Endpoint.gstring │ └── SimpleRootType.java ├── examples ├── pom.xml └── src │ └── main │ └── java │ └── org │ └── leandreck │ └── endpoints │ └── examples │ ├── MapKeyType.java │ ├── MapValueType.java │ ├── RootType.java │ ├── SecondTypeScriptEndpoint.java │ ├── SimpleEnum.java │ ├── SubType.java │ ├── TestTypeScriptEndpoint.java │ ├── abstractbase │ ├── BaseEndpoint.java │ ├── Clearable.java │ ├── Moveable.java │ ├── Person.java │ └── PersonEndpoint.java │ └── lombok │ ├── LombokRequest.java │ ├── LombokResponse.java │ └── LombokTypeScriptEndpoint.java └── pom.xml /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | pom.xml.tag 3 | pom.xml.releaseBackup 4 | pom.xml.versionsBackup 5 | pom.xml.next 6 | release.properties 7 | dependency-reduced-pom.xml 8 | buildNumber.properties 9 | .mvn/timing.properties 10 | /setPath.bat 11 | /.idea/ 12 | versioneye.properties 13 | /annotations/src/test/testcases/org/leandreck/endpoints/case1/Endpoint.java 14 | *.iml -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | os: 3 | - linux 4 | jdk: 5 | - oraclejdk8 6 | 7 | #matrix: 8 | # include: 9 | # - os: linux 10 | # jdk: oraclejdk8 11 | # - os: osx 12 | # osx_image: xcode8 13 | 14 | env: 15 | global: 16 | # The next declaration is the encrypted COVERITY_SCAN_TOKEN, created 17 | # via the "travis encrypt" command using the project repo's public key 18 | - secure: "O0+XK4b7KaLr04YZNlhxch+HdFN4/sjQVDbk+IPxMO55GeJPmkHuTqUvUkmHZmpMzLW/ruqn7IWTM10Kna/Hf9V50yvzAOZyWmp0ih2PraMUDa97V/mXJeQQMXxrsnb89oOOrNDB15UjQA7dQbTVFZ1Dh8D7dyBo5OmPWyAiQZ/OEJsolZTFPiCbOTq920BfejMUzGAhtWXqgeHpBNGCvIho4a8cHIYOSI16OnFgi2TVJUN0JJaZIhjL8KaMCojchIDGc7u24MlD/2xwVbxsyqaLrDJ83WOBD4UW5SShhdb8/QVXB5fYwsIHLjSxGJMtjD5o1oGJrtZ4SsNd60pjtiDf7n2xFjYLezVdz1R+3HB4JshGuLLWw4aN8PqKBiqoolYKXXVejhy6jEL9D4tuynzygdYPB57RkXpKnEv1a7L2L18GSN2t0OEKrhU875sJtxQEcetHQwN5b9ObovBWlItnesxWRJEH5CoKgpZ1RkJsRn6dSUzCej+QC7oj9Mwv/TtBWv2c4ayV6ijsfGKYaNHqPRd4ZC93k8+7Pe06RfS9i0k/cXjRneiPn/fRbX0py/6QABdXmaQIBoCJWYsi6sUug/ynG+94D/UgsT/ncLgySYc+9xwfAiGg+Du9CRUOvLdSbZ6IdwatdjZytL8U4uKz5ga2ew79H0vvUD5tHMo=" 19 | # The next declaration is the encrypted SONAR_TOKEN 20 | - secure: "qGawwy6qMugR0PJHbSQu+L5jEv7IsukJncvFevsC4SfvMdj0RNb/nj4NPZbtlxu3AJ3McxrAqEWWiekeXElVEBz4m9zm7NXuGQouV9ilHRRw8Y1BWSXlJVv5aIw55zCS1K40wjewSJmTw+qdmcocxVd99hA9kDMX0ZcBdT4T54F9ngqRJKyirtYWYv9RLQJvaKfOIX0vtzXRnqJateB4DSBF9SQGiEkF1megcsK829kAhrzuLKWamy5DfmxIRoTmBXCTxrL3T1yJWee6nf+dagtrCn3kqQQHtA0swRh9dUm/3lCMwDlXT+ewro79LgERXveVIVdMJtDRh8VsUvRMIJEBsXdQF6Yeahkoo/2pTgU5NJbo+BNQZ2mKb13987ChEQgIANOf15t4tE0IpLkUUqsdZPw3IwAnNybEmCazQWy4I422MO2zzxM5HqSCth2e6uc4KyDdsKWoowOxqVbvjPrxm1pX8RdBun7UyGSd9VF5PGh38i+TqsMo6GUEk5BcJeYiEhArnRN5Cqzyep2UHanIxPh1Y04yKQpC67+FMfRjhOeGkgn2h1V9PnCMjpxYzWeUFJyDABQebuwTBIX3CteivDzCos9R9VxG+kZQKfkgh+eiZtUjeKMjueLjbaO8ol9cyFNtB70YXVNYW66zQJFnPDqBqByNvd0EyF1+Amk=" 21 | 22 | before_install: 23 | - echo -n | openssl s_client -connect scan.coverity.com:443 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' | sudo tee -a /etc/ssl/certs/ca- 24 | 25 | addons: 26 | coverity_scan: 27 | project: 28 | name: "mkowalzik/spring-typescript-services" 29 | description: "Build submitted via Travis CI" 30 | notification_email: mathias.kowalzik@leandreck.org 31 | build_command_prepend: "mvn clean" 32 | build_command: "mvn -DskipTests=true compile" 33 | branch_pattern: coverity_scan 34 | sonarcloud: 35 | organization: "leandreck-org" # the key of the org you chose at step #3 36 | token: 37 | secure: $SONAR_TOKEN # encrypted value of your token 38 | 39 | script: 40 | # the following command line builds the project, runs the tests with coverage and then execute the SonarQube analysis 41 | - mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent install sonar:sonar 42 | 43 | after_success: 44 | - bash <(curl -s https://codecov.io/bash) 45 | 46 | notifications: 47 | slack: 48 | secure: qXSHcS4FY+mTuQGNoPwD0U5UIrnLRd+QJesPwpyIrmrtFbOk3BHDr2QqM3CECc69nG/EOtX5EgmC4ppgFQRAoy9uWFT8xk8ieaQI39ioGMQvMwyGDcblO0zrybxARCHyosMRup9D/ECOJIc3lnBMNlcnFLLnXsDjQA0u2aMVwKEZS9jTDKEEq99nCGBTJkpBxVNJS4BopJPQ92tawRHU4t4kJSd99u7GWvJlV/vu8rqYfF5hU1SHesYEC7ITe5e4Fo0g/yxWIbXhHIJzzbraDkq3BI+aHgGeDLM0Z9poeTg0jG8M6FLdLSG7AlwJOeTNX0T4qm7+Rmd74l73eLOp4M9ES5qedyw8hjfuTKjJGivhPFIkYxMaHkFr3I+ciMfUgfCy57ljzQ9gYHS8syL9jMIfCCQGxJdgyWLXsiXRQkqwBw2zgLr1YoHAU7bhgyIvN1FKj5i7HEOS+vmnkDEfM6DBTaoVsJC6vT9OJbbiLWaxvXlB+jUa2IRhsSKVkfIWxLCQmGhMF+1yu9K5bLo1ugnCg1c9IqN+GxWuNCZ+98lyGpFy14Upr+i1RyD36BUVnsQpB9oegTQuxxDIcjAqGkBJw9OX/rQn48AV2UtpSJM1BucRM8//x2CkQr9brPWGjN8hBcJpm/FxPoTWGuZakY9Nlt5ZdkdKAz/IqAlqOWY= 49 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## 0.4.0 4 | * TypeScriptEndpoints can now be Interfaces and they recognize @RequestMapping annotated Methods in Supertypes and Interfaces 5 | * Method suffixes in generated TypeScript files can now be configured or turned off (see @TypeScriptTemplatesConfiguration) 6 | * Unset http-parameters won't be send to the server now 7 | 8 | Thanks to [jscharett](https://github.com/jscharett) for the provided help. -------------------------------------------------------------------------------- /annotations/forbidden-apis.signatures: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | # https://github.com/policeman-tools/forbidden-apis/wiki/SignaturesSyntax 18 | -------------------------------------------------------------------------------- /annotations/src/main/java/org/leandreck/endpoints/annotations/TypeScriptEndpoint.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.leandreck.endpoints.annotations; 17 | 18 | import java.lang.annotation.*; 19 | 20 | /** 21 | * Annotate {@link org.springframework.web.bind.annotation.RestController} classes to generate 22 | * TypeScript endpoint and interface files. 23 | */ 24 | @Documented 25 | @Retention(RetentionPolicy.SOURCE) 26 | @Target({ElementType.METHOD, ElementType.TYPE}) 27 | public @interface TypeScriptEndpoint { 28 | 29 | /** 30 | * The name of the endpoint. Defaults to the name of the class annotated with TypeScriptEndpoint. 31 | * 32 | * @return name. 33 | */ 34 | String value() default ""; 35 | 36 | /** 37 | * Template to use for generating TypeScript-files for this specific TypeScriptEndpoint, this overwrites any defaults.
38 | * You can newConfiguredInstance a default Template for all TypeScriptEndpoints in {@link TypeScriptTemplatesConfiguration}.
39 | * If none is specified the default-template will be used.
40 | * Default template is located at "/org/leandreck/endpoints/templates/typescript/service.ftl",
41 | * 42 | * @return classpath location of the template 43 | * @see TypeScriptTemplatesConfiguration 44 | */ 45 | String template() default ""; 46 | } -------------------------------------------------------------------------------- /annotations/src/main/java/org/leandreck/endpoints/annotations/TypeScriptIgnore.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.leandreck.endpoints.annotations; 17 | 18 | import java.lang.annotation.*; 19 | 20 | /** 21 | * Methods or Fields annotated with {@link TypeScriptIgnore} will be ignored by the annotation processor.
22 | * Annotate Methods in your {@link org.springframework.web.bind.annotation.RestController} if you do not 23 | * want to include them in the endpoint file.
24 | * If applied to a Field it is not included in the respective interface file. 25 | */ 26 | @Documented 27 | @Retention(RetentionPolicy.SOURCE) 28 | @Target({ElementType.METHOD, ElementType.FIELD}) 29 | public @interface TypeScriptIgnore { 30 | 31 | } 32 | -------------------------------------------------------------------------------- /annotations/src/main/java/org/leandreck/endpoints/annotations/TypeScriptTemplatesConfiguration.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.leandreck.endpoints.annotations; 17 | 18 | import java.lang.annotation.Documented; 19 | import java.lang.annotation.ElementType; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.RetentionPolicy; 22 | import java.lang.annotation.Target; 23 | 24 | /** 25 | * Allow changing the templates that will be used for code generation, by specifying their 26 | * location in the classpath and how they should be processed. 27 | * 28 | * @see org.leandreck.endpoints.processor.model.PrintConfiguration 29 | */ 30 | @Documented 31 | @Retention(RetentionPolicy.SOURCE) 32 | @Target({ElementType.TYPE}) 33 | public @interface TypeScriptTemplatesConfiguration { 34 | String DEFAULT_API_MODULE = "/org/leandreck/endpoints/templates/typescript/apimodule.ftl"; 35 | String DEFAULT_ENUMERATION = "/org/leandreck/endpoints/templates/typescript/enum.ftl"; 36 | String DEFAULT_INDEX = "/org/leandreck/endpoints/templates/typescript/index.ftl"; 37 | String DEFAULT_INTERFACE = "/org/leandreck/endpoints/templates/typescript/interface.ftl"; 38 | String DEFAULT_ENDPOINT = "/org/leandreck/endpoints/templates/typescript/service.ftl"; 39 | 40 | boolean DEFAULT_USE_SUFFIXES = true; 41 | String DEFAULT_SUFFIX_GET = "Get"; 42 | String DEFAULT_SUFFIX_HEAD = "Head"; 43 | String DEFAULT_SUFFIX_DELETE = "Delete"; 44 | String DEFAULT_SUFFIX_OPTIONS = "Options"; 45 | String DEFAULT_SUFFIX_PATCH = "Patch"; 46 | String DEFAULT_SUFFIX_POST = "Post"; 47 | String DEFAULT_SUFFIX_PUT = "Put"; 48 | String DEFAULT_SUFFIX_TRACE = "Trace"; 49 | 50 | /** 51 | * Template used to generate the Angular API module. 52 | * @return By default returns "/org/leandreck/endpoints/templates/typescript/apimodule.ftl" 53 | */ 54 | String apimodule() default DEFAULT_API_MODULE; 55 | 56 | /** 57 | * Template that will be used to generate an enum. 58 | * @return By default returns "/org/leandreck/endpoints/templates/typescript/enum.ftl" 59 | */ 60 | String enumeration() default DEFAULT_ENUMERATION; 61 | 62 | /** 63 | * Entrypoint for all the the TypeScript generated classes. 64 | * @return By default returns "/org/leandreck/endpoints/templates/typescript/index.ftl" 65 | */ 66 | String index() default DEFAULT_INDEX; 67 | 68 | /** 69 | * Template used when generating a TypeScript interface. 70 | * @return By default returns "/org/leandreck/endpoints/templates/typescript/interface.ftl" 71 | */ 72 | String interfaces() default DEFAULT_INTERFACE; 73 | 74 | /** 75 | * Template used when generating the actual endpoint. 76 | * @return By default returns "/org/leandreck/endpoints/templates/typescript/service.ftl" 77 | */ 78 | String endpoint() default DEFAULT_ENDPOINT; 79 | 80 | /** 81 | * Whether generated Methods should have suffixes or not. 82 | * @return By default returns true 83 | */ 84 | boolean useSuffixes() default DEFAULT_USE_SUFFIXES; 85 | 86 | /** 87 | * Suffix for HTTP-GET Methods. 88 | * @return By default returns "Get". 89 | */ 90 | String suffixGet() default DEFAULT_SUFFIX_GET; 91 | 92 | /** 93 | * Suffix for HTTP-HEAD Methods. 94 | * @return By default returns "Head". 95 | */ 96 | String suffixHead() default DEFAULT_SUFFIX_HEAD; 97 | 98 | /** 99 | * Suffix for HTTP-DELETE Methods. 100 | * @return By default returns "Delete". 101 | */ 102 | String suffixDelete() default DEFAULT_SUFFIX_DELETE; 103 | 104 | /** 105 | * Suffix for HTTP-OPTIONS Methods. 106 | * @return By default returns "Options". 107 | */ 108 | String suffixOptions() default DEFAULT_SUFFIX_OPTIONS; 109 | 110 | /** 111 | * Suffix for HTTP-PATCH Methods. 112 | * @return By default returns "Patch". 113 | */ 114 | String suffixPatch() default DEFAULT_SUFFIX_PATCH; 115 | 116 | /** 117 | * Suffix for HTTP-POST Methods. 118 | * @return By default returns "Post". 119 | */ 120 | String suffixPost() default DEFAULT_SUFFIX_POST; 121 | 122 | /** 123 | * Suffix for HTTP-PUT Methods. 124 | * @return By default returns "Put". 125 | */ 126 | String suffixPut() default DEFAULT_SUFFIX_PUT; 127 | 128 | /** 129 | * Suffix for HTTP-TRACE Methods. 130 | * @return By default returns "Trace". 131 | */ 132 | String suffixTrace() default DEFAULT_SUFFIX_TRACE; 133 | 134 | } 135 | -------------------------------------------------------------------------------- /annotations/src/main/java/org/leandreck/endpoints/annotations/TypeScriptType.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.leandreck.endpoints.annotations; 17 | 18 | import java.lang.annotation.*; 19 | 20 | /** 21 | * Annotate Fields with {@link TypeScriptType} to specify a custom template or override default mappings.
22 | *
23 | * {@code @TypeScriptType("any")}
24 | * {@code private Foobar foo;}
25 | * will result in
26 | * {@code foo : any}
27 | *
28 | */ 29 | @Documented 30 | @Retention(RetentionPolicy.SOURCE) 31 | @Target({ElementType.TYPE}) 32 | public @interface TypeScriptType { 33 | 34 | /** 35 | * The name of the interface. Defaults to the name of the java type annotated with {@link TypeScriptType}. 36 | * 37 | * @return name. 38 | */ 39 | String value() default ""; 40 | 41 | /** 42 | * Template to use for generating TypeScript-files for this specific {@link TypeScriptType}, this overwrites any defaults.
43 | * You can newConfiguredInstance a default Template for all TypeScriptType in {@link TypeScriptTemplatesConfiguration}.
44 | * If none is specified the default-template will be used.
45 | * Default template is located at "/org/leandreck/endpoints/templates/typescript/interface.ftl".
46 | * 47 | * @return classpath location of the template 48 | * @see TypeScriptTemplatesConfiguration 49 | */ 50 | String template() default ""; 51 | } 52 | -------------------------------------------------------------------------------- /annotations/src/main/java/org/leandreck/endpoints/processor/config/MultipleConfigurationsFoundException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.leandreck.endpoints.processor.config; 17 | 18 | import javax.lang.model.element.Element; 19 | import java.util.HashSet; 20 | import java.util.Set; 21 | 22 | /** 23 | * Exception indicating that more than one configured {@link org.leandreck.endpoints.annotations.TypeScriptTemplatesConfiguration} exists inside the current compilation unit. 24 | */ 25 | public class MultipleConfigurationsFoundException extends Exception { 26 | 27 | private final transient Set elementsWithConfiguration; 28 | 29 | /** 30 | * @param elementsWithConfiguration all {@link Element}s annotated with {@link org.leandreck.endpoints.annotations.TypeScriptTemplatesConfiguration} 31 | */ 32 | public MultipleConfigurationsFoundException(final Set elementsWithConfiguration) { 33 | this.elementsWithConfiguration = new HashSet<>(elementsWithConfiguration); 34 | } 35 | 36 | /** 37 | * All {@link Element}s annotated with {@link org.leandreck.endpoints.annotations.TypeScriptTemplatesConfiguration}. 38 | * @return set of {@link Element} 39 | */ 40 | public Set getElementsWithConfiguration() { 41 | return elementsWithConfiguration; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /annotations/src/main/java/org/leandreck/endpoints/processor/model/EndpointNode.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.leandreck.endpoints.processor.model; 17 | 18 | import java.util.*; 19 | 20 | import static java.util.stream.Collectors.toList; 21 | 22 | /** 23 | */ 24 | public class EndpointNode { 25 | 26 | private final String serviceName; 27 | private final String serviceURL; 28 | private final String template; 29 | private final List methods; 30 | private final List getMethods; 31 | private final List headMethods; 32 | private final List postMethods; 33 | private final List putMethods; 34 | private final List patchMethods; 35 | private final List deleteMethods; 36 | private final List optionsMethods; 37 | private final List traceMethods; 38 | private final Set types; 39 | private final PrintConfiguration printConfiguration; 40 | private final String doc; 41 | 42 | 43 | /** 44 | * Constructor. 45 | * 46 | * @param serviceName {@link #getServiceName()} 47 | * @param serviceURL {@link #getServiceURL()} 48 | * @param doc {@link #getDoc()} 49 | * @param template {@link #getTemplate()} 50 | * @param methods {@link #getMethods} 51 | * @param printConfiguration {@link #getPrintConfiguration()} 52 | */ 53 | EndpointNode(final String serviceName, final String serviceURL, final String doc, final String template, final List methods, final PrintConfiguration printConfiguration) { 54 | this.serviceName = serviceName; 55 | this.serviceURL = serviceURL; 56 | this.doc = doc; 57 | this.template = template; 58 | this.methods = methods; 59 | this.printConfiguration = printConfiguration; 60 | 61 | this.getMethods = this.getMethods().stream().filter(m -> m.getHttpMethods().contains("get")).collect(toList()); 62 | this.headMethods = this.getMethods().stream().filter(m -> m.getHttpMethods().contains("head")).collect(toList()); 63 | this.postMethods = this.getMethods().stream().filter(m -> m.getHttpMethods().contains("post")).collect(toList()); 64 | this.putMethods = this.getMethods().stream().filter(m -> m.getHttpMethods().contains("put")).collect(toList()); 65 | this.patchMethods = this.getMethods().stream().filter(m -> m.getHttpMethods().contains("patch")).collect(toList()); 66 | this.deleteMethods = this.getMethods().stream().filter(m -> m.getHttpMethods().contains("delete")).collect(toList()); 67 | this.optionsMethods = this.getMethods().stream().filter(m -> m.getHttpMethods().contains("options")).collect(toList()); 68 | this.traceMethods = this.getMethods().stream().filter(m -> m.getHttpMethods().contains("trace")).collect(toList()); 69 | 70 | this.types = collectTypes(); 71 | } 72 | 73 | private Set collectTypes() { 74 | final Map typeMap = new HashMap<>(); 75 | 76 | this.getMethods().stream() 77 | .map(MethodNode::getTypes) 78 | .flatMap(Collection::stream) 79 | .filter(TypeNode::isDeclaredComplexType) 80 | .forEach(type -> typeMap.put(type.getTypeName(), type)); 81 | return new HashSet<>(typeMap.values()); 82 | } 83 | 84 | /** 85 | * Name of this EndpointNode, usually this is the Name of the Java Class of the Endpoint. 86 | * 87 | * @return serviceName 88 | */ 89 | public String getServiceName() { 90 | return serviceName; 91 | } 92 | 93 | /** 94 | * Base URL of this EndpointNode corresponds to value of @RequestMapping on the Java Class. 95 | * 96 | * @return serviceURL 97 | */ 98 | public String getServiceURL() { 99 | return serviceURL; 100 | } 101 | 102 | public List getMethods() { 103 | return methods; 104 | } 105 | 106 | public String getTemplate() { 107 | return template; 108 | } 109 | 110 | public Set getTypes() { 111 | return types; 112 | } 113 | 114 | public List getGetMethods() { 115 | return getMethods; 116 | } 117 | 118 | public List getHeadMethods() { 119 | return headMethods; 120 | } 121 | 122 | public List getPostMethods() { 123 | return postMethods; 124 | } 125 | 126 | public List getTraceMethods() { 127 | return traceMethods; 128 | } 129 | 130 | public List getOptionsMethods() { 131 | return optionsMethods; 132 | } 133 | 134 | public List getDeleteMethods() { 135 | return deleteMethods; 136 | } 137 | 138 | public List getPatchMethods() { 139 | return patchMethods; 140 | } 141 | 142 | public List getPutMethods() { 143 | return putMethods; 144 | } 145 | 146 | /** 147 | * Template Engine Configuration of this {@link EndpointNode} for customizing the generated output. 148 | * @return printConfiguration 149 | */ 150 | public PrintConfiguration getPrintConfiguration() { 151 | return printConfiguration; 152 | } 153 | 154 | /** 155 | * Documentation of this Endpointnode, this is the pure content of the JavaDoc of the Endpoint Java Class, 156 | * without any formatting characters or indentation. 157 | * 158 | * @return doc 159 | */ 160 | public String getDoc() { 161 | return doc; 162 | } 163 | } 164 | -------------------------------------------------------------------------------- /annotations/src/main/java/org/leandreck/endpoints/processor/model/EndpointNodeFactory.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.leandreck.endpoints.processor.model; 17 | 18 | import static javax.lang.model.type.TypeKind.DECLARED; 19 | 20 | import java.util.ArrayList; 21 | import java.util.List; 22 | 23 | import javax.lang.model.element.TypeElement; 24 | import javax.lang.model.type.DeclaredType; 25 | import javax.lang.model.type.TypeMirror; 26 | import javax.lang.model.util.ElementFilter; 27 | import javax.lang.model.util.Elements; 28 | import javax.lang.model.util.Types; 29 | 30 | import org.leandreck.endpoints.annotations.TypeScriptEndpoint; 31 | import org.leandreck.endpoints.processor.config.TemplateConfiguration; 32 | import org.springframework.web.bind.annotation.RequestMapping; 33 | 34 | /** 35 | */ 36 | public class EndpointNodeFactory { 37 | 38 | private final MethodNodeFactory methodNodeFactory; 39 | private final TemplateConfiguration configuration; 40 | private final Elements elementUtils; 41 | 42 | public EndpointNodeFactory(final TemplateConfiguration configuration, 43 | final Types typeUtils, 44 | final Elements elementUtils) { 45 | this.configuration = configuration; 46 | this.methodNodeFactory = new MethodNodeFactory(configuration, typeUtils, elementUtils); 47 | this.elementUtils = elementUtils; 48 | } 49 | 50 | public EndpointNode createEndpointNode(final TypeElement typeElement) { 51 | 52 | final TypeScriptEndpoint annotation = typeElement.getAnnotation(TypeScriptEndpoint.class); 53 | 54 | final String name = defineName(typeElement, annotation); 55 | final String url = defineUrl(typeElement); 56 | final String template = defineTemplate(annotation); 57 | final List methods = defineMethods(typeElement, (DeclaredType) typeElement.asType()); 58 | 59 | final String doc = elementUtils.getDocComment(typeElement); 60 | 61 | return new EndpointNode(name, url, doc, template, methods, configuration.getGlobalPrintConfiguration()); 62 | } 63 | 64 | private List defineMethods(final TypeElement typeElement, final DeclaredType containingType) { 65 | final TypeMirror superclass = typeElement.getSuperclass(); 66 | final List superclassMethods; 67 | if (DECLARED.equals(superclass.getKind()) && !"java.lang.Object".equals(superclass.toString())) { 68 | superclassMethods = defineMethods((TypeElement) ((DeclaredType)superclass).asElement(), containingType); 69 | } else { 70 | superclassMethods = new ArrayList<>(20); 71 | } 72 | 73 | //Implemented Interfaces: 74 | typeElement.getInterfaces().stream() 75 | .flatMap(it -> defineMethods((TypeElement) ((DeclaredType)it).asElement(), containingType).stream()) 76 | .forEach(superclassMethods::add); 77 | 78 | //Own enclosed Methods 79 | ElementFilter.methodsIn(typeElement.getEnclosedElements()).stream() 80 | .map(methodElement -> methodNodeFactory.createMethodNode(methodElement, containingType)) 81 | .filter(method -> !method.isIgnored()) 82 | .forEach(superclassMethods::add); 83 | return superclassMethods; 84 | } 85 | 86 | private static String defineName(final TypeElement typeElement, final TypeScriptEndpoint annotation) { 87 | final String name; 88 | if (annotation.value().isEmpty()) { 89 | name = typeElement.getSimpleName().toString(); 90 | } else { 91 | name = annotation.value(); 92 | } 93 | return name; 94 | } 95 | 96 | private static String defineUrl(final TypeElement typeElement) { 97 | final RequestMapping requestMapping = typeElement.getAnnotation(RequestMapping.class); 98 | if (requestMapping != null) { 99 | final String[] mappings = requestMapping.value(); 100 | if (mappings.length > 0) { 101 | return mappings[0]; 102 | } 103 | } 104 | return ""; 105 | } 106 | 107 | private String defineTemplate(final TypeScriptEndpoint annotation) { 108 | final String template; 109 | if (annotation == null || annotation.template().isEmpty()) { 110 | template = configuration.getEndpointTemplate(); 111 | } else { 112 | template = annotation.template(); 113 | } 114 | 115 | return template; 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /annotations/src/main/java/org/leandreck/endpoints/processor/model/EnumValue.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.leandreck.endpoints.processor.model; 17 | 18 | /** 19 | */ 20 | public class EnumValue { 21 | 22 | private final String name; 23 | 24 | public EnumValue(String name) { 25 | this.name = name; 26 | } 27 | 28 | public String getName() { 29 | return name; 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /annotations/src/main/java/org/leandreck/endpoints/processor/model/InitTypeNodeFactoriesException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.leandreck.endpoints.processor.model; 17 | 18 | public class InitTypeNodeFactoriesException extends RuntimeException { 19 | 20 | public InitTypeNodeFactoriesException(Throwable cause) { 21 | super(cause); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /annotations/src/main/java/org/leandreck/endpoints/processor/model/PrintConfiguration.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.leandreck.endpoints.processor.model; 17 | 18 | /** 19 | * Configuration for customizing some aspects of the generated TypeScript files. 20 | * Is available in ftl-templates while generating Endpoints. 21 | */ 22 | public class PrintConfiguration { 23 | 24 | private final boolean useSuffixes; 25 | private final String suffixGet; 26 | private final String suffixHead; 27 | private final String suffixDelete; 28 | private final String suffixOptions; 29 | private final String suffixPatch; 30 | private final String suffixPost; 31 | private final String suffixPut; 32 | private final String suffixTrace; 33 | 34 | public PrintConfiguration(final boolean useSuffixes, 35 | final String suffixGet, 36 | final String suffixHead, 37 | final String suffixDelete, 38 | final String suffixOptions, 39 | final String suffixPatch, 40 | final String suffixPost, 41 | final String suffixPut, 42 | final String suffixTrace) { 43 | this.useSuffixes = useSuffixes; 44 | this.suffixGet = suffixGet; 45 | this.suffixHead = suffixHead; 46 | this.suffixDelete = suffixDelete; 47 | this.suffixOptions = suffixOptions; 48 | this.suffixPatch = suffixPatch; 49 | this.suffixPost = suffixPost; 50 | this.suffixPut = suffixPut; 51 | this.suffixTrace = suffixTrace; 52 | } 53 | 54 | /** 55 | * Returns wether the templates should use suffixes for Methods or not. 56 | * @return true if suffixes should be used. 57 | */ 58 | public boolean isUseSuffixes() { 59 | return useSuffixes; 60 | } 61 | 62 | /** 63 | * Suffix for HTTP-GET Methods. 64 | * @return Suffix String. 65 | */ 66 | public String getSuffixGet() { 67 | return suffixGet; 68 | } 69 | 70 | /** 71 | * Suffix for HTTP-HEAD Methods. 72 | * @return Suffix String. 73 | */ 74 | public String getSuffixHead() { 75 | return suffixHead; 76 | } 77 | 78 | /** 79 | * Suffix for HTTP-DELETE Methods. 80 | * @return Suffix String. 81 | */ 82 | public String getSuffixDelete() { 83 | return suffixDelete; 84 | } 85 | 86 | /** 87 | * Suffix for HTTP-OPTIONS Methods. 88 | * @return Suffix String. 89 | */ 90 | public String getSuffixOptions() { 91 | return suffixOptions; 92 | } 93 | 94 | /** 95 | * Suffix for HTTP-PATCH Methods. 96 | * @return Suffix String. 97 | */ 98 | public String getSuffixPatch() { 99 | return suffixPatch; 100 | } 101 | 102 | /** 103 | * Suffix for HTTP-POST Methods. 104 | * @return Suffix String. 105 | */ 106 | public String getSuffixPost() { 107 | return suffixPost; 108 | } 109 | 110 | /** 111 | * Suffix for HTTP-PUT Methods. 112 | * @return Suffix String. 113 | */ 114 | public String getSuffixPut() { 115 | return suffixPut; 116 | } 117 | 118 | /** 119 | * Suffix for HTTP-TRACE Methods. 120 | * @return Suffix String. 121 | */ 122 | public String getSuffixTrace() { 123 | return suffixTrace; 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /annotations/src/main/java/org/leandreck/endpoints/processor/model/RequestMapping.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.leandreck.endpoints.processor.model; 17 | 18 | import org.springframework.web.bind.annotation.RequestMethod; 19 | 20 | import java.util.Arrays; 21 | 22 | /** 23 | */ 24 | public class RequestMapping { 25 | 26 | private final RequestMethod[] method; 27 | private final String[] produces; 28 | private final String[] value; 29 | 30 | public RequestMapping(final RequestMethod[] method, final String[] produces, final String[] value) { 31 | this.method = method == null ? new RequestMethod[0] : method; 32 | this.produces = produces == null ? new String[0] : produces; 33 | this.value = value == null ? new String[0] : value; 34 | } 35 | 36 | public RequestMethod[] method() { 37 | return Arrays.copyOf(method, method.length); 38 | } 39 | 40 | public String[] produces() { 41 | return Arrays.copyOf(produces, produces.length); 42 | } 43 | 44 | public String[] value() { 45 | return Arrays.copyOf(value, value.length); 46 | } 47 | 48 | 49 | } 50 | -------------------------------------------------------------------------------- /annotations/src/main/java/org/leandreck/endpoints/processor/model/RequestMappingFactory.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.leandreck.endpoints.processor.model; 17 | 18 | import org.springframework.web.bind.annotation.*; 19 | 20 | import javax.lang.model.element.ExecutableElement; 21 | import java.lang.annotation.Annotation; 22 | import java.lang.reflect.Method; 23 | import java.util.ArrayList; 24 | import java.util.Arrays; 25 | import java.util.List; 26 | 27 | import static org.springframework.web.bind.annotation.RequestMethod.*; 28 | 29 | /** 30 | */ 31 | public class RequestMappingFactory { 32 | 33 | public RequestMapping createRequestMapping(final ExecutableElement methodElement) { 34 | final ArrayList methods = new ArrayList<>(); 35 | final ArrayList produces = new ArrayList<>(); 36 | final ArrayList value = new ArrayList<>(); 37 | 38 | populate(methods, produces, value, methodElement.getAnnotation(org.springframework.web.bind.annotation.RequestMapping.class), null); 39 | populate(methods, produces, value, methodElement.getAnnotation(GetMapping.class), GET); 40 | populate(methods, produces, value, methodElement.getAnnotation(PostMapping.class), POST); 41 | populate(methods, produces, value, methodElement.getAnnotation(PutMapping.class), PUT); 42 | populate(methods, produces, value, methodElement.getAnnotation(DeleteMapping.class), DELETE); 43 | populate(methods, produces, value, methodElement.getAnnotation(PatchMapping.class), PATCH); 44 | 45 | return new RequestMapping(methods.toArray(new RequestMethod[0]), produces.toArray(new String[0]), value.toArray(new String[0])); 46 | } 47 | 48 | public void populate(final List methods, final List produces, final List value, final Annotation annotation, final RequestMethod requestMethod) { 49 | if (annotation != null) { 50 | if (annotation instanceof org.springframework.web.bind.annotation.RequestMapping) { 51 | org.springframework.web.bind.annotation.RequestMapping requestMapping = (org.springframework.web.bind.annotation.RequestMapping) annotation; 52 | final RequestMethod[] methods2Add = requestMapping.method(); 53 | if (methods2Add.length == 0) { 54 | methods.add(GET); 55 | } else { 56 | methods.addAll(Arrays.asList(requestMapping.method())); 57 | } 58 | } 59 | 60 | if (requestMethod != null) { 61 | methods.add(requestMethod); 62 | } 63 | 64 | produces.addAll(Arrays.asList(invokeMethod(annotation, "produces"))); 65 | value.addAll(Arrays.asList(invokeMethod(annotation, "value"))); 66 | } 67 | } 68 | 69 | private String[] invokeMethod(final Annotation annotation, final String methodName) { 70 | 71 | try { 72 | final Method method = annotation.getClass().getMethod(methodName); 73 | return (String[]) method.invoke(annotation); 74 | } catch (final ReflectiveOperationException wontHappen) { 75 | //this is never going to happen! 76 | } 77 | 78 | return new String[0]; 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /annotations/src/main/java/org/leandreck/endpoints/processor/model/StringUtil.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.leandreck.endpoints.processor.model; 17 | 18 | import java.util.Arrays; 19 | import java.util.Objects; 20 | 21 | /** 22 | * A class with minimal string utilities. 23 | */ 24 | public class StringUtil { 25 | 26 | /** 27 | * Returns the first defined value from the list of items, or 28 | * null if no value is defined. 29 | * @param items list of values 30 | * @return first found value 31 | */ 32 | public static String definedValue(String... items) { 33 | 34 | return Arrays.stream(items) 35 | .filter(Objects::nonNull) 36 | .filter(it -> !it.isEmpty()) 37 | .findFirst() 38 | .orElse(null); 39 | } 40 | 41 | 42 | /** 43 | * No Instances of this utility class. 44 | */ 45 | private StringUtil() { 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /annotations/src/main/java/org/leandreck/endpoints/processor/model/UnkownTypeProcessingException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.leandreck.endpoints.processor.model; 17 | 18 | public class UnkownTypeProcessingException extends RuntimeException { 19 | UnkownTypeProcessingException(Throwable cause) { 20 | super(cause); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /annotations/src/main/java/org/leandreck/endpoints/processor/model/VariableAnnotations.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.leandreck.endpoints.processor.model; 17 | 18 | import javax.lang.model.element.AnnotationMirror; 19 | import javax.lang.model.element.VariableElement; 20 | import java.util.Arrays; 21 | 22 | public enum VariableAnnotations { 23 | 24 | PATH_VARIABLE("org.springframework.web.bind.annotation.PathVariable"), 25 | REQUEST_PARAM("org.springframework.web.bind.annotation.RequestParam"), 26 | REQUEST_BODY("org.springframework.web.bind.annotation.RequestBody"); 27 | 28 | final String annotation; 29 | 30 | VariableAnnotations(final String annotation) { 31 | this.annotation = annotation; 32 | } 33 | 34 | public static boolean isOptionalByAnnotation(final VariableElement variableElement) { 35 | return variableElement.getAnnotationMirrors().stream() 36 | .map(VariableAnnotations::isOptional) 37 | .reduce((r, r2) -> (r || r2)).orElse(false); 38 | } 39 | 40 | public static boolean isOptional(final AnnotationMirror annotationMirror) { 41 | final boolean relevantAnnotation = Arrays.stream(VariableAnnotations.values()) 42 | .map(it -> annotationMirror.getAnnotationType().toString().startsWith(it.annotation)) 43 | .reduce((a, b) -> a || b).orElse(false); 44 | 45 | final boolean optional; 46 | if (relevantAnnotation) { 47 | final String required = annotationMirror.getElementValues().entrySet().stream().filter(e -> e.getKey().toString().equals("required()")).map(e -> e.getValue().toString()).findFirst().orElse("true"); 48 | optional = !Boolean.valueOf(required); 49 | } else { 50 | optional = false; 51 | } 52 | 53 | return optional; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /annotations/src/main/java/org/leandreck/endpoints/processor/model/typefactories/ArrayTypeNodeFactory.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.leandreck.endpoints.processor.model.typefactories; 17 | 18 | import org.leandreck.endpoints.processor.config.TemplateConfiguration; 19 | import org.leandreck.endpoints.processor.model.EnumValue; 20 | import org.leandreck.endpoints.processor.model.TypeNode; 21 | import org.leandreck.endpoints.processor.model.TypeNodeFactory; 22 | 23 | import javax.lang.model.type.ArrayType; 24 | import javax.lang.model.type.DeclaredType; 25 | import javax.lang.model.type.TypeMirror; 26 | import javax.lang.model.util.Elements; 27 | import javax.lang.model.util.Types; 28 | import java.util.List; 29 | import java.util.Set; 30 | 31 | /** 32 | * Concrete Factory for {@link ArrayTypeNode}. 33 | */ 34 | final class ArrayTypeNodeFactory implements ConcreteTypeNodeFactory { 35 | 36 | private final TypeNodeFactory typeNodeFactory; 37 | 38 | /** 39 | * Prototype Constructor for Registration in {@link TypeNodeKind}. 40 | */ 41 | ArrayTypeNodeFactory() { 42 | typeNodeFactory = null; 43 | } 44 | 45 | private ArrayTypeNodeFactory(final TypeNodeFactory typeNodeFactory) { 46 | this.typeNodeFactory = typeNodeFactory; 47 | } 48 | 49 | @Override 50 | public ConcreteTypeNodeFactory newConfiguredInstance(final TypeNodeFactory typeNodeFactory, final TemplateConfiguration configuration, final Types typeUtils, final Elements elementUtils) { 51 | return new ArrayTypeNodeFactory(typeNodeFactory); 52 | } 53 | 54 | @Override 55 | public TypeNode createTypeNode(final String fieldName, final String parameterName, final boolean optional, final TypeMirror typeMirror, final DeclaredType containingType) { 56 | final ArrayType arrayMirror = (ArrayType) typeMirror; 57 | final TypeMirror componentMirror = arrayMirror.getComponentType(); 58 | final TypeNode componentType = typeNodeFactory.createTypeNode(fieldName, parameterName, componentMirror, containingType); 59 | return new ArrayTypeNode(optional, componentType); 60 | } 61 | 62 | private final class ArrayTypeNode extends TypeNode { 63 | 64 | private final TypeNode componentType; 65 | 66 | private ArrayTypeNode(final boolean optional, final TypeNode componentType) { 67 | super(optional); 68 | this.componentType = componentType; 69 | } 70 | 71 | @Override 72 | public String getFieldName() { 73 | return componentType.getFieldName(); 74 | } 75 | 76 | @Override 77 | public String getParameterName() { 78 | return componentType.getParameterName(); 79 | } 80 | 81 | @Override 82 | public String getTypeName() { 83 | return componentType.getTypeName(); 84 | } 85 | 86 | @Override 87 | public String getType() { 88 | return componentType.getType() + "[]"; 89 | } 90 | 91 | @Override 92 | public String getTemplate() { 93 | return componentType.getTemplate(); 94 | } 95 | 96 | @Override 97 | public boolean isMappedType() { 98 | return componentType.isMappedType(); 99 | } 100 | 101 | @Override 102 | public TypeNodeKind getKind() { 103 | return TypeNodeKind.ARRAY; 104 | } 105 | 106 | @Override 107 | public List getTypeParameters() { 108 | return componentType.getTypeParameters(); 109 | } 110 | 111 | @Override 112 | public List getChildren() { 113 | return componentType.getChildren(); 114 | } 115 | 116 | @Override 117 | public Set getTypes() { 118 | return componentType.getTypes(); 119 | } 120 | 121 | @Override 122 | public Set getImports() { 123 | return componentType.getImports(); 124 | } 125 | 126 | @Override 127 | public Set getEnumValues() { 128 | return componentType.getEnumValues(); 129 | } 130 | 131 | @Override 132 | public boolean isDeclaredComplexType() { 133 | return componentType.isDeclaredComplexType(); 134 | } 135 | 136 | @Override 137 | public String getTypeNameVariable() { 138 | return componentType.getTypeNameVariable() + "[]"; 139 | } 140 | } 141 | } 142 | -------------------------------------------------------------------------------- /annotations/src/main/java/org/leandreck/endpoints/processor/model/typefactories/CollectionTypeNodeFactory.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.leandreck.endpoints.processor.model.typefactories; 17 | 18 | import org.leandreck.endpoints.processor.config.TemplateConfiguration; 19 | import org.leandreck.endpoints.processor.model.EnumValue; 20 | import org.leandreck.endpoints.processor.model.TypeNode; 21 | import org.leandreck.endpoints.processor.model.TypeNodeFactory; 22 | 23 | import javax.lang.model.type.DeclaredType; 24 | import javax.lang.model.type.TypeKind; 25 | import javax.lang.model.type.TypeMirror; 26 | import javax.lang.model.util.Elements; 27 | import javax.lang.model.util.Types; 28 | import java.util.List; 29 | import java.util.Set; 30 | 31 | /** 32 | * Concrete Factory for {@link CollectionTypeNode}. 33 | */ 34 | class CollectionTypeNodeFactory implements ConcreteTypeNodeFactory { 35 | 36 | private final TypeNodeFactory typeNodeFactory; 37 | private final TypeMirror objectMirror; 38 | 39 | /** 40 | * Prototype Constructor for Registration in {@link TypeNodeKind}. 41 | */ 42 | CollectionTypeNodeFactory() { 43 | typeNodeFactory = null; 44 | objectMirror = null; 45 | } 46 | 47 | private CollectionTypeNodeFactory(final TypeNodeFactory typeNodeFactory, final Elements elementUtils) { 48 | this.typeNodeFactory = typeNodeFactory; 49 | this.objectMirror = TypeNodeUtils.getObjectMirror(elementUtils); 50 | } 51 | 52 | @Override 53 | public ConcreteTypeNodeFactory newConfiguredInstance(final TypeNodeFactory typeNodeFactory, final TemplateConfiguration configuration, final Types typeUtils, final Elements elementUtils) { 54 | return new CollectionTypeNodeFactory(typeNodeFactory, elementUtils); 55 | } 56 | 57 | @Override 58 | public TypeNode createTypeNode(final String fieldName, final String parameterName, final boolean optional, final TypeMirror typeMirror, final DeclaredType containingType) { 59 | final TypeMirror containingTypeMirror = defineContainingTypeMirror(typeMirror); 60 | final TypeNode componentType = typeNodeFactory.createTypeNode(fieldName, parameterName, containingTypeMirror, containingType); 61 | return new CollectionTypeNode(optional, componentType); 62 | } 63 | 64 | private TypeMirror defineContainingTypeMirror(final TypeMirror typeMirror) { 65 | final DeclaredType declaredType = (DeclaredType) typeMirror; 66 | final List typeArguments = declaredType.getTypeArguments(); 67 | return typeArguments.stream() 68 | .map(t -> t.getKind().equals(TypeKind.WILDCARD) ? objectMirror : t) 69 | .findFirst() 70 | .orElse(objectMirror); 71 | } 72 | 73 | private final class CollectionTypeNode extends TypeNode { 74 | 75 | private final TypeNode containingType; 76 | 77 | private CollectionTypeNode(final boolean optional, final TypeNode containingType) { 78 | super(optional); 79 | this.containingType = containingType; 80 | } 81 | 82 | @Override 83 | public String getFieldName() { 84 | return containingType.getFieldName(); 85 | } 86 | 87 | @Override 88 | public String getParameterName() { 89 | return containingType.getParameterName(); 90 | } 91 | 92 | @Override 93 | public String getTypeName() { 94 | return containingType.getTypeName(); 95 | } 96 | 97 | @Override 98 | public String getType() { 99 | return containingType.getType() + "[]"; 100 | } 101 | 102 | @Override 103 | public String getTemplate() { 104 | return containingType.getTemplate(); 105 | } 106 | 107 | @Override 108 | public boolean isMappedType() { 109 | return containingType.isMappedType(); 110 | } 111 | 112 | @Override 113 | public TypeNodeKind getKind() { 114 | return TypeNodeKind.ARRAY; 115 | } 116 | 117 | @Override 118 | public List getTypeParameters() { 119 | return containingType.getTypeParameters(); 120 | } 121 | 122 | @Override 123 | public List getChildren() { 124 | return containingType.getChildren(); 125 | } 126 | 127 | @Override 128 | public Set getTypes() { 129 | return containingType.getTypes(); 130 | } 131 | 132 | @Override 133 | public Set getImports() { 134 | return containingType.getImports(); 135 | } 136 | 137 | @Override 138 | public Set getEnumValues() { 139 | return containingType.getEnumValues(); 140 | } 141 | 142 | @Override 143 | public boolean isDeclaredComplexType() { 144 | return containingType.isDeclaredComplexType(); 145 | } 146 | 147 | @Override 148 | public String getTypeNameVariable() { 149 | return containingType.getTypeNameVariable() + "[]"; 150 | } 151 | } 152 | } 153 | -------------------------------------------------------------------------------- /annotations/src/main/java/org/leandreck/endpoints/processor/model/typefactories/ConcreteTypeNodeFactory.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.leandreck.endpoints.processor.model.typefactories; 17 | 18 | import org.leandreck.endpoints.processor.config.TemplateConfiguration; 19 | import org.leandreck.endpoints.processor.model.TypeNode; 20 | import org.leandreck.endpoints.processor.model.TypeNodeFactory; 21 | 22 | import javax.lang.model.type.DeclaredType; 23 | import javax.lang.model.type.TypeMirror; 24 | import javax.lang.model.util.Elements; 25 | import javax.lang.model.util.Types; 26 | 27 | public interface ConcreteTypeNodeFactory { 28 | 29 | /** 30 | * @param typeNodeFactory {@link TypeNodeFactory} 31 | * @param configuration {@link TemplateConfiguration} 32 | * @param typeUtils {@link Types} 33 | * @param elementUtils {@link Elements} 34 | * @return properly configured instance 35 | */ 36 | ConcreteTypeNodeFactory newConfiguredInstance(final TypeNodeFactory typeNodeFactory, final TemplateConfiguration configuration, 37 | final Types typeUtils, 38 | final Elements elementUtils); 39 | 40 | /** 41 | * Factory-Method for creating concrete {@link TypeNode} instances. 42 | * @param fieldName {@link TypeNode#getFieldName()} 43 | * @param parameterName {@link TypeNode#getParameterName()} 44 | * @param optional {@link TypeNode#isOptional()} 45 | * @param typeMirror {@link TypeMirror} of which the {@link TypeNode} will be created 46 | * @return concrete {@link TypeNode} 47 | * 48 | * @see TypeNode 49 | */ 50 | TypeNode createTypeNode(final String fieldName, 51 | final String parameterName, 52 | final boolean optional, 53 | final TypeMirror typeMirror, 54 | final DeclaredType containingType); 55 | } 56 | -------------------------------------------------------------------------------- /annotations/src/main/java/org/leandreck/endpoints/processor/model/typefactories/MappedTypeNodeFactory.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.leandreck.endpoints.processor.model.typefactories; 17 | 18 | import org.leandreck.endpoints.annotations.TypeScriptType; 19 | import org.leandreck.endpoints.processor.config.TemplateConfiguration; 20 | import org.leandreck.endpoints.processor.model.TypeNode; 21 | import org.leandreck.endpoints.processor.model.TypeNodeFactory; 22 | 23 | import javax.lang.model.type.DeclaredType; 24 | import javax.lang.model.type.TypeKind; 25 | import javax.lang.model.type.TypeMirror; 26 | import javax.lang.model.util.Elements; 27 | import javax.lang.model.util.Types; 28 | import java.util.Collections; 29 | import java.util.List; 30 | import java.util.Set; 31 | 32 | import static org.leandreck.endpoints.processor.model.typefactories.TypeNodeUtils.NO_TEMPLATE; 33 | 34 | class MappedTypeNodeFactory implements ConcreteTypeNodeFactory { 35 | 36 | private final Types typeUtils; 37 | 38 | /** 39 | * Prototype Constructor for Registration in {@link TypeNodeKind}. 40 | */ 41 | MappedTypeNodeFactory() { 42 | typeUtils = null; 43 | } 44 | 45 | private MappedTypeNodeFactory(final Types typeUtils) { 46 | this.typeUtils = typeUtils; 47 | } 48 | 49 | @Override 50 | public ConcreteTypeNodeFactory newConfiguredInstance(final TypeNodeFactory typeNodeFactory, final TemplateConfiguration configuration, final Types typeUtils, final Elements elementUtils) { 51 | return new MappedTypeNodeFactory(typeUtils); 52 | } 53 | 54 | @Override 55 | public TypeNode createTypeNode(final String fieldName, final String parameterName, final boolean optional, final TypeMirror typeMirror, final DeclaredType containingType) { 56 | final TypeScriptType typeScriptTypeAnnotation = TypeNodeUtils.getAnnotationForClass(typeMirror, TypeScriptType.class, typeUtils); 57 | final String typeName = TypeNodeUtils.defineName(typeMirror, typeScriptTypeAnnotation, this::defineNameFromMapped); 58 | 59 | return new MappedTypeNode(optional, fieldName, parameterName, typeName); 60 | } 61 | 62 | private String defineNameFromMapped(final TypeMirror typeMirror) { 63 | final TypeKind kind = typeMirror.getKind(); 64 | final String typeName; 65 | if (kind.isPrimitive() || TypeKind.VOID.equals(kind)) { 66 | typeName = TypeNodeKind.getMapping(kind.name()); 67 | } else { 68 | final String key = typeUtils.asElement(typeMirror).getSimpleName().toString(); 69 | typeName = TypeNodeKind.getMapping(key); 70 | } 71 | return typeName; 72 | } 73 | 74 | class MappedTypeNode extends TypeNode { 75 | 76 | private final String fieldName; 77 | private final String parameterName; 78 | private final String typeName; 79 | 80 | MappedTypeNode(final boolean optional, 81 | final String fieldName, 82 | final String parameterName, 83 | final String typeName) { 84 | super(optional); 85 | this.fieldName = fieldName; 86 | this.parameterName = parameterName; 87 | this.typeName = typeName; 88 | } 89 | 90 | @Override 91 | public String getFieldName() { 92 | return fieldName; 93 | } 94 | 95 | @Override 96 | public String getParameterName() { 97 | return parameterName; 98 | } 99 | 100 | @Override 101 | public String getTypeName() { 102 | return typeName; 103 | } 104 | 105 | @Override 106 | public String getType() { 107 | return getTypeName(); 108 | } 109 | 110 | @Override 111 | public String getTemplate() { 112 | return NO_TEMPLATE; 113 | } 114 | 115 | @Override 116 | public boolean isMappedType() { 117 | return true; 118 | } 119 | 120 | @Override 121 | public TypeNodeKind getKind() { 122 | return TypeNodeKind.MAPPED; 123 | } 124 | 125 | @Override 126 | public List getTypeParameters() { 127 | return Collections.emptyList(); 128 | } 129 | 130 | @Override 131 | public List getChildren() { 132 | return Collections.emptyList(); 133 | } 134 | 135 | @Override 136 | public Set getTypes() { 137 | return Collections.emptySet(); 138 | } 139 | 140 | @Override 141 | public Set getImports() { 142 | return Collections.emptySet(); 143 | } 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /annotations/src/main/java/org/leandreck/endpoints/processor/model/typefactories/MissingConfigurationTemplateException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.leandreck.endpoints.processor.model.typefactories; 17 | 18 | import javax.lang.model.element.Element; 19 | 20 | /** 21 | * Exception thrown if the {@link org.leandreck.endpoints.processor.config.TemplateConfiguration} is null while an {@link Element} is processed. 22 | */ 23 | public class MissingConfigurationTemplateException extends RuntimeException { 24 | 25 | private final transient Element element; 26 | 27 | MissingConfigurationTemplateException(final String message, final Element element) { 28 | super(message); 29 | this.element = element; 30 | } 31 | 32 | /** 33 | * @return The Element processed while hitting the missing {@link org.leandreck.endpoints.processor.config.TemplateConfiguration} 34 | */ 35 | public Element getElement() { 36 | return element; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /annotations/src/main/java/org/leandreck/endpoints/processor/model/typefactories/NullTypeNodeFactory.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.leandreck.endpoints.processor.model.typefactories; 17 | 18 | import org.leandreck.endpoints.processor.config.TemplateConfiguration; 19 | import org.leandreck.endpoints.processor.model.TypeNode; 20 | import org.leandreck.endpoints.processor.model.TypeNodeFactory; 21 | 22 | import javax.lang.model.type.DeclaredType; 23 | import javax.lang.model.type.TypeMirror; 24 | import javax.lang.model.util.Elements; 25 | import javax.lang.model.util.Types; 26 | import java.util.Collections; 27 | import java.util.List; 28 | import java.util.Set; 29 | 30 | import static org.leandreck.endpoints.processor.model.typefactories.TypeNodeUtils.NO_TEMPLATE; 31 | 32 | /** 33 | * Concrete Factory for {@link NullTypeNode}. 34 | */ 35 | final class NullTypeNodeFactory implements ConcreteTypeNodeFactory { 36 | 37 | /** 38 | * Prototype Constructor for Registration in {@link TypeNodeKind}. 39 | */ 40 | NullTypeNodeFactory() { 41 | } 42 | 43 | @Override 44 | public ConcreteTypeNodeFactory newConfiguredInstance(final TypeNodeFactory typeNodeFactory, final TemplateConfiguration configuration, final Types typeUtils, final Elements elementUtils) { 45 | return new NullTypeNodeFactory(); 46 | } 47 | 48 | @Override 49 | public TypeNode createTypeNode(final String fieldName, final String parameterName, final boolean optional, final TypeMirror typeMirror, final DeclaredType containingType) { 50 | return new NullTypeNode(fieldName); 51 | } 52 | 53 | private final class NullTypeNode extends TypeNode { 54 | 55 | private final String fieldName; 56 | 57 | private NullTypeNode(final String fieldName) { 58 | super(false); 59 | this.fieldName = fieldName; 60 | } 61 | 62 | @Override 63 | public String getFieldName() { 64 | return fieldName; 65 | } 66 | 67 | @Override 68 | public String getParameterName() { 69 | return null; 70 | } 71 | 72 | @Override 73 | public String getTypeName() { 74 | return "any | null"; 75 | } 76 | 77 | @Override 78 | public String getType() { 79 | return getTypeName(); 80 | } 81 | 82 | @Override 83 | public String getTemplate() { 84 | return NO_TEMPLATE; 85 | } 86 | 87 | @Override 88 | public boolean isMappedType() { 89 | return true; 90 | } 91 | 92 | @Override 93 | public TypeNodeKind getKind() { 94 | return TypeNodeKind.NULL; 95 | } 96 | 97 | @Override 98 | public List getTypeParameters() { 99 | return Collections.emptyList(); 100 | } 101 | 102 | @Override 103 | public List getChildren() { 104 | return Collections.emptyList(); 105 | } 106 | 107 | @Override 108 | public Set getTypes() { 109 | return Collections.emptySet(); 110 | } 111 | 112 | @Override 113 | public Set getImports() { 114 | return Collections.emptySet(); 115 | } 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /annotations/src/main/java/org/leandreck/endpoints/processor/model/typefactories/OptionalTypeNodeFactory.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.leandreck.endpoints.processor.model.typefactories; 17 | 18 | import org.leandreck.endpoints.processor.config.TemplateConfiguration; 19 | import org.leandreck.endpoints.processor.model.EnumValue; 20 | import org.leandreck.endpoints.processor.model.TypeNode; 21 | import org.leandreck.endpoints.processor.model.TypeNodeFactory; 22 | 23 | import javax.lang.model.type.DeclaredType; 24 | import javax.lang.model.type.TypeKind; 25 | import javax.lang.model.type.TypeMirror; 26 | import javax.lang.model.util.Elements; 27 | import javax.lang.model.util.Types; 28 | import java.util.List; 29 | import java.util.Set; 30 | 31 | /** 32 | * Concrete Factory for {@link OptionalTypeNodeFactory}. 33 | */ 34 | final class OptionalTypeNodeFactory implements ConcreteTypeNodeFactory { 35 | 36 | private final TypeNodeFactory typeNodeFactory; 37 | private final TypeMirror objectMirror; 38 | 39 | /** 40 | * Prototype Constructor for Registration in {@link TypeNodeKind}. 41 | */ 42 | OptionalTypeNodeFactory() { 43 | typeNodeFactory = null; 44 | objectMirror = null; 45 | } 46 | 47 | private OptionalTypeNodeFactory(final TypeNodeFactory typeNodeFactory, final Elements elementUtils) { 48 | this.typeNodeFactory = typeNodeFactory; 49 | this.objectMirror = TypeNodeUtils.getObjectMirror(elementUtils); 50 | } 51 | 52 | @Override 53 | public ConcreteTypeNodeFactory newConfiguredInstance(final TypeNodeFactory typeNodeFactory, final TemplateConfiguration configuration, final Types typeUtils, final Elements elementUtils) { 54 | return new OptionalTypeNodeFactory(typeNodeFactory, elementUtils); 55 | } 56 | 57 | @Override 58 | public TypeNode createTypeNode(final String fieldName, final String parameterName, final boolean optional, final TypeMirror typeMirror, final DeclaredType containingType) { 59 | final TypeNode componentType = typeNodeFactory.createTypeNode(fieldName, parameterName, defineValueMirror(typeMirror), containingType); 60 | return new OptionalTypeNode(componentType); 61 | } 62 | 63 | private TypeMirror defineValueMirror(final TypeMirror typeMirror) { 64 | final DeclaredType declaredType = (DeclaredType) typeMirror; 65 | final List typeArguments = declaredType.getTypeArguments(); 66 | 67 | return typeArguments.stream() 68 | .map(t -> t.getKind().equals(TypeKind.WILDCARD) ? objectMirror : t) 69 | .findFirst().orElse(objectMirror); 70 | } 71 | 72 | private final class OptionalTypeNode extends TypeNode { 73 | 74 | private final TypeNode valueType; 75 | 76 | private OptionalTypeNode(final TypeNode valueType) { 77 | super(true); //always true 78 | this.valueType = valueType; 79 | } 80 | 81 | @Override 82 | public String getFieldName() { 83 | return valueType.getFieldName(); 84 | } 85 | 86 | @Override 87 | public String getParameterName() { 88 | return valueType.getParameterName(); 89 | } 90 | 91 | @Override 92 | public String getTypeName() { 93 | return valueType.getTypeName(); 94 | } 95 | 96 | @Override 97 | public String getType() { 98 | return valueType.getType(); 99 | } 100 | 101 | @Override 102 | public String getTemplate() { 103 | return valueType.getTemplate(); 104 | } 105 | 106 | @Override 107 | public boolean isMappedType() { 108 | return valueType.isMappedType(); 109 | } 110 | 111 | @Override 112 | public TypeNodeKind getKind() { 113 | return TypeNodeKind.OPTIONAL; 114 | } 115 | 116 | @Override 117 | public List getTypeParameters() { 118 | return valueType.getTypeParameters(); 119 | } 120 | 121 | @Override 122 | public List getChildren() { 123 | return valueType.getChildren(); 124 | } 125 | 126 | @Override 127 | public Set getTypes() { 128 | return valueType.getTypes(); 129 | } 130 | 131 | @Override 132 | public Set getImports() { 133 | return valueType.getImports(); 134 | } 135 | 136 | @Override 137 | public Set getEnumValues() { 138 | return valueType.getEnumValues(); 139 | } 140 | 141 | @Override 142 | public boolean isDeclaredComplexType() { 143 | return valueType.isDeclaredComplexType(); 144 | } 145 | } 146 | } 147 | -------------------------------------------------------------------------------- /annotations/src/main/java/org/leandreck/endpoints/processor/model/typefactories/TypeNodeKind.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.leandreck.endpoints.processor.model.typefactories; 17 | 18 | import org.leandreck.endpoints.processor.model.InitTypeNodeFactoriesException; 19 | 20 | import java.util.HashMap; 21 | import java.util.Map; 22 | 23 | /** 24 | */ 25 | public enum TypeNodeKind { 26 | 27 | SIMPLE(SimpleTypeNodeFactory.class), 28 | ARRAY(ArrayTypeNodeFactory.class), 29 | COLLECTION(CollectionTypeNodeFactory.class), 30 | MAP(MapTypeNodeFactory.class), 31 | ENUM(EnumTypeNodeFactory.class), 32 | MAPPED(MappedTypeNodeFactory.class), 33 | OPTIONAL(OptionalTypeNodeFactory.class), 34 | TYPEVAR(TypeVarTypeNodeFactory.class), 35 | NULL(NullTypeNodeFactory.class); 36 | 37 | private static final String NUMBER_TYPE = "number"; 38 | private static final String STRING_TYPE = "string"; 39 | private static final String BOOLEAN_TYPE = "boolean"; 40 | private static final Map mappings = new HashMap<>(20); 41 | 42 | static { 43 | //Void 44 | mappings.put("VOID", "void"); 45 | 46 | //Number 47 | mappings.put("BYTE", NUMBER_TYPE); 48 | mappings.put("Byte", NUMBER_TYPE); 49 | mappings.put("SHORT", NUMBER_TYPE); 50 | mappings.put("Short", NUMBER_TYPE); 51 | mappings.put("INT", NUMBER_TYPE); 52 | mappings.put("Integer", NUMBER_TYPE); 53 | mappings.put("LONG", NUMBER_TYPE); 54 | mappings.put("Long", NUMBER_TYPE); 55 | mappings.put("FLOAT", NUMBER_TYPE); 56 | mappings.put("Float", NUMBER_TYPE); 57 | mappings.put("DOUBLE", NUMBER_TYPE); 58 | mappings.put("Double", NUMBER_TYPE); 59 | mappings.put("BigDecimal", NUMBER_TYPE); 60 | mappings.put("BigInteger", NUMBER_TYPE); 61 | 62 | //String 63 | mappings.put("CHAR", STRING_TYPE); 64 | mappings.put("Character", STRING_TYPE); 65 | mappings.put("String", STRING_TYPE); 66 | 67 | //Boolean 68 | mappings.put("BOOLEAN", BOOLEAN_TYPE); 69 | mappings.put("Boolean", BOOLEAN_TYPE); 70 | 71 | //Date 72 | mappings.put("Date", "Date"); 73 | mappings.put("LocalDate", "Date"); 74 | 75 | //any 76 | mappings.put("Object", "any"); 77 | 78 | //MultipartFile 79 | mappings.put("MultipartFile", "FormData"); 80 | } 81 | 82 | 83 | private final ConcreteTypeNodeFactory typeNodeFactory; 84 | 85 | TypeNodeKind(final Class typeNodeFactory) { 86 | ConcreteTypeNodeFactory tmpFactory = null; 87 | try { 88 | tmpFactory = typeNodeFactory.newInstance(); 89 | } catch (InstantiationException | IllegalAccessException e) { 90 | throw new InitTypeNodeFactoriesException(e); 91 | } 92 | this.typeNodeFactory = tmpFactory; 93 | } 94 | 95 | public ConcreteTypeNodeFactory getTypeNodeFactory() { 96 | return typeNodeFactory; 97 | } 98 | 99 | public static boolean containsMapping(final String key) { 100 | return mappings.containsKey(key); 101 | } 102 | 103 | public static String getMapping(final String key) { 104 | return mappings.get(key); 105 | } 106 | } 107 | 108 | -------------------------------------------------------------------------------- /annotations/src/main/java/org/leandreck/endpoints/processor/model/typefactories/TypeNodeUtils.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.leandreck.endpoints.processor.model.typefactories; 17 | 18 | import org.leandreck.endpoints.annotations.TypeScriptType; 19 | 20 | import javax.lang.model.element.Element; 21 | import javax.lang.model.type.ArrayType; 22 | import javax.lang.model.type.TypeKind; 23 | import javax.lang.model.type.TypeMirror; 24 | import javax.lang.model.util.Elements; 25 | import javax.lang.model.util.Types; 26 | import java.lang.annotation.Annotation; 27 | import java.util.function.Function; 28 | 29 | public class TypeNodeUtils { 30 | 31 | static final String NO_TEMPLATE = "NO_TEMPLATE"; 32 | static final String UNDEFINED_TYPE_NAME = "UNDEFINED"; 33 | static final String JAVA_LANG_OBJECT = "java.lang.Object"; 34 | static TypeMirror objectMirror; 35 | 36 | public static A getAnnotationForClass(final TypeMirror typeMirror, final Class annotation, final Types typeUtils) { 37 | final TypeKind kind = typeMirror.getKind(); 38 | final TypeMirror realMirror; 39 | if (TypeKind.ARRAY.equals(kind)) { 40 | realMirror = ((ArrayType) typeMirror).getComponentType(); 41 | } else { 42 | realMirror = typeMirror; 43 | } 44 | 45 | final Element definingElement = typeUtils.asElement(realMirror); 46 | return (definingElement != null) ? definingElement.getAnnotation(annotation) : null; 47 | } 48 | 49 | static String defineTemplate(final String typeNodeTemplate, 50 | final TypeScriptType typeScriptTypeAnnotation, 51 | final Element element) { 52 | 53 | if (typeNodeTemplate == null || typeNodeTemplate.isEmpty()) { 54 | throw new MissingConfigurationTemplateException("TemplateConfiguration is null while processing Element", element); 55 | } 56 | 57 | final String template; 58 | if (typeScriptTypeAnnotation == null || typeScriptTypeAnnotation.template().isEmpty()) { 59 | template = typeNodeTemplate; 60 | } else { 61 | template = typeScriptTypeAnnotation.template(); 62 | } 63 | 64 | return template; 65 | } 66 | 67 | static String defineName(final TypeMirror typeMirror, final TypeScriptType typeScriptTypeAnnotation, final Function nameFunction) { 68 | //check if has a annotation and a type 69 | final String typeFromAnnotation = TypeNodeUtils.defineTypeFromAnnotation(typeScriptTypeAnnotation); 70 | if (!UNDEFINED_TYPE_NAME.equals(typeFromAnnotation)) { 71 | return typeFromAnnotation; 72 | } 73 | //forward to furter determination 74 | return nameFunction.apply(typeMirror); 75 | } 76 | 77 | static TypeMirror getObjectMirror(final Elements elementUtils) { 78 | if (objectMirror == null) { 79 | objectMirror = elementUtils.getTypeElement(JAVA_LANG_OBJECT).asType(); 80 | } 81 | return objectMirror; 82 | } 83 | 84 | private static String defineTypeFromAnnotation(final TypeScriptType annotation) { 85 | if (annotation != null && !annotation.value().isEmpty()) { 86 | return annotation.value(); 87 | } 88 | return UNDEFINED_TYPE_NAME; 89 | } 90 | 91 | /** 92 | * No Instances of this utility class. 93 | */ 94 | private TypeNodeUtils() { 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /annotations/src/main/java/org/leandreck/endpoints/processor/model/typefactories/TypeVarTypeNodeFactory.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.leandreck.endpoints.processor.model.typefactories; 17 | 18 | import org.leandreck.endpoints.processor.config.TemplateConfiguration; 19 | import org.leandreck.endpoints.processor.model.EnumValue; 20 | import org.leandreck.endpoints.processor.model.TypeNode; 21 | import org.leandreck.endpoints.processor.model.TypeNodeFactory; 22 | 23 | import javax.lang.model.element.Element; 24 | import javax.lang.model.type.DeclaredType; 25 | import javax.lang.model.type.TypeMirror; 26 | import javax.lang.model.util.Elements; 27 | import javax.lang.model.util.Types; 28 | import java.util.List; 29 | import java.util.Set; 30 | 31 | final class TypeVarTypeNodeFactory implements ConcreteTypeNodeFactory { 32 | 33 | private final TypeNodeFactory typeNodeFactory; 34 | private final Types typeUtils; 35 | 36 | /** 37 | * Prototype Constructor for Registration in {@link TypeNodeKind}. 38 | */ 39 | TypeVarTypeNodeFactory() { 40 | typeUtils = null; 41 | typeNodeFactory = null; 42 | } 43 | 44 | private TypeVarTypeNodeFactory(final TypeNodeFactory typeNodeFactory, final Types typeUtils) { 45 | this.typeNodeFactory = typeNodeFactory; 46 | this.typeUtils = typeUtils; 47 | } 48 | 49 | @Override 50 | public ConcreteTypeNodeFactory newConfiguredInstance(final TypeNodeFactory typeNodeFactory, final TemplateConfiguration configuration, final Types typeUtils, final Elements elementUtils) { 51 | return new TypeVarTypeNodeFactory(typeNodeFactory, typeUtils); 52 | } 53 | 54 | @Override 55 | public TypeNode createTypeNode(final String fieldName, final String parameterName, final boolean optional, final TypeMirror typeMirror, final DeclaredType containingType) { 56 | final Element element = typeUtils.asElement(typeMirror); 57 | final TypeMirror boundMirror = typeUtils.asMemberOf(containingType, element); 58 | final TypeNode boundType = typeNodeFactory.createTypeNode(fieldName, parameterName, boundMirror, containingType); 59 | return new TypeVarTypeNode(optional, element.getSimpleName().toString(), boundType); 60 | } 61 | 62 | private final class TypeVarTypeNode extends TypeNode { 63 | 64 | private final String typeNameVariable; 65 | private final TypeNode boundType; 66 | 67 | private TypeVarTypeNode(final boolean optional, final String typeNameVariable, final TypeNode boundType) { 68 | super(optional); 69 | this.typeNameVariable = typeNameVariable; 70 | this.boundType = boundType; 71 | } 72 | 73 | @Override 74 | public String getFieldName() { 75 | return boundType.getFieldName(); 76 | } 77 | 78 | @Override 79 | public String getParameterName() { 80 | return boundType.getParameterName(); 81 | } 82 | 83 | @Override 84 | public String getTypeName() { 85 | return boundType.getTypeName(); 86 | } 87 | 88 | @Override 89 | public String getType() { 90 | return boundType.getType(); 91 | } 92 | 93 | @Override 94 | public String getTemplate() { 95 | return boundType.getTemplate(); 96 | } 97 | 98 | @Override 99 | public boolean isMappedType() { 100 | return boundType.isMappedType(); 101 | } 102 | 103 | @Override 104 | public TypeNodeKind getKind() { 105 | return TypeNodeKind.TYPEVAR; 106 | } 107 | 108 | @Override 109 | public List getTypeParameters() { 110 | return boundType.getTypeParameters(); 111 | } 112 | 113 | @Override 114 | public List getChildren() { 115 | return boundType.getChildren(); 116 | } 117 | 118 | @Override 119 | public Set getTypes() { 120 | return boundType.getTypes(); 121 | } 122 | 123 | @Override 124 | public Set getImports() { 125 | return boundType.getImports(); 126 | } 127 | 128 | @Override 129 | public Set getEnumValues() { 130 | return boundType.getEnumValues(); 131 | } 132 | 133 | @Override 134 | public boolean isDeclaredComplexType() { 135 | return boundType.isDeclaredComplexType(); 136 | } 137 | 138 | @Override 139 | public String getTypeNameVariable() { 140 | return typeNameVariable; 141 | } 142 | 143 | @Override 144 | public String getDoc() { 145 | return boundType.getDoc(); 146 | } 147 | } 148 | } 149 | -------------------------------------------------------------------------------- /annotations/src/main/java/org/leandreck/endpoints/processor/printer/Engine.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.leandreck.endpoints.processor.printer; 17 | 18 | import java.io.IOException; 19 | import java.io.Writer; 20 | 21 | import org.leandreck.endpoints.processor.config.TemplateConfiguration; 22 | import org.leandreck.endpoints.processor.model.EndpointNode; 23 | import org.leandreck.endpoints.processor.model.TypeNode; 24 | 25 | import freemarker.template.Configuration; 26 | import freemarker.template.Template; 27 | import freemarker.template.TemplateException; 28 | import freemarker.template.TemplateExceptionHandler; 29 | 30 | /** 31 | * Handles Freemarker initialization and processing of the templates. 32 | */ 33 | public class Engine { 34 | 35 | private final Configuration freemarkerConfiguration; 36 | private final TemplateConfiguration templateConfiguration; 37 | 38 | public Engine(TemplateConfiguration configuration) { 39 | this.templateConfiguration = configuration; 40 | 41 | // Create your Configuration instance, and specify if up to what FreeMarker 42 | // version (here 2.3.25) do you want to apply the fixes that are not 100% 43 | // backward-compatible. See the Configuration JavaDoc for details. 44 | this.freemarkerConfiguration = new Configuration(Configuration.VERSION_2_3_23); 45 | 46 | // Set the preferred charset template files are stored in. UTF-8 is 47 | // a good choice in most applications: 48 | this.freemarkerConfiguration.setDefaultEncoding("UTF-8"); 49 | 50 | // Specify the source where the template files come from. Here I set a 51 | // plain directory for it, but non-file-system sources are possible too: 52 | this.freemarkerConfiguration.setClassForTemplateLoading(this.getClass(), "/"); 53 | 54 | 55 | // Sets how errors will appear. 56 | this.freemarkerConfiguration.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER); 57 | 58 | // Don't log exceptions inside FreeMarker that it will thrown at you anyway: 59 | this.freemarkerConfiguration.setLogTemplateExceptions(false); 60 | } 61 | 62 | public void processEndpoint(final EndpointNode clazz, final Writer out) throws IOException, TemplateException { 63 | final Template service = this.freemarkerConfiguration.getTemplate(clazz.getTemplate()); 64 | service.process(clazz, out); 65 | out.append("\n"); 66 | } 67 | 68 | public void processIndexTs(final TypesPackage params, final Writer out) throws IOException, TemplateException { 69 | final Template service = this.freemarkerConfiguration.getTemplate(templateConfiguration.getIndexTemplate()); 70 | service.process(params, out); 71 | out.append("\n"); 72 | } 73 | 74 | public void processModuleTs(final TypesPackage params, final Writer out) throws IOException, TemplateException { 75 | final Template service = this.freemarkerConfiguration.getTemplate(templateConfiguration.getApiModuleTemplate()); 76 | service.process(params, out); 77 | out.append("\n"); 78 | } 79 | 80 | public void processTypeScriptTypeNode(final TypeNode node, final Writer out) throws IOException, TemplateException { 81 | final Template temp = this.freemarkerConfiguration.getTemplate(node.getTemplate()); 82 | temp.process(node, out); 83 | out.append("\n"); 84 | } 85 | 86 | public void processServiceConfig(final Writer out) throws IOException, TemplateException { 87 | final Template service = this.freemarkerConfiguration.getTemplate("/org/leandreck/endpoints/templates/typescript/serviceconfig.ftl"); 88 | service.process(null, out); 89 | out.append("\n"); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /annotations/src/main/java/org/leandreck/endpoints/processor/printer/TypesPackage.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.leandreck.endpoints.processor.printer; 17 | 18 | import org.leandreck.endpoints.processor.model.EndpointNode; 19 | import org.leandreck.endpoints.processor.model.TypeNode; 20 | 21 | import java.util.Set; 22 | 23 | /** 24 | */ 25 | public class TypesPackage { 26 | 27 | private final Set endpoints; 28 | private final Set types; 29 | 30 | public TypesPackage(final Set endpoints, final Set types) { 31 | this.endpoints = endpoints; 32 | this.types = types; 33 | } 34 | 35 | public Set getEndpoints() { 36 | return endpoints; 37 | } 38 | 39 | public Set getTypes() { 40 | return types; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /annotations/src/main/resources/META-INF/services/javax.annotation.processing.Processor: -------------------------------------------------------------------------------- 1 | org.leandreck.endpoints.processor.TypeScriptEndpointProcessor -------------------------------------------------------------------------------- /annotations/src/main/resources/org/leandreck/endpoints/templates/typescript/apimodule.ftl: -------------------------------------------------------------------------------- 1 | <#-- @ftlvariable name="" type="org.leandreck.endpoints.processor.printer.TypesPackage" --> 2 | <#-- 3 | 4 | Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | 18 | --> 19 | import { NgModule, ModuleWithProviders } from '@angular/core'; 20 | <#list endpoints as service> 21 | import { ${service.serviceName} } from './${service.serviceName?lower_case}.generated'; 22 | 23 | import { ServiceConfig } from './serviceconfig'; 24 | 25 | @NgModule({}) 26 | export class APIModule { 27 | static forRoot(serviceConfig: ServiceConfig = {context: ''}): ModuleWithProviders { 28 | return { 29 | ngModule: APIModule, 30 | providers: [ 31 | {provide: ServiceConfig, useValue: serviceConfig}, 32 | <#list endpoints as service> 33 | ${service.serviceName}<#sep>, 34 | 35 | ] 36 | }; 37 | } 38 | } -------------------------------------------------------------------------------- /annotations/src/main/resources/org/leandreck/endpoints/templates/typescript/enum.ftl: -------------------------------------------------------------------------------- 1 | <#-- 2 | 3 | Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | --> 18 | <#-- @ftlvariable name="" type="org.leandreck.endpoints.processor.model.TypeNode" --> 19 | export enum ${typeName} { 20 | <#list enumValues as value> 21 | "${value.name}"<#sep>, 22 | 23 | } -------------------------------------------------------------------------------- /annotations/src/main/resources/org/leandreck/endpoints/templates/typescript/index.ftl: -------------------------------------------------------------------------------- 1 | <#-- @ftlvariable name="" type="org.leandreck.endpoints.processor.printer.TypesPackage" --> 2 | <#-- 3 | 4 | Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | 18 | --> 19 | <#list types as type> 20 | export { ${type.typeName} } from './${type.typeName?lower_case}.model.generated'; 21 | 22 | <#list endpoints as service> 23 | export { ${service.serviceName} } from './${service.serviceName?lower_case}.generated'; 24 | 25 | export { ServiceConfig } from './serviceconfig'; 26 | export { APIModule } from './api.module'; -------------------------------------------------------------------------------- /annotations/src/main/resources/org/leandreck/endpoints/templates/typescript/interface.ftl: -------------------------------------------------------------------------------- 1 | <#-- 2 | 3 | Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | --> 18 | <#-- @ftlvariable name="" type="org.leandreck.endpoints.processor.model.TypeNode" --> 19 | <#-- @ftlvariable name="type" type="org.leandreck.endpoints.processor.model.TypeNode" --> 20 | <#list imports as type> 21 | import { ${type.typeName} } from './${type.typeName?lower_case}.model.generated'; 22 | 23 | 24 | <#if doc??> 25 | <#assign typeDoc = doc?replace('\n', '\n * ')> 26 | /** 27 | * ${typeDoc} 28 | */ 29 | 30 | export interface ${variableType} { 31 | <#list children as property> 32 | <#if property.doc??> 33 | <#assign typeDoc = property.doc?replace('\n', '\n * ')> 34 | /** 35 | * ${typeDoc} 36 | */ 37 | 38 | ${property.fieldName}: ${property.typeNameVariable}; 39 | 40 | } -------------------------------------------------------------------------------- /annotations/src/main/resources/org/leandreck/endpoints/templates/typescript/serviceconfig.ftl: -------------------------------------------------------------------------------- 1 | <#-- 2 | 3 | Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | --> 18 | import { Injectable } from '@angular/core'; 19 | import { HttpErrorResponse } from '@angular/common/http'; 20 | import { ErrorObservable } from 'rxjs/observable/ErrorObservable'; 21 | 22 | @Injectable() 23 | export abstract class ServiceConfig { 24 | context?: string; 25 | debug?: boolean; 26 | onError?(error?: HttpErrorResponse): ErrorObservable; 27 | } -------------------------------------------------------------------------------- /annotations/src/test/groovy/org/leandreck/endpoints/processor/TypeScriptEndpointProcessorErrorSpec.groovy: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.leandreck.endpoints.processor 17 | 18 | import spock.lang.* 19 | 20 | import javax.annotation.processing.Processor 21 | import javax.tools.Diagnostic 22 | import javax.tools.JavaFileObject 23 | import java.nio.file.Files 24 | 25 | /** 26 | */ 27 | @Narrative('''Integration Test for TypeScriptEndpointProcessor which compiles an 28 | Endpoint.java with all possible combinations of possible Errors and checking Diagnostic afterwards. 29 | ''') 30 | @Title("TypeScriptEndpointProcessor Error Integrations") 31 | @Subject(TypeScriptEndpointProcessor) 32 | class TypeScriptEndpointProcessorErrorSpec extends Specification { 33 | 34 | @Shared 35 | def defaultPathBase 36 | 37 | @Shared 38 | def annotationsTarget 39 | 40 | def setupSpec() { 41 | defaultPathBase = new File(".").getCanonicalPath() 42 | annotationsTarget = new File("$defaultPathBase/target/generated-sources/annotations") 43 | Files.createDirectories(annotationsTarget.toPath()) 44 | } 45 | 46 | def "if the template cannot be found an error should be printed"() { 47 | given: "an Endpoint with an invalid template in TypeScriptEndpoint-Annotation" 48 | def classFile = new File("$defaultPathBase/src/test/testcases/org/leandreck/endpoints/notemplate/Endpoint.java") 49 | def folder = "/notemplate" 50 | def destinationFolder = new File("$annotationsTarget/$folder") 51 | Files.createDirectories(destinationFolder.toPath()) 52 | 53 | when: "a simple Endpoint is compiled" 54 | List> diagnostics = 55 | CompilerTestHelper.compileTestCase(Arrays. asList(new TypeScriptEndpointProcessor()), folder, classFile) 56 | 57 | then: "there should be one error on line 26" 58 | diagnostics.size() == 1 59 | diagnostics.every { d -> (Diagnostic.Kind.ERROR == d.kind) } 60 | diagnostics.get(0).getLineNumber() == 26 61 | 62 | cleanup: "remove test destination folder" 63 | destinationFolder.deleteDir() 64 | } 65 | 66 | def "if the template cannot be processed an error should be printed"() { 67 | given: "an Endpoint with an unprocessable template in TypeScriptEndpoint-Annotation" 68 | def classFile = new File("$defaultPathBase/src/test/testcases/org/leandreck/endpoints/errtemplate/Endpoint.java") 69 | def folder = "/errtemplate" 70 | def destinationFolder = new File("$annotationsTarget/$folder") 71 | Files.createDirectories(destinationFolder.toPath()) 72 | 73 | when: "a simple Endpoint is compiled" 74 | List> diagnostics = 75 | CompilerTestHelper.compileTestCase(Arrays. asList(new TypeScriptEndpointProcessor()), folder, classFile) 76 | 77 | then: "there should be one error on line 26" 78 | diagnostics.size() == 1 79 | diagnostics.every { d -> (Diagnostic.Kind.ERROR == d.kind) } 80 | diagnostics.get(0).getLineNumber() == 26 81 | 82 | cleanup: "remove test destination folder" 83 | destinationFolder.deleteDir() 84 | } 85 | 86 | } 87 | -------------------------------------------------------------------------------- /annotations/src/test/groovy/org/leandreck/endpoints/processor/TypeScriptEndpointProcessorUnitSpec.groovy: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.leandreck.endpoints.processor 17 | 18 | import org.leandreck.endpoints.annotations.TypeScriptTemplatesConfiguration 19 | import org.leandreck.endpoints.processor.config.MultipleConfigurationsFoundException 20 | import org.leandreck.endpoints.processor.config.TemplateConfiguration 21 | import spock.lang.Narrative 22 | import spock.lang.Specification 23 | import spock.lang.Subject 24 | import spock.lang.Title 25 | 26 | import javax.annotation.processing.Messager 27 | import javax.annotation.processing.ProcessingEnvironment 28 | import javax.annotation.processing.RoundEnvironment 29 | import javax.lang.model.element.AnnotationMirror 30 | import javax.lang.model.element.Element 31 | import javax.tools.Diagnostic 32 | 33 | import static org.hamcrest.Matchers.any 34 | import static org.hamcrest.Matchers.containsInAnyOrder 35 | import static org.hamcrest.Matchers.equalTo 36 | import static spock.util.matcher.HamcrestSupport.that 37 | 38 | @Narrative('''Unit Test for TypeScriptEndpointProcessor checking correct behaviour of utility Methods.''') 39 | @Title("TypeScriptEndpointProcessor Unit Test") 40 | @Subject(TypeScriptEndpointProcessor) 41 | class TypeScriptEndpointProcessorUnitSpec extends Specification { 42 | 43 | def "printConfigurationErrors should print no ERROR when MultipleConfigurationsFoundException contains no Elements"() { 44 | given: "a TypeScriptEndpointProcessor and a MultipleConfigurationsFoundException containing no Elements annotated with @TypeScriptTemplatesConfiguration" 45 | 46 | ProcessingEnvironment environment = Stub ProcessingEnvironment 47 | Messager messager = Mock Messager 48 | environment.messager >> messager 49 | TypeScriptEndpointProcessor endpointProcessor = new TypeScriptEndpointProcessor() 50 | endpointProcessor.init(environment) 51 | 52 | MultipleConfigurationsFoundException mcfe = new MultipleConfigurationsFoundException(Collections.emptySet()) 53 | 54 | when: "printConfigurationErrors is called" 55 | endpointProcessor.printConfigurationErrors(mcfe) 56 | 57 | then: 58 | 0 * messager.printMessage(_, _,) 59 | 0 * messager.printMessage(_, _, _) 60 | 0 * messager.printMessage(_, _, _, _) 61 | 0 * messager.printMessage(_, _, _, _, _) 62 | } 63 | 64 | def "printConfigurationErrors should print one ERROR for every Configuration-Element in MultipleConfigurationsFoundException"() { 65 | given: "a TypeScriptEndpointProcessor and a MultipleConfigurationsFoundException containing three Elements annotated with @TypeScriptTemplatesConfiguration" 66 | 67 | ProcessingEnvironment environment = Stub ProcessingEnvironment 68 | Messager messager = Mock Messager 69 | environment.messager >> messager 70 | TypeScriptEndpointProcessor endpointProcessor = new TypeScriptEndpointProcessor() 71 | endpointProcessor.init(environment) 72 | 73 | def setOfElements = [createElement(), createElement(), createElement()] as Set 74 | 75 | MultipleConfigurationsFoundException mcfe = new MultipleConfigurationsFoundException(setOfElements) 76 | 77 | when: "printConfigurationErrors is called" 78 | endpointProcessor.printConfigurationErrors(mcfe) 79 | 80 | then: 81 | setOfElements.size() * messager.printMessage(Diagnostic.Kind.ERROR, _, _, _) 82 | } 83 | 84 | Element createElement() { 85 | TypeScriptTemplatesConfiguration annotation = Stub TypeScriptTemplatesConfiguration 86 | Element element = Stub Element 87 | element.getAnnotation(TypeScriptTemplatesConfiguration.class) >> annotation 88 | element.getAnnotationMirrors() >> Collections.singletonList(Stub(AnnotationMirror)) 89 | return element 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /annotations/src/test/groovy/org/leandreck/endpoints/processor/config/TemplateConfigurationUnitSpec.groovy: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.leandreck.endpoints.processor.config 17 | 18 | import org.leandreck.endpoints.annotations.TypeScriptTemplatesConfiguration 19 | import spock.lang.Narrative 20 | import spock.lang.Specification 21 | import spock.lang.Subject 22 | import spock.lang.Title 23 | 24 | import javax.annotation.processing.RoundEnvironment 25 | import javax.lang.model.element.Element 26 | 27 | import static org.hamcrest.Matchers.containsInAnyOrder 28 | import static spock.util.matcher.HamcrestSupport.that 29 | 30 | @Narrative('''Unit Test for TemplateConfiguration checking correct TemplateConfiguration creation and possible Exceptions. 31 | ''') 32 | @Title("TemplateConfiguration Unit Test") 33 | @Subject(TemplateConfiguration) 34 | class TemplateConfigurationUnitSpec extends Specification { 35 | 36 | def "If no @TypeScriptTemplatesConfiguration is found a TemplateConfiguration with defaults is created"() { 37 | given: "a RoundEnvironment containing no Elements annotated with @TypeScriptTemplatesConfiguration" 38 | RoundEnvironment environment = Stub RoundEnvironment 39 | environment.getElementsAnnotatedWith(TypeScriptTemplatesConfiguration.class) >> Collections.emptyList() 40 | 41 | when: 42 | TemplateConfiguration actual = TemplateConfiguration.buildFromEnvironment(environment) 43 | 44 | then: 45 | notThrown MultipleConfigurationsFoundException 46 | 47 | and: 48 | actual.apiModuleTemplate == TypeScriptTemplatesConfiguration.DEFAULT_API_MODULE 49 | actual.endpointTemplate == TypeScriptTemplatesConfiguration.DEFAULT_ENDPOINT 50 | actual.enumTemplate == TypeScriptTemplatesConfiguration.DEFAULT_ENUMERATION 51 | actual.indexTemplate == TypeScriptTemplatesConfiguration.DEFAULT_INDEX 52 | actual.interfaceTemplate == TypeScriptTemplatesConfiguration.DEFAULT_INTERFACE 53 | } 54 | 55 | def "If one @TypeScriptTemplatesConfiguration is found a TemplateConfiguration is created"() { 56 | given: "a RoundEnvironment containing one Element annotated with a customized @TypeScriptTemplatesConfiguration" 57 | TypeScriptTemplatesConfiguration configuration = Stub TypeScriptTemplatesConfiguration 58 | configuration.apimodule() >> "api" 59 | configuration.endpoint() >> "endoint" 60 | configuration.enumeration() >> "enumeration" 61 | configuration.index() >> "index" 62 | configuration.interfaces() >> "interfaces" 63 | 64 | Element element = Stub Element 65 | element.getAnnotation(TypeScriptTemplatesConfiguration.class) >> configuration 66 | 67 | RoundEnvironment environment = Stub RoundEnvironment 68 | environment.getElementsAnnotatedWith(TypeScriptTemplatesConfiguration.class) >> Collections.singletonList(element) 69 | 70 | when: 71 | TemplateConfiguration actual = TemplateConfiguration.buildFromEnvironment(environment) 72 | 73 | then: 74 | notThrown MultipleConfigurationsFoundException 75 | 76 | and: 77 | actual.apiModuleTemplate == configuration.apimodule() 78 | actual.endpointTemplate == configuration.endpoint() 79 | actual.enumTemplate == configuration.enumeration() 80 | actual.indexTemplate == configuration.index() 81 | actual.interfaceTemplate == configuration.interfaces() 82 | } 83 | 84 | def "If multiple @TypeScriptTemplatesConfiguration are found throw MultipleConfigurationsFoundException"() { 85 | given: "a RoundEnvironment containing two Elements annotated with @TypeScriptTemplatesConfiguration" 86 | 87 | Element element1 = Stub(Element) 88 | Element element2 = Stub(Element) 89 | 90 | RoundEnvironment environment = Stub RoundEnvironment 91 | environment.getElementsAnnotatedWith(TypeScriptTemplatesConfiguration.class) >> [ element1, element2 ] 92 | 93 | when: 94 | TemplateConfiguration.buildFromEnvironment(environment) 95 | 96 | then: 97 | MultipleConfigurationsFoundException mcfe = thrown() 98 | 99 | and: 100 | that mcfe.elementsWithConfiguration, containsInAnyOrder(element1, element2) 101 | } 102 | 103 | } 104 | -------------------------------------------------------------------------------- /annotations/src/test/groovy/org/leandreck/endpoints/processor/model/RequestMappingFactorySpec.groovy: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.leandreck.endpoints.processor.model 17 | 18 | import org.springframework.web.bind.annotation.GetMapping 19 | import org.springframework.web.bind.annotation.RequestMethod 20 | import spock.lang.* 21 | 22 | import java.lang.annotation.Annotation 23 | import java.lang.reflect.Method 24 | 25 | /** 26 | */ 27 | @Title("RequestMappingFactory Unittests") 28 | @Subject(RequestMappingFactory) 29 | class RequestMappingFactorySpec extends Specification { 30 | 31 | @Shared 32 | def factory = new RequestMappingFactory() 33 | 34 | @Unroll 35 | def "Populate with #annotation throwing different Exceptions"() { 36 | given: "empty Lists and an Annotation" 37 | def methodsList = [] 38 | def producesList = [] 39 | def valueList = [] 40 | 41 | when: "the populate method is called" 42 | factory.populate(methodsList, producesList, valueList, annotation, RequestMethod.GET) 43 | 44 | then: "and all lists except methodsList must still be empty" 45 | methodsList == [RequestMethod.GET] 46 | producesList == [] 47 | valueList == [] 48 | 49 | where: "possible annotations are" 50 | annotation << [ 51 | Stub(Annotation) { 52 | }, 53 | Stub(GetMapping) { 54 | produces() >> { throw new IOException() } 55 | } 56 | ] 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /annotations/src/test/groovy/org/leandreck/endpoints/processor/model/RequestMappingSpec.groovy: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.leandreck.endpoints.processor.model 17 | 18 | import org.springframework.web.bind.annotation.RequestMethod 19 | import spock.lang.Specification 20 | import spock.lang.Unroll 21 | 22 | /** 23 | */ 24 | class RequestMappingSpec extends Specification { 25 | 26 | @Unroll 27 | def "Method is always an Array #methods"() { 28 | given: "a RequestMapping" 29 | def methodsParam = methods == null ? null : methods.toArray(new RequestMethod[0]) 30 | def reqMapping = new RequestMapping(methodsParam, null, null) 31 | 32 | when: "method is called" 33 | def retVal = reqMapping.method() 34 | 35 | then: "retVal should be a Collection" 36 | retVal instanceof RequestMethod[] 37 | 38 | where: "possible values for methods are" 39 | methods << [[RequestMethod.GET], null] 40 | } 41 | 42 | @Unroll 43 | def "if a Method #methods is added it must be returned by RequestMapping"() { 44 | given: "a RequestMapping" 45 | def reqMapping = new RequestMapping(methods.toArray(new RequestMethod[0]), null, null) 46 | 47 | when: "method is called" 48 | def retVal = reqMapping.method() 49 | 50 | then: "retVal should be a Collection" 51 | retVal instanceof RequestMethod[] 52 | retVal == methods 53 | 54 | where: "possible values for methods are" 55 | methods << RequestMethod.values().collect { r -> [r]} 56 | } 57 | 58 | @Unroll 59 | def "Produces is always an Array #produces"() { 60 | given: "a RequestMapping" 61 | def producesParam = produces == null ? null : produces.toArray(new String[0]) 62 | def reqMapping = new RequestMapping(null, producesParam, null) 63 | 64 | when: "method is called" 65 | def retVal = reqMapping.produces() 66 | 67 | then: "retVal should be a Collection" 68 | retVal instanceof String[] 69 | 70 | where: "possible values for produces are" 71 | produces << [["some"], null] 72 | } 73 | 74 | @Unroll 75 | def "Value is always an Array #value"() { 76 | given: "a RequestMapping" 77 | def valueParam = value == null ? null : value.toArray(new String[0]) 78 | def reqMapping = new RequestMapping(null, null, valueParam) 79 | 80 | when: "method is called" 81 | def retVal = reqMapping.value() 82 | 83 | then: "retVal should be a Collection" 84 | retVal instanceof String[] 85 | 86 | where: "possible values for produces are" 87 | value << [["some"], null] 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /annotations/src/test/groovy/org/leandreck/endpoints/processor/model/typefactories/TypeNodeUtilsUnitSpec.groovy: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.leandreck.endpoints.processor.model.typefactories 17 | 18 | import org.leandreck.endpoints.annotations.TypeScriptType 19 | import org.leandreck.endpoints.processor.config.TemplateConfiguration 20 | import spock.lang.* 21 | 22 | import javax.lang.model.element.TypeElement 23 | 24 | @Title("RequestMappingFactory Unittests") 25 | @Subject(TypeNodeUtils) 26 | class TypeNodeUtilsUnitSpec extends Specification { 27 | 28 | @Unroll 29 | def "If template() is #templateValue and TypeNodeKind is #typeNodeKind it will returned #expectedTemplate"() { 30 | given: "an Element annotated with TypeScriptEndpoint" 31 | TypeElement typeElement = Stub TypeElement 32 | TypeScriptType typeScriptType = Stub TypeScriptType 33 | typeScriptType.template() >> templateValue 34 | 35 | when: 36 | def actual = TypeNodeUtils.defineTemplate(expectedTemplate, typeScriptType, typeElement) 37 | 38 | then: 39 | notThrown MissingConfigurationTemplateException 40 | 41 | and: 42 | actual == expectedTemplate 43 | 44 | where: "possible values are" 45 | templateValue | typeNodeKind || expectedTemplate 46 | "" | TypeNodeKind.SIMPLE || "interfaceTemplate" 47 | "" | TypeNodeKind.ARRAY || "interfaceTemplate" 48 | "" | TypeNodeKind.COLLECTION || "interfaceTemplate" 49 | "" | TypeNodeKind.MAP || "interfaceTemplate" 50 | "" | TypeNodeKind.ENUM || "enumTemplate" 51 | 52 | "some value" | TypeNodeKind.SIMPLE || "some value" 53 | "some value" | TypeNodeKind.ARRAY || "some value" 54 | "some value" | TypeNodeKind.COLLECTION || "some value" 55 | "some value" | TypeNodeKind.MAP || "some value" 56 | "some value" | TypeNodeKind.ENUM || "some value" 57 | } 58 | 59 | def "If templateConfiguration is null a MissingConfigurationTemplateException is thrown"() { 60 | given: "an Element annotated with TypeScriptEndpoint" 61 | TypeElement typeElement = Stub TypeElement 62 | 63 | when: 64 | def actual = TypeNodeUtils.defineTemplate(null, null, typeElement) 65 | 66 | then: 67 | MissingConfigurationTemplateException mcte = thrown() 68 | 69 | and: 70 | mcte.element == typeElement 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /annotations/src/test/java/org/leandreck/endpoints/processor/CompilerTestHelper.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.leandreck.endpoints.processor; 17 | 18 | import javax.annotation.processing.Processor; 19 | import javax.tools.*; 20 | import javax.tools.JavaCompiler.CompilationTask; 21 | import java.io.File; 22 | import java.io.IOException; 23 | import java.nio.charset.Charset; 24 | import java.util.Arrays; 25 | import java.util.Collections; 26 | import java.util.List; 27 | import java.util.Locale; 28 | 29 | /** 30 | */ 31 | class CompilerTestHelper { 32 | 33 | private static final JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); 34 | private static final Charset utf8 = Charset.forName("UTF-8"); 35 | 36 | public static List> compileTestCase(final Iterable processors, final String subfolder, File... compilationUnitFiles) throws IOException { 37 | 38 | final DiagnosticCollector diagnosticCollector = new DiagnosticCollector<>(); 39 | 40 | try ( 41 | final StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnosticCollector, Locale.GERMAN, utf8) 42 | ) { 43 | // If we don't specify the location of the new class files, they will be 44 | // placed at the project's root directory. 45 | fileManager.setLocation(StandardLocation.SOURCE_OUTPUT, Collections.singletonList(new File("target/generated-sources/annotations" + subfolder))); 46 | 47 | final Iterable compilationUnits = fileManager.getJavaFileObjectsFromFiles(Arrays.asList(compilationUnitFiles)); 48 | 49 | final CompilationTask task = compiler.getTask(null, fileManager, diagnosticCollector, Collections.singletonList("-proc:only"), null, compilationUnits); 50 | task.setProcessors(processors); 51 | task.call(); 52 | } 53 | 54 | return diagnosticCollector.getDiagnostics(); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /annotations/src/test/java/org/leandreck/endpoints/processor/CompleteRootType.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.leandreck.endpoints.processor; 17 | 18 | import java.math.BigDecimal; 19 | import java.math.BigInteger; 20 | 21 | public class CompleteRootType { 22 | 23 | private byte byteField; 24 | private Byte byteClassField; 25 | private short shortField; 26 | private Short shortClassField; 27 | private int intField; 28 | private Integer integerClassField; 29 | private long longField; 30 | private Long longClassField; 31 | private float floatField; 32 | private Float floatClassField; 33 | private double doubleField; 34 | private Double doubleClassField; 35 | private BigDecimal bigDecimalField; 36 | private BigInteger bigIntegerField; 37 | private char charField; 38 | private Character characterClassField; 39 | private String stringField; 40 | private boolean booleanField; 41 | private Boolean booleanClassField; 42 | 43 | public byte getByteField() { 44 | return byteField; 45 | } 46 | 47 | public void setByteField(byte byteField) { 48 | this.byteField = byteField; 49 | } 50 | 51 | public Byte getByteClassField() { 52 | return byteClassField; 53 | } 54 | 55 | public void setByteClassField(Byte byteClassField) { 56 | this.byteClassField = byteClassField; 57 | } 58 | 59 | public short getShortField() { 60 | return shortField; 61 | } 62 | 63 | public void setShortField(short shortField) { 64 | this.shortField = shortField; 65 | } 66 | 67 | public Short getShortClassField() { 68 | return shortClassField; 69 | } 70 | 71 | public void setShortClassField(Short shortClassField) { 72 | this.shortClassField = shortClassField; 73 | } 74 | 75 | public int getIntField() { 76 | return intField; 77 | } 78 | 79 | public void setIntField(int intField) { 80 | this.intField = intField; 81 | } 82 | 83 | public Integer getIntegerClassField() { 84 | return integerClassField; 85 | } 86 | 87 | public void setIntegerClassField(Integer integerClassField) { 88 | this.integerClassField = integerClassField; 89 | } 90 | 91 | public long getLongField() { 92 | return longField; 93 | } 94 | 95 | public void setLongField(long longField) { 96 | this.longField = longField; 97 | } 98 | 99 | public Long getLongClassField() { 100 | return longClassField; 101 | } 102 | 103 | public void setLongClassField(Long longClassField) { 104 | this.longClassField = longClassField; 105 | } 106 | 107 | public float getFloatField() { 108 | return floatField; 109 | } 110 | 111 | public void setFloatField(float floatField) { 112 | this.floatField = floatField; 113 | } 114 | 115 | public Float getFloatClassField() { 116 | return floatClassField; 117 | } 118 | 119 | public void setFloatClassField(Float floatClassField) { 120 | this.floatClassField = floatClassField; 121 | } 122 | 123 | public double getDoubleField() { 124 | return doubleField; 125 | } 126 | 127 | public void setDoubleField(double doubleField) { 128 | this.doubleField = doubleField; 129 | } 130 | 131 | public Double getDoubleClassField() { 132 | return doubleClassField; 133 | } 134 | 135 | public void setDoubleClassField(Double doubleClassField) { 136 | this.doubleClassField = doubleClassField; 137 | } 138 | 139 | public BigDecimal getBigDecimalField() { 140 | return bigDecimalField; 141 | } 142 | 143 | public void setBigDecimalField(BigDecimal bigDecimalField) { 144 | this.bigDecimalField = bigDecimalField; 145 | } 146 | 147 | public BigInteger getBigIntegerField() { 148 | return bigIntegerField; 149 | } 150 | 151 | public void setBigIntegerField(BigInteger bigIntegerField) { 152 | this.bigIntegerField = bigIntegerField; 153 | } 154 | 155 | public char getCharField() { 156 | return charField; 157 | } 158 | 159 | public void setCharField(char charField) { 160 | this.charField = charField; 161 | } 162 | 163 | public Character getCharacterClassField() { 164 | return characterClassField; 165 | } 166 | 167 | public void setCharacterClassField(Character characterClassField) { 168 | this.characterClassField = characterClassField; 169 | } 170 | 171 | public String getStringField() { 172 | return stringField; 173 | } 174 | 175 | public void setStringField(String stringField) { 176 | this.stringField = stringField; 177 | } 178 | 179 | public boolean isBooleanField() { 180 | return booleanField; 181 | } 182 | 183 | public void setBooleanField(boolean booleanField) { 184 | this.booleanField = booleanField; 185 | } 186 | 187 | public Boolean getBooleanClassField() { 188 | return booleanClassField; 189 | } 190 | 191 | public void setBooleanClassField(Boolean booleanClassField) { 192 | this.booleanClassField = booleanClassField; 193 | } 194 | 195 | } -------------------------------------------------------------------------------- /annotations/src/test/resources/org/leandreck/endpoints/templates/errtemplate/service.ftl: -------------------------------------------------------------------------------- 1 | <#-- 2 | 3 | Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | --> 18 | <#-- @ftlvariable name="" type="org.leandreck.endpoints.processor.model.EndpointNode" --> 19 | <#function map seq key> 20 | <#assign result = []> 21 | <#list seq as item> 22 | <#assign result = result + [item[key]]> 23 | 24 | <#return result> 25 | 26 | <#function flatten seq> 27 | <#assign result = []> 28 | <#list seq as innerSeq> 29 | <#list innerSeq as item> 30 | <#assign result = result + [item]> 31 | 32 | 33 | <#return result> 34 | 35 | { 36 | "serviceName": "${serviceName}", 37 | "serviceUrl": "${serviceURL}", 38 | "methodCount": ${methods?size}, 39 | "getMethodCount": ${getGetMethods()?size}, 40 | "headMethodCount": ${getHeadMethods()?size}, 41 | "postMethodCount": ${getPostMethods()?size}, 42 | "putMethodCount": ${getPutMethods()?size}, 43 | "patchMethodCount": ${getPatchMethods()?size}, 44 | "deleteMethodCount": ${getDeleteMethods()?size}, 45 | "optionsMethodCount": ${getOptionsMethods()?size}, 46 | "traceMethodCount": ${getTraceMethods()?size}, 47 | "methods": [ 48 | <#some Error> 49 | <#list methods as method> 50 | { 51 | "name": "${method.name}", 52 | "url": "${method.url}", 53 | "httpMethods": ["${method.httpMethods?join("\", \"")}"], 54 | "returnType": "${method.returnType.type}" 55 | }<#sep>, 56 | 57 | ], 58 | "getMethods": [ 59 | <#list getGetMethods() as method> 60 | { 61 | "name": "${method.name}", 62 | "url": "${method.url}", 63 | "httpMethods": ["${method.httpMethods?join("\", \"")}"], 64 | "returnType": "${method.returnType.type}" 65 | }<#sep>, 66 | 67 | ], 68 | "headMethods": [ 69 | <#list getHeadMethods() as method> 70 | { 71 | "name": "${method.name}", 72 | "url": "${method.url}", 73 | "httpMethods": ["${method.httpMethods?join("\", \"")}"], 74 | "returnType": "${method.returnType.type}" 75 | }<#sep>, 76 | 77 | ], 78 | "postMethods": [ 79 | <#list getPostMethods() as method> 80 | { 81 | "name": "${method.name}", 82 | "url": "${method.url}", 83 | "httpMethods": ["${method.httpMethods?join("\", \"")}"], 84 | "returnType": "${method.returnType.type}" 85 | }<#sep>, 86 | 87 | ], 88 | "putMethods": [ 89 | <#list getPutMethods() as method> 90 | { 91 | "name": "${method.name}", 92 | "url": "${method.url}", 93 | "httpMethods": ["${method.httpMethods?join("\", \"")}"], 94 | "returnType": "${method.returnType.type}" 95 | }<#sep>, 96 | 97 | ], 98 | "patchMethods": [ 99 | <#list getPatchMethods() as method> 100 | { 101 | "name": "${method.name}", 102 | "url": "${method.url}", 103 | "httpMethods": ["${method.httpMethods?join("\", \"")}"], 104 | "returnType": "${method.returnType.type}" 105 | }<#sep>, 106 | 107 | ], 108 | "deleteMethods": [ 109 | <#list getDeleteMethods() as method> 110 | { 111 | "name": "${method.name}", 112 | "url": "${method.url}", 113 | "httpMethods": ["${method.httpMethods?join("\", \"")}"], 114 | "returnType": "${method.returnType.type}" 115 | }<#sep>, 116 | 117 | ], 118 | "optionsMethods": [ 119 | <#list getOptionsMethods() as method> 120 | { 121 | "name": "${method.name}", 122 | "url": "${method.url}", 123 | "httpMethods": ["${method.httpMethods?join("\", \"")}"], 124 | "returnType": "${method.returnType.type}" 125 | }<#sep>, 126 | 127 | ], 128 | "traceMethods": [ 129 | <#list getTraceMethods() as method> 130 | { 131 | "name": "${method.name}", 132 | "url": "${method.url}", 133 | "httpMethods": ["${method.httpMethods?join("\", \"")}"], 134 | "returnType": "${method.returnType.type}" 135 | }<#sep>, 136 | 137 | ] 138 | } 139 | 140 | <#--methodNames=${map(methods, "name")?join(", ")}--> 141 | <#--httpMethods=${flatten(map(methods, "httpMethods"))?join(", ")}--> 142 | <#--methodUrls=${map(methods, "url")?join(", ")}--> -------------------------------------------------------------------------------- /annotations/src/test/resources/org/leandreck/endpoints/templates/testing/enum.ftl: -------------------------------------------------------------------------------- 1 | <#-- 2 | 3 | Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | --> 18 | <#-- @ftlvariable name="" type="org.leandreck.endpoints.processor.model.TypeNode" --> 19 | { 20 | "typeName": "${typeName}", 21 | "children": [ 22 | <#list children as property> 23 | { 24 | "fieldName": "${property.fieldName}", 25 | "typeName": "${property.typeName}", 26 | "type": "${property.type}", 27 | }<#sep>, 28 | 29 | ], 30 | "values": [ 31 | <#list enumValues as value> 32 | { 33 | "value": "${value.name}" 34 | }<#sep>, 35 | 36 | ] 37 | } -------------------------------------------------------------------------------- /annotations/src/test/resources/org/leandreck/endpoints/templates/testing/interface.ftl: -------------------------------------------------------------------------------- 1 | <#-- 2 | 3 | Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | 17 | --> 18 | <#-- @ftlvariable name="" type="org.leandreck.endpoints.processor.model.TypeNode" --> 19 | { 20 | "typeName": "${typeName}", 21 | "children": [ 22 | <#list children as property> 23 | { 24 | "fieldName": "${property.fieldName}", 25 | "typeName": "${property.typeName}", 26 | "type": "${property.type}", 27 | "typeNameVariable": "${property.typeNameVariable}", 28 | "variableType": "${property.variableType}", 29 | "asFunctionParameter": "${property.asFunctionParameter}", 30 | "asVariableName": "${property.asVariableName}", 31 | "parameterName": "${property.parameterName!}", 32 | "declaredComplexType": ${property.declaredComplexType?c}, 33 | "mappedType": ${property.mappedType?c}, 34 | "optional": ${property.optional?c} 35 | <#--"imports": "${property.imports}",--> 36 | }<#sep>, 37 | 38 | ], 39 | "values": [ 40 | <#list enumValues as value> 41 | { 42 | "value": "${value.name}" 43 | }<#sep>, 44 | 45 | ] 46 | } -------------------------------------------------------------------------------- /annotations/src/test/testcases/org/leandreck/endpoints/case1/Endpoint.gstring: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.leandreck.endpoints.case1; 17 | 18 | import org.leandreck.endpoints.annotations.TypeScriptEndpoint; 19 | import org.springframework.http.MediaType; 20 | import org.springframework.web.bind.annotation.RequestMapping; 21 | import org.springframework.web.bind.annotation.ResponseBody; 22 | import org.springframework.web.bind.annotation.RestController; 23 | 24 | import static org.springframework.web.bind.annotation.RequestMethod.GET; 25 | 26 | @TypeScriptEndpoint(template = "/org/leandreck/endpoints/templates/testing/service.ftl") 27 | @RestController 28 | @RequestMapping("/api") 29 | public class Endpoint { 30 | 31 | @RequestMapping(value = "/int", method = GET, produces = MediaType.APPLICATION_JSON_VALUE) 32 | public @ResponseBody $returnType getInt() { 33 | $returnValue; 34 | } 35 | } -------------------------------------------------------------------------------- /annotations/src/test/testcases/org/leandreck/endpoints/complex/Endpoint.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.leandreck.endpoints.complex; 17 | 18 | import org.leandreck.endpoints.annotations.TypeScriptEndpoint; 19 | import org.leandreck.endpoints.annotations.TypeScriptType; 20 | import org.springframework.http.MediaType; 21 | import org.springframework.web.bind.annotation.RequestMapping; 22 | import org.springframework.web.bind.annotation.RestController; 23 | 24 | import static org.springframework.web.bind.annotation.RequestMethod.GET; 25 | 26 | @TypeScriptEndpoint(template = "/org/leandreck/endpoints/templates/testing/service.ftl") 27 | @RestController 28 | @RequestMapping("/api") 29 | public class Endpoint { 30 | 31 | @RequestMapping(value = "/SimpleRootType", method = GET, produces = MediaType.APPLICATION_JSON_VALUE) 32 | public SimpleRootType getSimpleRootType() { 33 | return new SimpleRootType(); 34 | } 35 | } -------------------------------------------------------------------------------- /annotations/src/test/testcases/org/leandreck/endpoints/complex/SimpleRootType.gstring: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.leandreck.endpoints.complex; 17 | 18 | import org.leandreck.endpoints.annotations.TypeScriptType; 19 | 20 | @TypeScriptType(template = "/org/leandreck/endpoints/templates/testing/interface.ftl") 21 | public class SimpleRootType { 22 | 23 | private $type field; 24 | 25 | public $type getField() { 26 | return field; 27 | } 28 | 29 | public void setField($type field) { 30 | this.field = field; 31 | } 32 | } -------------------------------------------------------------------------------- /annotations/src/test/testcases/org/leandreck/endpoints/composed/Endpoint.gstring: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.leandreck.endpoints.composed; 17 | 18 | import org.leandreck.endpoints.annotations.TypeScriptEndpoint; 19 | import org.springframework.http.MediaType; 20 | import org.springframework.web.bind.annotation.*; 21 | 22 | import java.math.BigDecimal; 23 | import java.util.List; 24 | 25 | @TypeScriptEndpoint(template = "/org/leandreck/endpoints/templates/testing/service.ftl") 26 | @RestController 27 | @RequestMapping("/api/method") 28 | public class Endpoint { 29 | 30 | $annotation(produces = MediaType.APPLICATION_JSON_UTF8_VALUE) 31 | public List getInt() { 32 | return Collections.emptyList(); 33 | } 34 | } -------------------------------------------------------------------------------- /annotations/src/test/testcases/org/leandreck/endpoints/enums/DeclaredEnum.gstring: -------------------------------------------------------------------------------- 1 | package org.leandreck.endpoints.enums; 2 | 3 | import org.leandreck.endpoints.annotations.TypeScriptType; 4 | 5 | /** 6 | * Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | @TypeScriptType(template = "/org/leandreck/endpoints/templates/testing/enum.ftl") 21 | public enum DeclaredEnum { 22 | $values 23 | } -------------------------------------------------------------------------------- /annotations/src/test/testcases/org/leandreck/endpoints/enums/Endpoint.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.leandreck.endpoints.enums; 17 | 18 | import org.leandreck.endpoints.annotations.TypeScriptEndpoint; 19 | import org.leandreck.endpoints.annotations.TypeScriptType; 20 | import org.springframework.http.MediaType; 21 | import org.springframework.web.bind.annotation.RequestMapping; 22 | import org.springframework.web.bind.annotation.RestController; 23 | 24 | import static org.springframework.web.bind.annotation.RequestMethod.GET; 25 | 26 | @TypeScriptEndpoint(template = "/org/leandreck/endpoints/templates/testing/service.ftl") 27 | @RestController 28 | @RequestMapping("/api") 29 | public class Endpoint { 30 | 31 | @RequestMapping(value = "/SimpleRootType", method = GET, produces = MediaType.APPLICATION_JSON_VALUE) 32 | public SimpleRootType getSimpleRootType() { 33 | return new SimpleRootType(); 34 | } 35 | } -------------------------------------------------------------------------------- /annotations/src/test/testcases/org/leandreck/endpoints/enums/SimpleRootType.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.leandreck.endpoints.enums; 17 | 18 | import org.leandreck.endpoints.annotations.TypeScriptType; 19 | 20 | @TypeScriptType(template = "/org/leandreck/endpoints/templates/testing/interface.ftl") 21 | public class SimpleRootType { 22 | 23 | private DeclaredEnum field; 24 | 25 | public DeclaredEnum getField() { 26 | return field; 27 | } 28 | 29 | public void setField(DeclaredEnum field) { 30 | this.field = field; 31 | } 32 | } -------------------------------------------------------------------------------- /annotations/src/test/testcases/org/leandreck/endpoints/epname/Endpoint.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.leandreck.endpoints.epname; 17 | 18 | import org.leandreck.endpoints.annotations.TypeScriptEndpoint; 19 | import org.springframework.http.MediaType; 20 | import org.springframework.web.bind.annotation.RequestMapping; 21 | import org.springframework.web.bind.annotation.RestController; 22 | 23 | import static org.springframework.web.bind.annotation.RequestMethod.GET; 24 | 25 | @TypeScriptEndpoint(template = "/org/leandreck/endpoints/templates/testing/service.ftl", value = "CustomName") 26 | @RestController 27 | public class Endpoint { 28 | 29 | @RequestMapping(value = "/int", method = GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) 30 | public String getInt() { 31 | return "Some"; 32 | } 33 | } -------------------------------------------------------------------------------- /annotations/src/test/testcases/org/leandreck/endpoints/errtemplate/Endpoint.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.leandreck.endpoints.errtemplate; 17 | 18 | import org.leandreck.endpoints.annotations.TypeScriptEndpoint; 19 | import org.springframework.http.MediaType; 20 | import org.springframework.web.bind.annotation.RequestMapping; 21 | import org.springframework.web.bind.annotation.ResponseBody; 22 | import org.springframework.web.bind.annotation.RestController; 23 | 24 | import static org.springframework.web.bind.annotation.RequestMethod.GET; 25 | 26 | @TypeScriptEndpoint(template = "/org/leandreck/endpoints/templates/errtemplate/service.ftl") 27 | @RestController 28 | @RequestMapping("/api") 29 | public class Endpoint { 30 | 31 | @RequestMapping(value = "/int", method = GET, produces = MediaType.APPLICATION_JSON_VALUE) 32 | public @ResponseBody int getInt() { 33 | return 1; 34 | } 35 | } -------------------------------------------------------------------------------- /annotations/src/test/testcases/org/leandreck/endpoints/generics/Endpoint.gstring: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.leandreck.endpoints.generics; 17 | 18 | import org.leandreck.endpoints.annotations.TypeScriptEndpoint; 19 | import org.springframework.http.MediaType; 20 | import org.springframework.web.bind.annotation.RequestMapping; 21 | import org.springframework.web.bind.annotation.RequestParam; 22 | import org.springframework.web.bind.annotation.RestController; 23 | 24 | import static org.springframework.web.bind.annotation.RequestMethod.GET; 25 | 26 | @TypeScriptEndpoint(template = "/org/leandreck/endpoints/templates/testing/service.ftl") 27 | @RestController 28 | @RequestMapping("/api") 29 | public class Endpoint { 30 | 31 | @RequestMapping(value = "/boundType/{value}", method = GET, produces = MediaType.APPLICATION_JSON_VALUE) 32 | public $boundType echoBoundType(@RequestParam $boundType value) { 33 | return value; 34 | } 35 | } -------------------------------------------------------------------------------- /annotations/src/test/testcases/org/leandreck/endpoints/generics/SimpleRootType.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.leandreck.endpoints.generics; 17 | 18 | import org.leandreck.endpoints.annotations.TypeScriptType; 19 | 20 | @TypeScriptType(template = "/org/leandreck/endpoints/templates/testing/interface.ftl") 21 | public class SimpleRootType { 22 | 23 | private T field; 24 | 25 | public T getField() { 26 | return field; 27 | } 28 | 29 | public void setField(T field) { 30 | this.field = field; 31 | } 32 | } -------------------------------------------------------------------------------- /annotations/src/test/testcases/org/leandreck/endpoints/httpmethods/Endpoint.gstring: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.leandreck.endpoints.httpmethods; 18 | 19 | import org.leandreck.endpoints.annotations.TypeScriptEndpoint; 20 | import org.springframework.http.MediaType; 21 | import org.springframework.web.bind.annotation.RequestMapping; 22 | import org.springframework.web.bind.annotation.RestController; 23 | 24 | import static org.springframework.web.bind.annotation.RequestMethod.*; 25 | 26 | @TypeScriptEndpoint(template = "/org/leandreck/endpoints/templates/testing/service.ftl") 27 | @RestController 28 | @RequestMapping("/api") 29 | public class $httpMethod { 30 | 31 | @RequestMapping(value = "/int", $sourceMethod produces = MediaType.APPLICATION_JSON_VALUE) 32 | public void getInt() { 33 | } 34 | } -------------------------------------------------------------------------------- /annotations/src/test/testcases/org/leandreck/endpoints/ignored/Annotated.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.leandreck.endpoints.case1; 17 | 18 | import org.leandreck.endpoints.annotations.TypeScriptEndpoint; 19 | import org.leandreck.endpoints.annotations.TypeScriptIgnore; 20 | import org.springframework.http.MediaType; 21 | import org.springframework.web.bind.annotation.RequestMapping; 22 | import org.springframework.web.bind.annotation.ResponseBody; 23 | import org.springframework.web.bind.annotation.RestController; 24 | 25 | import static org.springframework.web.bind.annotation.RequestMethod.GET; 26 | 27 | @TypeScriptEndpoint(template = "/org/leandreck/endpoints/templates/testing/service.ftl") 28 | @RestController 29 | @RequestMapping("/api") 30 | public class Annotated { 31 | 32 | @TypeScriptIgnore 33 | @RequestMapping(value = "/int", method = GET, produces = MediaType.APPLICATION_JSON_VALUE) 34 | public @ResponseBody int getInt() { 35 | return 1; 36 | } 37 | } -------------------------------------------------------------------------------- /annotations/src/test/testcases/org/leandreck/endpoints/ignored/NoJson.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.leandreck.endpoints.case1; 17 | 18 | import org.leandreck.endpoints.annotations.TypeScriptEndpoint; 19 | import org.leandreck.endpoints.annotations.TypeScriptIgnore; 20 | import org.springframework.http.MediaType; 21 | import org.springframework.web.bind.annotation.RequestMapping; 22 | import org.springframework.web.bind.annotation.ResponseBody; 23 | import org.springframework.web.bind.annotation.RestController; 24 | 25 | import static org.springframework.web.bind.annotation.RequestMethod.GET; 26 | 27 | @TypeScriptEndpoint(template = "/org/leandreck/endpoints/templates/testing/service.ftl") 28 | @RestController 29 | @RequestMapping("/api") 30 | public class NoJson { 31 | 32 | @RequestMapping(value = "/int", method = GET, produces = MediaType.IMAGE_PNG_VALUE) 33 | public @ResponseBody int getInt() { 34 | return 1; 35 | } 36 | } -------------------------------------------------------------------------------- /annotations/src/test/testcases/org/leandreck/endpoints/ignored/NoJsonMultiple.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.leandreck.endpoints.case1; 17 | 18 | import org.leandreck.endpoints.annotations.TypeScriptEndpoint; 19 | import org.leandreck.endpoints.annotations.TypeScriptIgnore; 20 | import org.springframework.http.MediaType; 21 | import org.springframework.web.bind.annotation.RequestMapping; 22 | import org.springframework.web.bind.annotation.ResponseBody; 23 | import org.springframework.web.bind.annotation.RestController; 24 | 25 | import static org.springframework.web.bind.annotation.RequestMethod.GET; 26 | 27 | @TypeScriptEndpoint(template = "/org/leandreck/endpoints/templates/testing/service.ftl") 28 | @RestController 29 | @RequestMapping("/api") 30 | public class NoJsonMultiple { 31 | 32 | @RequestMapping(value = "/int", method = GET, 33 | produces = { MediaType.IMAGE_PNG_VALUE, 34 | MediaType.APPLICATION_ATOM_XML_VALUE, 35 | MediaType.APPLICATION_OCTET_STREAM_VALUE }) 36 | public @ResponseBody int getInt() { 37 | return 1; 38 | } 39 | } -------------------------------------------------------------------------------- /annotations/src/test/testcases/org/leandreck/endpoints/ignored/NoMapping.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.leandreck.endpoints.case1; 17 | 18 | import org.leandreck.endpoints.annotations.TypeScriptEndpoint; 19 | import org.leandreck.endpoints.annotations.TypeScriptIgnore; 20 | import org.springframework.http.MediaType; 21 | import org.springframework.web.bind.annotation.RequestMapping; 22 | import org.springframework.web.bind.annotation.ResponseBody; 23 | import org.springframework.web.bind.annotation.RestController; 24 | 25 | import static org.springframework.web.bind.annotation.RequestMethod.GET; 26 | 27 | @TypeScriptEndpoint(template = "/org/leandreck/endpoints/templates/testing/service.ftl") 28 | @RestController 29 | @RequestMapping("/api") 30 | public class NoMapping { 31 | 32 | public @ResponseBody int getInt() { 33 | return 1; 34 | } 35 | } -------------------------------------------------------------------------------- /annotations/src/test/testcases/org/leandreck/endpoints/ignored/PackageMethod.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.leandreck.endpoints.case1; 17 | 18 | import org.leandreck.endpoints.annotations.TypeScriptEndpoint; 19 | import org.leandreck.endpoints.annotations.TypeScriptIgnore; 20 | import org.springframework.http.MediaType; 21 | import org.springframework.web.bind.annotation.RequestMapping; 22 | import org.springframework.web.bind.annotation.ResponseBody; 23 | import org.springframework.web.bind.annotation.RestController; 24 | 25 | import static org.springframework.web.bind.annotation.RequestMethod.GET; 26 | 27 | @TypeScriptEndpoint(template = "/org/leandreck/endpoints/templates/testing/service.ftl") 28 | @RestController 29 | @RequestMapping("/api") 30 | public class PackageMethod { 31 | 32 | @RequestMapping(value = "/int", method = GET, produces = MediaType.APPLICATION_JSON_VALUE) 33 | @ResponseBody int getInt() { 34 | return 1; 35 | } 36 | } -------------------------------------------------------------------------------- /annotations/src/test/testcases/org/leandreck/endpoints/ignored/PrivateMethod.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.leandreck.endpoints.case1; 17 | 18 | import org.leandreck.endpoints.annotations.TypeScriptEndpoint; 19 | import org.leandreck.endpoints.annotations.TypeScriptIgnore; 20 | import org.springframework.http.MediaType; 21 | import org.springframework.web.bind.annotation.RequestMapping; 22 | import org.springframework.web.bind.annotation.ResponseBody; 23 | import org.springframework.web.bind.annotation.RestController; 24 | 25 | import static org.springframework.web.bind.annotation.RequestMethod.GET; 26 | 27 | @TypeScriptEndpoint(template = "/org/leandreck/endpoints/templates/testing/service.ftl") 28 | @RestController 29 | @RequestMapping("/api") 30 | public class PrivateMethod { 31 | 32 | @RequestMapping(value = "/int", method = GET, produces = MediaType.APPLICATION_JSON_VALUE) 33 | private @ResponseBody int getInt() { 34 | return 1; 35 | } 36 | } -------------------------------------------------------------------------------- /annotations/src/test/testcases/org/leandreck/endpoints/ignored/ProtectedMethod.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.leandreck.endpoints.case1; 17 | 18 | import org.leandreck.endpoints.annotations.TypeScriptEndpoint; 19 | import org.leandreck.endpoints.annotations.TypeScriptIgnore; 20 | import org.springframework.http.MediaType; 21 | import org.springframework.web.bind.annotation.RequestMapping; 22 | import org.springframework.web.bind.annotation.ResponseBody; 23 | import org.springframework.web.bind.annotation.RestController; 24 | 25 | import static org.springframework.web.bind.annotation.RequestMethod.GET; 26 | 27 | @TypeScriptEndpoint(template = "/org/leandreck/endpoints/templates/testing/service.ftl") 28 | @RestController 29 | @RequestMapping("/api") 30 | public class ProtectedMethod { 31 | 32 | @RequestMapping(value = "/int", method = GET, produces = MediaType.APPLICATION_JSON_VALUE) 33 | protected @ResponseBody int getInt() { 34 | return 1; 35 | } 36 | } -------------------------------------------------------------------------------- /annotations/src/test/testcases/org/leandreck/endpoints/interfaces/Endpoint.gstring: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.leandreck.endpoints.interfaces; 17 | 18 | import org.leandreck.endpoints.annotations.TypeScriptEndpoint; 19 | import org.springframework.http.MediaType; 20 | import org.springframework.web.bind.annotation.RequestMapping; 21 | import org.springframework.web.bind.annotation.RequestParam; 22 | import org.springframework.web.bind.annotation.RestController; 23 | 24 | import static org.springframework.web.bind.annotation.RequestMethod.GET; 25 | 26 | @TypeScriptEndpoint(template = "/org/leandreck/endpoints/templates/testing/service.ftl") 27 | @RestController 28 | @RequestMapping("/interfaces") 29 | public interface Endpoint { 30 | 31 | @RequestMapping(value = "/interfaces/{position}", method = GET, produces = MediaType.APPLICATION_JSON_VALUE) 32 | public Integer getInterfaceNumber(@RequestParam(name = "position") String position); 33 | } -------------------------------------------------------------------------------- /annotations/src/test/testcases/org/leandreck/endpoints/lombok/DataType.gstring: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.leandreck.endpoints.lombok; 17 | 18 | import org.leandreck.endpoints.annotations.TypeScriptType; 19 | import lombok.Data; 20 | 21 | @Data 22 | @TypeScriptType(template = "/org/leandreck/endpoints/templates/testing/interface.ftl") 23 | public class DataType { 24 | private $type dataField; 25 | } -------------------------------------------------------------------------------- /annotations/src/test/testcases/org/leandreck/endpoints/lombok/Endpoint.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.leandreck.endpoints.lombok; 17 | 18 | import org.leandreck.endpoints.annotations.TypeScriptEndpoint; 19 | import org.springframework.http.MediaType; 20 | import org.springframework.web.bind.annotation.RequestBody; 21 | import org.springframework.web.bind.annotation.RequestMapping; 22 | import org.springframework.web.bind.annotation.RestController; 23 | 24 | import static org.springframework.web.bind.annotation.RequestMethod.GET; 25 | 26 | @TypeScriptEndpoint(template = "/org/leandreck/endpoints/templates/testing/service.ftl") 27 | @RestController 28 | @RequestMapping("/api") 29 | public class Endpoint { 30 | 31 | @RequestMapping(value = "/SimpleRootType", method = GET, produces = MediaType.APPLICATION_JSON_VALUE) 32 | public DataType getSimpleRootType(@RequestBody ValueType valueTypeParam) { 33 | return new DataType(); 34 | } 35 | } -------------------------------------------------------------------------------- /annotations/src/test/testcases/org/leandreck/endpoints/lombok/ValueType.gstring: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.leandreck.endpoints.lombok; 17 | 18 | import org.leandreck.endpoints.annotations.TypeScriptType; 19 | import lombok.Value; 20 | 21 | @Value 22 | @TypeScriptType(template = "/org/leandreck/endpoints/templates/testing/interface.ftl") 23 | public class ValueType { 24 | private $type valueField; 25 | } -------------------------------------------------------------------------------- /annotations/src/test/testcases/org/leandreck/endpoints/notemplate/Endpoint.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.leandreck.endpoints.notemplate; 17 | 18 | import org.leandreck.endpoints.annotations.TypeScriptEndpoint; 19 | import org.springframework.http.MediaType; 20 | import org.springframework.web.bind.annotation.RequestMapping; 21 | import org.springframework.web.bind.annotation.ResponseBody; 22 | import org.springframework.web.bind.annotation.RestController; 23 | 24 | import static org.springframework.web.bind.annotation.RequestMethod.GET; 25 | 26 | @TypeScriptEndpoint(template = "/some/bogus/value/where/no/template/is/service.ftl") 27 | @RestController 28 | @RequestMapping("/api") 29 | public class Endpoint { 30 | 31 | @RequestMapping(value = "/int", method = GET, produces = MediaType.APPLICATION_JSON_VALUE) 32 | public @ResponseBody int getInt() { 33 | return 1; 34 | } 35 | } -------------------------------------------------------------------------------- /annotations/src/test/testcases/org/leandreck/endpoints/pathvariable/Endpoint.gstring: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.leandreck.endpoints.pathvariable; 18 | 19 | import static org.springframework.web.bind.annotation.RequestMethod.*; 20 | 21 | import org.leandreck.endpoints.annotations.TypeScriptEndpoint; 22 | import org.springframework.http.MediaType; 23 | import org.springframework.web.bind.annotation.PathVariable; 24 | import org.springframework.web.bind.annotation.RequestMapping; 25 | import org.springframework.web.bind.annotation.RestController; 26 | 27 | @TypeScriptEndpoint(template = "/org/leandreck/endpoints/templates/testing/service.ftl") 28 | @RestController 29 | @RequestMapping("/api") 30 | public class $httpMethod { 31 | 32 | @RequestMapping(value = "/{value}", method = $httpMethod, produces = MediaType.APPLICATION_JSON_VALUE) 33 | public $type getInt(@PathVariable $type value) { 34 | return value; 35 | } 36 | } -------------------------------------------------------------------------------- /annotations/src/test/testcases/org/leandreck/endpoints/returnref/Endpoint.gstring: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.leandreck.endpoints.returnref; 17 | 18 | import org.leandreck.endpoints.annotations.TypeScriptEndpoint; 19 | import org.springframework.http.MediaType; 20 | import org.springframework.web.bind.annotation.RequestMapping; 21 | import org.springframework.web.bind.annotation.RestController; 22 | 23 | import static org.springframework.web.bind.annotation.RequestMethod.GET; 24 | 25 | @TypeScriptEndpoint(template = "/org/leandreck/endpoints/templates/testing/service.ftl") 26 | @RestController 27 | @RequestMapping("/api") 28 | public class Endpoint { 29 | 30 | @RequestMapping(value = "/int", method = GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) 31 | public $returnType getInt() { 32 | $returnValue; 33 | } 34 | } -------------------------------------------------------------------------------- /annotations/src/test/testcases/org/leandreck/endpoints/returnref/SimpleRootType.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.leandreck.endpoints.returnref; 17 | 18 | import org.leandreck.endpoints.annotations.TypeScriptType; 19 | 20 | @TypeScriptType(template = "/org/leandreck/endpoints/templates/testing/interface.ftl") 21 | public class SimpleRootType { 22 | 23 | private String field1; 24 | private String field2; 25 | 26 | public String getField1() { 27 | return field1; 28 | } 29 | 30 | public void setField1(final String field1) { 31 | this.field1 = field1; 32 | } 33 | 34 | public String getField2() { 35 | return field2; 36 | } 37 | 38 | public void setField2(final String field2) { 39 | this.field2 = field2; 40 | } 41 | } -------------------------------------------------------------------------------- /annotations/src/test/testcases/org/leandreck/endpoints/returnvoid/Endpoint.gstring: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.leandreck.endpoints.returnvoid; 17 | 18 | import org.leandreck.endpoints.annotations.TypeScriptEndpoint; 19 | import org.springframework.http.MediaType; 20 | import org.springframework.web.bind.annotation.RequestBody; 21 | import org.springframework.web.bind.annotation.RequestMapping; 22 | import org.springframework.web.bind.annotation.RestController; 23 | 24 | import static org.springframework.web.bind.annotation.RequestMethod.GET; 25 | 26 | @TypeScriptEndpoint(template = "/org/leandreck/endpoints/templates/testing/service.ftl") 27 | @RestController 28 | @RequestMapping("/api/method") 29 | public class Endpoint { 30 | 31 | @RequestMapping(value = "", method = GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) 32 | public void getInt(@RequestBody $paramType onlyParam) { 33 | //intentionally left blank 34 | } 35 | } -------------------------------------------------------------------------------- /annotations/src/test/testcases/org/leandreck/endpoints/returnvoid/SimpleRootType.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.leandreck.endpoints.returnvoid; 17 | 18 | import org.leandreck.endpoints.annotations.TypeScriptType; 19 | 20 | import java.math.BigDecimal; 21 | import java.util.List; 22 | 23 | @TypeScriptType(template = "/org/leandreck/endpoints/templates/testing/interface.ftl") 24 | public class SimpleRootType { 25 | 26 | private BigDecimal field1; 27 | private List field2; 28 | 29 | public String getField1() { 30 | return field1; 31 | } 32 | 33 | public void setField1(final String field1) { 34 | this.field1 = field1; 35 | } 36 | 37 | public List getField2() { 38 | return field2; 39 | } 40 | 41 | public void setField2(List field2) { 42 | this.field2 = field2; 43 | } 44 | } -------------------------------------------------------------------------------- /examples/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 22 | 4.0.0 23 | 24 | 25 | org.leandreck.endpoints 26 | parent 27 | 0.5.0-SNAPSHOT 28 | ../ 29 | 30 | 31 | examples 32 | 33 | 34 | true 35 | 36 | 37 | 38 | 39 | org.leandreck.endpoints 40 | annotations 41 | provided 42 | true 43 | 44 | 45 | 46 | org.springframework 47 | spring-web 48 | 49 | 50 | org.springframework 51 | spring-context 52 | 53 | 54 | org.springframework 55 | spring-aop 56 | 57 | 58 | org.springframework 59 | spring-beans 60 | 61 | 62 | commons-logging 63 | commons-logging 64 | 65 | 66 | 67 | 68 | org.projectlombok 69 | lombok 70 | 71 | 72 | javax.servlet 73 | servlet-api 74 | 75 | 76 | javax.ws.rs 77 | javax.ws.rs-api 78 | 79 | 80 | javax.validation 81 | validation-api 82 | 2.0.1.Final 83 | 84 | 85 | 86 | -------------------------------------------------------------------------------- /examples/src/main/java/org/leandreck/endpoints/examples/MapKeyType.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.leandreck.endpoints.examples; 17 | 18 | /** 19 | */ 20 | public class MapKeyType { 21 | 22 | private String bar; 23 | 24 | public String getBar() { 25 | return bar; 26 | } 27 | 28 | public void setBar(String bar) { 29 | this.bar = bar; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /examples/src/main/java/org/leandreck/endpoints/examples/MapValueType.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.leandreck.endpoints.examples; 17 | 18 | /** 19 | */ 20 | public class MapValueType { 21 | 22 | private String foo; 23 | 24 | public String getFoo() { 25 | return foo; 26 | } 27 | 28 | public void setFoo(String foo) { 29 | this.foo = foo; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /examples/src/main/java/org/leandreck/endpoints/examples/RootType.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.leandreck.endpoints.examples; 17 | 18 | import org.leandreck.endpoints.annotations.TypeScriptIgnore; 19 | import org.leandreck.endpoints.annotations.TypeScriptType; 20 | 21 | import java.math.BigDecimal; 22 | import java.util.List; 23 | import java.util.Map; 24 | 25 | /** 26 | */ 27 | @TypeScriptType("MyTypeScriptType") 28 | public class RootType { 29 | 30 | private Long id; 31 | 32 | private String name; 33 | private String givenName; 34 | private int weight; 35 | 36 | private SimpleEnum[] simpleArray; 37 | 38 | @TypeScriptIgnore 39 | private BigDecimal ignoredField; 40 | 41 | private transient String transientField; 42 | 43 | private char noPublicGetter; 44 | 45 | private List subTypeList; 46 | 47 | private Map subTypeMap; 48 | 49 | private Map mapValue; 50 | private Map mapKey; 51 | 52 | public RootType() { 53 | this.id = Long.MIN_VALUE; 54 | } 55 | 56 | public RootType(final Long id) { 57 | this.id = id; 58 | } 59 | 60 | public Long getId() { 61 | return id; 62 | } 63 | 64 | public String getName() { 65 | return name; 66 | } 67 | 68 | public String getGivenName() { 69 | return givenName; 70 | } 71 | 72 | public int getWeight() { 73 | return weight; 74 | } 75 | 76 | public BigDecimal getIgnoredField() { 77 | return ignoredField; 78 | } 79 | 80 | public String getTransientField() { 81 | return transientField; 82 | } 83 | 84 | public void setId(Long id) { 85 | this.id = id; 86 | } 87 | 88 | public Map getSubTypeMap() { 89 | return subTypeMap; 90 | } 91 | 92 | public void setSubTypeMap(Map subTypeMap) { 93 | this.subTypeMap = subTypeMap; 94 | } 95 | 96 | public Map getMapValue() { 97 | return mapValue; 98 | } 99 | 100 | public void setMapValue(Map mapValue) { 101 | this.mapValue = mapValue; 102 | } 103 | 104 | public Map getMapKey() { 105 | return mapKey; 106 | } 107 | 108 | public void setMapKey(Map mapKey) { 109 | this.mapKey = mapKey; 110 | } 111 | 112 | public List getSubTypeList() { 113 | return subTypeList; 114 | } 115 | 116 | public void setSubTypeList(List subTypeList) { 117 | this.subTypeList = subTypeList; 118 | } 119 | 120 | public SimpleEnum[] getSimpleArray() { 121 | return simpleArray; 122 | } 123 | 124 | public void setSimpleArray(SimpleEnum[] simpleArray) { 125 | this.simpleArray = simpleArray; 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /examples/src/main/java/org/leandreck/endpoints/examples/SecondTypeScriptEndpoint.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.leandreck.endpoints.examples; 17 | 18 | import org.leandreck.endpoints.annotations.TypeScriptEndpoint; 19 | import org.leandreck.endpoints.annotations.TypeScriptIgnore; 20 | import org.springframework.core.io.InputStreamResource; 21 | import org.springframework.http.MediaType; 22 | import org.springframework.http.ResponseEntity; 23 | import org.springframework.web.bind.annotation.PathVariable; 24 | import org.springframework.web.bind.annotation.RequestBody; 25 | import org.springframework.web.bind.annotation.RequestMapping; 26 | import org.springframework.web.bind.annotation.RestController; 27 | 28 | import java.io.ByteArrayInputStream; 29 | import java.util.*; 30 | 31 | import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; 32 | import static org.springframework.http.MediaType.IMAGE_PNG; 33 | import static org.springframework.web.bind.annotation.RequestMethod.*; 34 | 35 | /** 36 | */ 37 | @TypeScriptEndpoint 38 | @RestController 39 | @RequestMapping("/api") 40 | public class SecondTypeScriptEndpoint { 41 | 42 | @RequestMapping(value = "/type/{id}", method = POST, consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE) 43 | public List setId(@PathVariable Long id, @RequestBody SubType body) { 44 | // do something 45 | return Collections.singletonList(body); 46 | } 47 | 48 | @RequestMapping(value = "/persons", method = GET, produces = APPLICATION_JSON_VALUE) 49 | public List getPersons() { 50 | final List rootTypes = new ArrayList<>(); 51 | rootTypes.add(new RootType()); 52 | return rootTypes; 53 | } 54 | 55 | @RequestMapping(value = "/person/{id}/{typeRef}", method = GET, produces = APPLICATION_JSON_VALUE) 56 | public RootType getPerson(@PathVariable Long id, @PathVariable String typeRef) { 57 | return new RootType(id); 58 | } 59 | 60 | @RequestMapping(value = "/person/{id}", method = POST, consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE) 61 | public RootType updatePerson(@PathVariable Long id, @RequestBody RootType rootType) { 62 | rootType.setId(id); 63 | return rootType; 64 | } 65 | 66 | @RequestMapping(value = "/maps", method = GET, consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE) 67 | public Map maps() { 68 | final Map map = new HashMap<>(); 69 | map.put("one", new RootType()); 70 | return map; 71 | } 72 | 73 | @TypeScriptIgnore 74 | @RequestMapping(value = "/photos/{id}", method = GET, produces = MediaType.IMAGE_PNG_VALUE) 75 | public ResponseEntity getPhoto(@PathVariable Long id) { 76 | return ResponseEntity 77 | .ok() 78 | .contentLength(0) 79 | .contentType(IMAGE_PNG) 80 | .body(new InputStreamResource(new ByteArrayInputStream("No Content".getBytes()))); 81 | } 82 | 83 | private List ignoreList() { 84 | return null; 85 | } 86 | 87 | protected List ignoredTwo() { 88 | return null; 89 | } 90 | 91 | List ignoredAlso() { 92 | return null; 93 | } 94 | 95 | @RequestMapping(value = "/subType", method = {HEAD, PUT, PATCH, DELETE, OPTIONS, TRACE}, produces = APPLICATION_JSON_VALUE) 96 | public SubType handleSubType(@RequestBody final SubType param) { 97 | return param; 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /examples/src/main/java/org/leandreck/endpoints/examples/SimpleEnum.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.leandreck.endpoints.examples; 17 | 18 | /** 19 | */ 20 | public enum SimpleEnum { 21 | ONE, 22 | TWO, 23 | THREE 24 | } 25 | -------------------------------------------------------------------------------- /examples/src/main/java/org/leandreck/endpoints/examples/SubType.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.leandreck.endpoints.examples; 17 | 18 | import java.util.Date; 19 | 20 | /** 21 | */ 22 | public class SubType { 23 | 24 | private Date date = new Date(); 25 | 26 | public Date getDate() { 27 | return date; 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /examples/src/main/java/org/leandreck/endpoints/examples/TestTypeScriptEndpoint.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.leandreck.endpoints.examples; 17 | 18 | import org.leandreck.endpoints.annotations.TypeScriptEndpoint; 19 | import org.leandreck.endpoints.annotations.TypeScriptIgnore; 20 | import org.leandreck.endpoints.annotations.TypeScriptTemplatesConfiguration; 21 | import org.springframework.core.io.InputStreamResource; 22 | import org.springframework.http.MediaType; 23 | import org.springframework.http.ResponseEntity; 24 | import org.springframework.web.bind.annotation.PathVariable; 25 | import org.springframework.web.bind.annotation.RequestBody; 26 | import org.springframework.web.bind.annotation.RequestMapping; 27 | import org.springframework.web.bind.annotation.RestController; 28 | 29 | import java.io.ByteArrayInputStream; 30 | import java.util.*; 31 | 32 | import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; 33 | import static org.springframework.http.MediaType.IMAGE_PNG; 34 | import static org.springframework.web.bind.annotation.RequestMethod.*; 35 | 36 | /** 37 | */ 38 | @TypeScriptEndpoint 39 | @RestController 40 | @RequestMapping("/api") 41 | @TypeScriptTemplatesConfiguration( 42 | apimodule = TypeScriptTemplatesConfiguration.DEFAULT_API_MODULE 43 | ) 44 | public class TestTypeScriptEndpoint { 45 | 46 | @RequestMapping(value = "/type/{id}", method = POST, consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE) 47 | public List setId(@PathVariable Long id, @RequestBody SubType body) { 48 | // do something 49 | return Collections.singletonList(body); 50 | } 51 | 52 | @RequestMapping(value = "/persons", method = GET, produces = APPLICATION_JSON_VALUE) 53 | public List getPersons() { 54 | final List rootTypes = new ArrayList<>(); 55 | rootTypes.add(new RootType()); 56 | return rootTypes; 57 | } 58 | 59 | @RequestMapping(value = "/person/{id}/{typeRef}", method = GET, produces = APPLICATION_JSON_VALUE) 60 | public RootType getPerson(@PathVariable Long id, @PathVariable String typeRef) { 61 | return new RootType(id); 62 | } 63 | 64 | @RequestMapping(value = "/person/{id}", method = POST, consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE) 65 | public RootType updatePerson(@PathVariable Long id, @RequestBody RootType rootType) { 66 | rootType.setId(id); 67 | return rootType; 68 | } 69 | 70 | @RequestMapping(value = "/maps", method = GET, consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE) 71 | public Map maps() { 72 | final Map map = new HashMap<>(); 73 | map.put("one", new RootType()); 74 | return map; 75 | } 76 | 77 | @TypeScriptIgnore 78 | @RequestMapping(value = "/photos/{id}", method = GET, produces = MediaType.IMAGE_PNG_VALUE) 79 | public ResponseEntity getPhoto(@PathVariable Long id) { 80 | return ResponseEntity 81 | .ok() 82 | .contentLength(0) 83 | .contentType(IMAGE_PNG) 84 | .body(new InputStreamResource(new ByteArrayInputStream("No Content".getBytes()))); 85 | } 86 | 87 | private List ignoreList() { 88 | return Collections.emptyList(); 89 | } 90 | 91 | protected List ignoredTwo() { 92 | return Collections.emptyList(); 93 | } 94 | 95 | List ignoredAlso() { 96 | return Collections.emptyList(); 97 | } 98 | 99 | @RequestMapping(value = "/subType", method = {HEAD, PUT, PATCH, DELETE, OPTIONS, TRACE}, produces = APPLICATION_JSON_VALUE) 100 | public SubType handleSubType(@RequestBody final SubType param) { 101 | return param; 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /examples/src/main/java/org/leandreck/endpoints/examples/abstractbase/BaseEndpoint.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.leandreck.endpoints.examples.abstractbase; 17 | 18 | import org.springframework.web.bind.annotation.PathVariable; 19 | import org.springframework.web.bind.annotation.RequestBody; 20 | import org.springframework.web.bind.annotation.RequestMapping; 21 | 22 | import java.util.Optional; 23 | 24 | import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; 25 | import static org.springframework.web.bind.annotation.RequestMethod.DELETE; 26 | import static org.springframework.web.bind.annotation.RequestMethod.GET; 27 | import static org.springframework.web.bind.annotation.RequestMethod.POST; 28 | import static org.springframework.web.bind.annotation.RequestMethod.PUT; 29 | 30 | public abstract class BaseEndpoint implements Moveable { 31 | 32 | private T useLessField; 33 | 34 | @RequestMapping(value = "/", method = POST, consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE) 35 | public T create(@RequestBody T newEntity) { 36 | // do something 37 | useLessField = newEntity; 38 | return newEntity; 39 | } 40 | 41 | @RequestMapping(value = "/{id}", method = PUT, consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE) 42 | public T update(@PathVariable String id, @RequestBody T updatedEntity) { 43 | // do something 44 | return updatedEntity; 45 | } 46 | 47 | @RequestMapping(value = "/{id}", method = GET, produces = APPLICATION_JSON_VALUE) 48 | public Optional read(@PathVariable String id) { 49 | // do something 50 | return Optional.of(useLessField); 51 | } 52 | 53 | @RequestMapping(value = "/{id}", method = DELETE, produces = APPLICATION_JSON_VALUE) 54 | public abstract void delete(@PathVariable String id); 55 | } 56 | -------------------------------------------------------------------------------- /examples/src/main/java/org/leandreck/endpoints/examples/abstractbase/Clearable.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.leandreck.endpoints.examples.abstractbase; 17 | 18 | import org.springframework.web.bind.annotation.RequestMapping; 19 | 20 | import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; 21 | import static org.springframework.web.bind.annotation.RequestMethod.DELETE; 22 | 23 | public interface Clearable { 24 | 25 | @RequestMapping(value = "/", method = DELETE, produces = APPLICATION_JSON_VALUE) 26 | int clearAll(); 27 | } 28 | -------------------------------------------------------------------------------- /examples/src/main/java/org/leandreck/endpoints/examples/abstractbase/Moveable.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.leandreck.endpoints.examples.abstractbase; 17 | 18 | import org.springframework.web.bind.annotation.PathVariable; 19 | import org.springframework.web.bind.annotation.RequestMapping; 20 | 21 | import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; 22 | import static org.springframework.web.bind.annotation.RequestMethod.POST; 23 | 24 | public interface Moveable { 25 | 26 | @RequestMapping(value = "/{id}/to/{cityId}", method = POST, produces = APPLICATION_JSON_VALUE) 27 | void move(@PathVariable String id, @PathVariable String cityId); 28 | } 29 | -------------------------------------------------------------------------------- /examples/src/main/java/org/leandreck/endpoints/examples/abstractbase/Person.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.leandreck.endpoints.examples.abstractbase; 17 | 18 | import lombok.Data; 19 | 20 | import java.util.List; 21 | 22 | @Data 23 | public class Person { 24 | 25 | String id; 26 | String name; 27 | List neighbours; 28 | } 29 | -------------------------------------------------------------------------------- /examples/src/main/java/org/leandreck/endpoints/examples/abstractbase/PersonEndpoint.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.leandreck.endpoints.examples.abstractbase; 17 | 18 | import org.leandreck.endpoints.annotations.TypeScriptEndpoint; 19 | import org.springframework.web.bind.annotation.PathVariable; 20 | import org.springframework.web.bind.annotation.RequestMapping; 21 | import org.springframework.web.bind.annotation.RestController; 22 | 23 | import java.util.Collections; 24 | import java.util.List; 25 | 26 | import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; 27 | import static org.springframework.web.bind.annotation.RequestMethod.GET; 28 | 29 | @TypeScriptEndpoint 30 | @RestController 31 | @RequestMapping("/persons") 32 | public class PersonEndpoint extends BaseEndpoint implements Clearable { 33 | 34 | @RequestMapping(value = "/{id}/neighbours", method = GET, produces = APPLICATION_JSON_VALUE) 35 | public List neighbours(@PathVariable String id) { 36 | // do something 37 | return Collections.emptyList(); 38 | } 39 | 40 | @Override 41 | public void delete(String id) { 42 | //void 43 | } 44 | 45 | @Override 46 | public int clearAll() { 47 | return 0; 48 | } 49 | 50 | @Override 51 | public void move(String id, String cityId) { 52 | //void 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /examples/src/main/java/org/leandreck/endpoints/examples/lombok/LombokRequest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.leandreck.endpoints.examples.lombok; 17 | 18 | import lombok.Value; 19 | 20 | @Value 21 | public class LombokRequest { 22 | 23 | private String token; 24 | 25 | } 26 | -------------------------------------------------------------------------------- /examples/src/main/java/org/leandreck/endpoints/examples/lombok/LombokResponse.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.leandreck.endpoints.examples.lombok; 17 | 18 | import lombok.Data; 19 | 20 | import javax.validation.constraints.NotNull; 21 | import java.util.List; 22 | import java.util.Map; 23 | 24 | /** 25 | * This is a documentation of a LombokResponse 26 | * 27 | * @param T 28 | * @param X 29 | * @param Y 30 | * @param Z 31 | * @param and some B 32 | */ 33 | @Data 34 | class LombokResponse, X extends List, Y, Z, B> { 35 | 36 | /** 37 | * This is the size. 38 | */ 39 | @NotNull 40 | Integer size; 41 | 42 | /** 43 | * This is a listWithTypeBElements 44 | */ 45 | T listWithTypeBElements; 46 | 47 | /** 48 | * Some other listWithSuperTypesOfY 49 | */ 50 | X listWithSuperTypesOfY; 51 | 52 | /** 53 | * Useless typeY TypeNode 54 | */ 55 | List typeY; 56 | 57 | /** 58 | * Array TypeNode of Zs 59 | */ 60 | Z[] typeZ; 61 | 62 | /** 63 | * And a Map 64 | */ 65 | Map mapTypeYZ; 66 | 67 | } 68 | -------------------------------------------------------------------------------- /examples/src/main/java/org/leandreck/endpoints/examples/lombok/LombokTypeScriptEndpoint.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2016 Mathias Kowalzik (Mathias.Kowalzik@leandreck.org) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.leandreck.endpoints.examples.lombok; 17 | 18 | import org.leandreck.endpoints.annotations.TypeScriptEndpoint; 19 | import org.leandreck.endpoints.examples.RootType; 20 | import org.leandreck.endpoints.examples.SubType; 21 | import org.springframework.http.ResponseEntity; 22 | import org.springframework.web.bind.annotation.PathVariable; 23 | import org.springframework.web.bind.annotation.RequestBody; 24 | import org.springframework.web.bind.annotation.RequestMapping; 25 | import org.springframework.web.bind.annotation.RequestParam; 26 | import org.springframework.web.bind.annotation.RestController; 27 | import org.springframework.web.multipart.MultipartFile; 28 | 29 | import javax.servlet.http.HttpServletRequest; 30 | import javax.ws.rs.core.Context; 31 | import java.util.ArrayList; 32 | import java.util.List; 33 | import java.util.Map; 34 | import java.util.Optional; 35 | 36 | import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; 37 | import static org.springframework.web.bind.annotation.RequestMethod.POST; 38 | 39 | /** 40 | * LombokTypeScriptEndpoint JavaDoc. 41 | * 42 | * @see StringBuilder 43 | * @see java.util.TreeMap 44 | * @since 0.3.0 45 | */ 46 | @TypeScriptEndpoint 47 | @RestController 48 | @RequestMapping("/api") 49 | public class LombokTypeScriptEndpoint { 50 | 51 | /** 52 | * this is a simple javadoc for Method {@link #setId(Long, String, Optional, LombokRequest)}. 53 | * @param id id 54 | * @param typeRef a reference 55 | * @param queryParameter a query parameter 56 | * @param body a body parameter 57 | * @return LombokResponse 58 | */ 59 | @RequestMapping(value = "/type/{idPathVariable}/{typeRef}", method = POST, consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE) 60 | public LombokResponse, List, Boolean, Map, SubType> setId( 61 | @PathVariable(name = "idPathVariable") Long id, 62 | @PathVariable String typeRef, 63 | @RequestParam(name = "queryRequestParam", required = false) Optional queryParameter, 64 | @RequestBody(required = false) LombokRequest body) { 65 | // do something 66 | return new LombokResponse<>(); 67 | } 68 | 69 | @RequestMapping(value = "/foo/{idPathVariable}/{typeRef}", method = POST, consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE) 70 | public LombokResponse, List, Boolean, SubType, RootType> setFoo( 71 | @PathVariable(name = "idPathVariable") Long id, 72 | @PathVariable String typeRef, 73 | @RequestParam(name = "queryRequestParam", required = false) Optional queryParameter, 74 | @RequestBody(required = false) LombokRequest body) { 75 | // do something 76 | return new LombokResponse<>(); 77 | } 78 | 79 | @RequestMapping(value = "/foo/{idPathVariable}/{typeRef}", method = POST, consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE) 80 | public ResponseEntity, List, Boolean, SubType, RootType>> setResponseEntity( 81 | @PathVariable(name = "idPathVariable") Long id, 82 | @PathVariable String typeRef, 83 | @RequestParam(name = "queryRequestParam", required = false) Optional queryParameter, 84 | @RequestBody(required = false) LombokRequest body) { 85 | // do something 86 | return ResponseEntity.ok(new LombokResponse<>()); 87 | } 88 | 89 | @RequestMapping(value = "/upload/{id}", method = POST, consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE) 90 | public ResponseEntity, List, Boolean, SubType, RootType>> fileUpload( 91 | @PathVariable("id") long id, 92 | @RequestParam("uploadfile") MultipartFile uploadfile, 93 | @Context HttpServletRequest request) { 94 | // do something 95 | return ResponseEntity.ok(new LombokResponse<>()); 96 | } 97 | } 98 | --------------------------------------------------------------------------------